Skip to content

Commit 5c43458

Browse files
committed
Added Adapter Details window (#671)
1 parent f40f898 commit 5c43458

File tree

8 files changed

+452
-21
lines changed

8 files changed

+452
-21
lines changed

InternetTest/InternetTest/Components/NetworkAdapterItem.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
<Button
137137
Padding="5 3"
138138
Background="Transparent"
139+
Command="{Binding DetailsCommand}"
139140
Cursor="Hand"
140141
Foreground="{DynamicResource Foreground1}">
141142
<StackPanel Orientation="Horizontal">

InternetTest/InternetTest/Components/NetworkAdapterItem.xaml.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2626

2727
namespace InternetTest.Components
2828
{
29-
/// <summary>
30-
/// Interaction logic for NetworkAdapterItem.xaml
31-
/// </summary>
32-
public partial class NetworkAdapterItem : UserControl
33-
{
34-
public NetworkAdapterItem()
35-
{
36-
InitializeComponent();
37-
}
38-
}
29+
/// <summary>
30+
/// Interaction logic for NetworkAdapterItem.xaml
31+
/// </summary>
32+
public partial class NetworkAdapterItem : UserControl
33+
{
34+
public NetworkAdapterItem()
35+
{
36+
InitializeComponent();
37+
}
38+
}
3939
}

InternetTest/InternetTest/MainWindow.xaml.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
*/
2424
using MicaWPF.Lite.Controls;
2525

26-
namespace InternetTest
26+
namespace InternetTest;
27+
28+
/// <summary>
29+
/// Interaction logic for MainWindow.xaml
30+
/// </summary>
31+
public partial class MainWindow : MicaWindow
2732
{
28-
/// <summary>
29-
/// Interaction logic for MainWindow.xaml
30-
/// </summary>
31-
public partial class MainWindow : MicaWindow
33+
public MainWindow()
3234
{
33-
public MainWindow()
34-
{
35-
InitializeComponent();
36-
}
35+
InitializeComponent();
3736
}
3837
}

InternetTest/InternetTest/ViewModels/Components/NetworkAdapterItemViewModel.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
using InternetTest.Commands;
2525
using InternetTest.Helpers;
2626
using InternetTest.Models;
27+
using InternetTest.Services;
28+
using InternetTest.Windows;
2729
using System.Diagnostics;
2830
using System.Net.NetworkInformation;
2931
using System.Windows.Input;
@@ -66,6 +68,7 @@ public SolidColorBrush? StatusColor
6668
}
6769

6870
public ICommand SettingsCommand { get; }
71+
public ICommand DetailsCommand { get; }
6972

7073
public NetworkAdapterItemViewModel(NetworkAdapter networkAdapter)
7174
{
@@ -101,9 +104,15 @@ public NetworkAdapterItemViewModel(NetworkAdapter networkAdapter)
101104
TotalBytesSent = $"{StorageUnitHelper.GetStorageUnit(networkAdapter.BytesSent).Item2:0.00} {StorageUnitHelper.UnitToString(StorageUnitHelper.GetStorageUnit(networkAdapter.BytesSent).Item1)}";
102105
TotalBytesReceived = $"{StorageUnitHelper.GetStorageUnit(networkAdapter.BytesReceived).Item2:0.00} {StorageUnitHelper.UnitToString(StorageUnitHelper.GetStorageUnit(networkAdapter.BytesReceived).Item1)}";
103106

104-
SettingsCommand = new RelayCommand((object o) =>
107+
SettingsCommand = new RelayCommand(o =>
105108
{
106109
Process.Start("control.exe", "ncpa.cpl");
107110
});
111+
112+
DetailsCommand = new RelayCommand(o =>
113+
{
114+
WindowService windowService = new();
115+
windowService.ShowWindow<AdapterDetailsWindow>(new Windows.AdapterDetailsWindowViewModel(networkAdapter));
116+
});
108117
}
109118
}

InternetTest/InternetTest/ViewModels/HomePageViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class HomePageViewModel : ViewModelBase
7474

7575
private SolidColorBrush? _statusColor;
7676
public SolidColorBrush? StatusColor { get => _statusColor; set { _statusColor = value; OnPropertyChanged(nameof(StatusColor)); } }
77-
77+
7878
private readonly Settings _settings;
7979

