Skip to content

Commit 68f45cf

Browse files
committed
Cleanup, wiki view splitted into two views
1 parent c4fc7dd commit 68f45cf

9 files changed

Lines changed: 471 additions & 367 deletions

File tree

Source/NETworkManager/NETworkManager.csproj

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,16 @@
179179
<Compile Include="Validators\EmptyOrIPv4AddressValidator.cs" />
180180
<Compile Include="Validators\OpacityTextboxValidator.cs" />
181181
<Compile Include="ViewModels\Applications\DNSLookupViewModel.cs" />
182+
<Compile Include="ViewModels\Applications\WikiOUILookupViewModel.cs" />
182183
<Compile Include="ViewModels\Help\HelpCommandLineViewModel.cs" />
183184
<Compile Include="ViewModels\Settings\SettingsApplicationDNSLookupViewModel.cs" />
184185
<Compile Include="ViewModels\Settings\SettingsApplicationWakeOnLANViewModel.cs" />
186+
<Compile Include="Views\Applications\WikiOUILookupView.xaml.cs">
187+
<DependentUpon>WikiOUILookupView.xaml</DependentUpon>
188+
</Compile>
189+
<Compile Include="Views\Applications\WikiPortView.xaml.cs">
190+
<DependentUpon>WikiPortView.xaml</DependentUpon>
191+
</Compile>
185192
<Compile Include="Views\Settings\UpdateView.xaml.cs">
186193
<DependentUpon>UpdateView.xaml</DependentUpon>
187194
</Compile>
@@ -235,6 +242,14 @@
235242
<Generator>MSBuild:Compile</Generator>
236243
<SubType>Designer</SubType>
237244
</Page>
245+
<Page Include="Views\Applications\WikiOUILookupView.xaml">
246+
<Generator>MSBuild:Compile</Generator>
247+
<SubType>Designer</SubType>
248+
</Page>
249+
<Page Include="Views\Applications\WikiPortView.xaml">
250+
<Generator>MSBuild:Compile</Generator>
251+
<SubType>Designer</SubType>
252+
</Page>
238253
<Page Include="Views\Applications\WikiView.xaml">
239254
<Generator>MSBuild:Compile</Generator>
240255
<SubType>Designer</SubType>
@@ -385,7 +400,7 @@
385400
<Compile Include="Validators\FileExistsValidator.cs" />
386401
<Compile Include="Validators\PortRangeValidator.cs" />
387402
<Compile Include="ViewModels\Applications\PortScannerViewModel.cs" />
388-
<Compile Include="ViewModels\Applications\WikiViewModel.cs" />
403+
<Compile Include="ViewModels\Applications\WikiPortViewModel.cs" />
389404
<Compile Include="ViewModels\Settings\SettingsApplicationPortScannerViewModel.cs" />
390405
<Compile Include="ViewModels\Settings\SettingsApplicationIPScannerViewModel.cs" />
391406
<Compile Include="ViewModels\Settings\SettingsApplicationPingViewModel.cs" />
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
using System.Windows.Input;
2+
using MahApps.Metro.Controls.Dialogs;
3+
using System.Collections.ObjectModel;
4+
using NETworkManager.Models.Settings;
5+
using System.Collections.Generic;
6+
using NETworkManager.Models.Network;
7+
using NETworkManager.Helpers;
8+
using System.Text.RegularExpressions;
9+
10+
namespace NETworkManager.ViewModels.Applications
11+
{
12+
public class WikiOUILookupViewModel : ViewModelBase
13+
{
14+
#region Variables
15+
private IDialogCoordinator dialogCoordinator;
16+
17+
private bool _isLoading = true;
18+
19+
private string _macOrVendorAddress;
20+
public string MACAddressOrVendor
21+
{
22+
get { return _macOrVendorAddress; }
23+
set
24+
{
25+
if (value == _macOrVendorAddress)
26+
return;
27+
28+
_macOrVendorAddress = value;
29+
OnPropertyChanged();
30+
}
31+
}
32+
33+
private bool _macAddressOrVendorHasError;
34+
public bool MACAddressOrVendorHasError
35+
{
36+
get { return _macAddressOrVendorHasError; }
37+
set
38+
{
39+
if (value == _macAddressOrVendorHasError)
40+
return;
41+
42+
_macAddressOrVendorHasError = value;
43+
OnPropertyChanged();
44+
}
45+
}
46+
47+
private List<string> _macAddressOrVendorHistory = new List<string>();
48+
public List<string> MACAddressOrVendorHistory
49+
{
50+
get { return _macAddressOrVendorHistory; }
51+
set
52+
{
53+
if (value == _macAddressOrVendorHistory)
54+
return;
55+
56+
if (!_isLoading)
57+
SettingsManager.Current.Wiki_MACAddressOrVendorHistory = value;
58+
59+
_macAddressOrVendorHistory = value;
60+
OnPropertyChanged();
61+
}
62+
}
63+
64+
private bool _isOUILookupRunning;
65+
public bool IsOUILookupRunning
66+
{
67+
get { return _isOUILookupRunning; }
68+
set
69+
{
70+
if (value == _isOUILookupRunning)
71+
return;
72+
73+
_isOUILookupRunning = value;
74+
OnPropertyChanged();
75+
}
76+
}
77+
78+
private ObservableCollection<OUIInfo> _ouiLookupResult = new ObservableCollection<OUIInfo>();
79+
public ObservableCollection<OUIInfo> OUILookupResult
80+
{
81+
get { return _ouiLookupResult; }
82+
set
83+
{
84+
if (value == _ouiLookupResult)
85+
return;
86+
87+
_ouiLookupResult = value;
88+
}
89+
}
90+
91+
private bool _noVendorFound;
92+
public bool NoVendorFound
93+
{
94+
get { return _noVendorFound; }
95+
set
96+
{
97+
if (value == _noVendorFound)
98+
return;
99+
100+
_noVendorFound = value;
101+
OnPropertyChanged();
102+
}
103+
}
104+
#endregion
105+
106+
#region Constructor, Load settings
107+
public WikiOUILookupViewModel(IDialogCoordinator instance)
108+
{
109+
dialogCoordinator = instance;
110+
111+
LoadSettings();
112+
113+
_isLoading = false;
114+
}
115+
116+
private void LoadSettings()
117+
{
118+
if (SettingsManager.Current.Wiki_MACAddressOrVendorHistory != null)
119+
MACAddressOrVendorHistory = new List<string>(SettingsManager.Current.Wiki_MACAddressOrVendorHistory);
120+
}
121+
#endregion
122+
123+
#region ICommands & Actions
124+
public ICommand OUILookupCommand
125+
{
126+
get { return new RelayCommand(p => OUILookupAction(), OUILookup_CanExecute); }
127+
}
128+
129+
private bool OUILookup_CanExecute(object parameter)
130+
{
131+
return !MACAddressOrVendorHasError;
132+
}
133+
134+
private async void OUILookupAction()
135+
{
136+
IsOUILookupRunning = true;
137+
138+
OUILookupResult.Clear();
139+
140+
List<string> vendors = new List<string>();
141+
142+
foreach (string macAddressOrVendor in MACAddressOrVendor.Split(';'))
143+
{
144+
string macAddressOrVendor1 = macAddressOrVendor.Trim();
145+
146+
if (Regex.IsMatch(macAddressOrVendor1, RegexHelper.MACAddressRegex) || Regex.IsMatch(macAddressOrVendor1, RegexHelper.MACAddressFirst3BytesRegex))
147+
{
148+
foreach (OUIInfo info in await OUILookup.LookupAsync(macAddressOrVendor1))
149+
{
150+
OUILookupResult.Add(info);
151+
}
152+
}
153+
else
154+
{
155+
vendors.Add(macAddressOrVendor1);
156+
}
157+
}
158+
159+
foreach (OUIInfo info in await OUILookup.LookupByVendorAsync(vendors))
160+
{
161+
OUILookupResult.Add(info);
162+
}
163+
164+
if (OUILookupResult.Count == 0)
165+
{
166+
NoVendorFound = true;
167+
}
168+
else
169+
{
170+
MACAddressOrVendorHistory = new List<string>(HistoryListHelper.Modify(MACAddressOrVendorHistory, MACAddressOrVendor, SettingsManager.Current.Application_HistoryListEntries));
171+
NoVendorFound = false;
172+
}
173+
174+
IsOUILookupRunning = false;
175+
}
176+
#endregion
177+
}
178+
}

0 commit comments

Comments
 (0)