8080
bool connected = true;
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
MIT License
3+
4+
Copyright (c) Léo Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
using InternetTest.Commands;
25+
using InternetTest.Helpers;
26+
using InternetTest.Models;
27+
using System.Collections.ObjectModel;
28+
using System.Net.NetworkInformation;
29+
using System.Windows;
30+
using System.Windows.Input;
31+
32+
namespace InternetTest.ViewModels.Windows;
33+
34+
public class AdapterDetailsWindowViewModel : ViewModelBase
35+
{
36+
private readonly NetworkAdapter _networkAdapter;
37+
38+
private string? _name;
39+
public string Name { get => _name ?? string.Empty; set { _name = value; OnPropertyChanged(nameof(Name)); } }
40+
public ObservableCollection<GridItemViewModel> Details { get; } = [];
41+
public ObservableCollection<GridItemViewModel> Cat2 { get; } = [];
42+
public ObservableCollection<GridItemViewModel> Cat3 { get; } = [];
43+
44+
public ICommand CopyCommand { get; }
45+
public AdapterDetailsWindowViewModel(NetworkAdapter networkAdapter)
46+
{
47+
Name = networkAdapter.Name;
48+
Details = [
49+
new(Properties.Resources.DataConsumption, $"{StorageUnitHelper.GetStorageUnit(networkAdapter.BytesReceived + networkAdapter.BytesSent).Item2:0.00} {StorageUnitHelper.UnitToString(StorageUnitHelper.GetStorageUnit(networkAdapter.BytesReceived + networkAdapter.BytesSent).Item1)}", 0, 0),
50+
new(Properties.Resources.InterfaceType, NetworkAdapter.GetInterfaceTypeName(networkAdapter.NetworkInterfaceType), 1, 0),
51+
new(Properties.Resources.Status, networkAdapter.Status switch {
52+
OperationalStatus.Up => Properties.Resources.ConnectedS,
53+
OperationalStatus.Down => Properties.Resources.Disconnected,
54+
_ => networkAdapter.Status.ToString()
55+
}, 0, 1),
56+
new(Properties.Resources.IpVersion, networkAdapter.IpVersion ?? Properties.Resources.Unknown, 1, 1),
57+
new(Properties.Resources.Speed, $"{StorageUnitHelper.GetStorageUnit(networkAdapter.Speed).Item2:0.00} {StorageUnitHelper.UnitToString(StorageUnitHelper.GetStorageUnit(networkAdapter.Speed).Item1)}/s", 2, 0),
58+
];
59+
60+
Cat2 = [
61+
new (Properties.Resources.DNSSuffix, networkAdapter.DnsSuffix, 0, 0),
62+
new(Properties.Resources.MTU, networkAdapter.Mtu.ToString(), 1, 0),
63+
new( Properties.Resources.DnsEnabled, BoolToString(networkAdapter.DnsEnabled), 0, 1),
64+
new( Properties.Resources.DnsDynamicConfigured, BoolToString(networkAdapter.IsDynamicDnsEnabled), 1, 1),
65+
new( Properties.Resources.Multicast, BoolToString(networkAdapter.SupportsMulticast), 2, 0)
66+
];
67+
68+
Cat3 = [
69+
new (Properties.Resources.TotalBytesReceived, $"{StorageUnitHelper.GetStorageUnit(networkAdapter.BytesReceived).Item2:0.00} {StorageUnitHelper.UnitToString(StorageUnitHelper.GetStorageUnit(networkAdapter.BytesReceived).Item1)}", 0, 0),
70+
new (Properties.Resources.TotalBytesSent, $"{StorageUnitHelper.GetStorageUnit(networkAdapter.BytesSent).Item2:0.00} {StorageUnitHelper.UnitToString(StorageUnitHelper.GetStorageUnit(networkAdapter.BytesSent).Item1)}", 1, 0),
71+
new (Properties.Resources.IncomingPacketsDiscarded, networkAdapter.IncomingPacketsDiscarded.ToString(), 2, 0),
72+
new (Properties.Resources.IncomingPacketsWithErrors, networkAdapter.IncomingPacketsWithErrors.ToString(), 3, 0),
73+
new (Properties.Resources.IncomingUnknownProtocolPackets, networkAdapter.IncomingUnknownProtocolPackets.ToString(), 4, 0),
74+
new (Properties.Resources.NonUnicastPacketsReceived, networkAdapter.NonUnicastPacketsReceived.ToString(), 5, 0),
75+
new (Properties.Resources.NonUnicastPacketsSent, networkAdapter.NonUnicastPacketsSent.ToString(), 0, 1),
76+
new (Properties.Resources.OutgoingPacketsDiscarded, networkAdapter.OutgoingPacketsDiscarded.ToString(), 1, 1),
77+
new (Properties.Resources.OutgoingPacketsWithErrors, networkAdapter.OutgoingPacketsWithErrors.ToString(), 2, 1),
78+
new (Properties.Resources.OutputQueueLength, networkAdapter.OutputQueueLength.ToString(), 3, 1),
79+
new (Properties.Resources.UnicastPacketsReceived, networkAdapter.UnicastPacketsReceived.ToString(), 4, 1),
80+
new (Properties.Resources.UnicastPacketsSent, networkAdapter.UnicastPacketsSent.ToString(), 5, 1)
81+
];
82+
83+
CopyCommand = new RelayCommand(Copy);
84+
_networkAdapter = networkAdapter;
85+
}
86+
87+
private void Copy(object? o)
88+
{
89+
Clipboard.SetDataObject(_networkAdapter.ToFormattedString());
90+
}
91+
92+
private string BoolToString(bool b)
93+
{
94+
return b ? Properties.Resources.Yes : Properties.Resources.No;
95+
}
96+
}
97+
98+
public class GridItemViewModel : ViewModelBase
99+
{
100+
private string? _title;
101+
public string? Title
102+
{
103+
get => _title;
104+
set { _title = value; OnPropertyChanged(nameof(Title)); }
105+
}
106+
private string? _value;
107+
public string? Value
108+
{
109+
get => _value;
110+
set { _value = value; OnPropertyChanged(nameof(Value)); }
111+
}
112+
113+
private int _gridColumn;
114+
public int GridColumn
115+
{
116+
get => _gridColumn;
117+
set { _gridColumn = value; OnPropertyChanged(nameof(GridColumn)); }
118+
}
119+
120+
private int _gridRow;
121+
public int GridRow
122+
{
123+
get => _gridRow;
124+
set { _gridRow = value; OnPropertyChanged(nameof(GridRow)); }
125+
}
126+
127+
public GridItemViewModel(string title, string value, int row, int col)
128+
{
129+
Title = title;
130+
Value = value;
131+
GridRow = row;
132+
GridColumn = col;
133+
}
134+
}

0 commit comments

Comments
 (0)