Skip to content

Commit acc6ea9

Browse files
committed
WakeOnLAN - client dialog (add/edit/copy as) added
1 parent afe7567 commit acc6ea9

10 files changed

Lines changed: 471 additions & 52 deletions

File tree

Source/NETworkManager/Models/Settings/WakeOnLANClientInfo.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22
{
33
public class WakeOnLANClientInfo
44
{
5+
public string Name { get; set; }
56
public string MACAddress { get; set; }
6-
public string Hostname { get; set; }
7-
public int Port { get; set; }
87
public string Broadcast { get; set; }
8+
public int Port { get; set; }
9+
public string Group { get; set; }
910

1011
public WakeOnLANClientInfo()
1112
{
1213

1314
}
1415

16+
public WakeOnLANClientInfo(string name, string macAddress, string broadcast, int port, string group)
17+
{
18+
Name = name;
19+
MACAddress = macAddress;
20+
Broadcast = broadcast;
21+
Port = port;
22+
Group = group;
23+
}
24+
1525
public override string ToString()
1626
{
1727
return MACAddress;

Source/NETworkManager/NETworkManager.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
<Compile Include="Models\RemoteDesktop\RemoteDesktopSessionInfo.cs" />
188188
<Compile Include="Models\Settings\RemoteDesktopSessionManager.cs" />
189189
<Compile Include="Models\Settings\RemoteDesktopSessionInfo.cs" />
190+
<Compile Include="ViewModels\Dialogs\WakeOnLANClientViewModel.cs" />
190191
<Compile Include="ViewModels\Dialogs\IPScannerProfileViewModel.cs" />
191192
<Compile Include="ViewModels\Dialogs\RemoteDesktopSessionViewModel.cs" />
192193
<Compile Include="ViewModels\Dialogs\RemoteDesktopSessionConnectViewModel.cs" />
@@ -234,6 +235,9 @@
234235
<Compile Include="Controls\DragablzTabHostWindow.xaml.cs">
235236
<DependentUpon>DragablzTabHostWindow.xaml</DependentUpon>
236237
</Compile>
238+
<Compile Include="Views\Dialogs\WakeOnLANClientDialog.xaml.cs">
239+
<DependentUpon>WakeOnLANClientDialog.xaml</DependentUpon>
240+
</Compile>
237241
<Compile Include="Views\Dialogs\IPScannerProfileDialog.xaml.cs">
238242
<DependentUpon>IPScannerProfileDialog.xaml</DependentUpon>
239243
</Compile>
@@ -363,6 +367,10 @@
363367
<Generator>MSBuild:Compile</Generator>
364368
<SubType>Designer</SubType>
365369
</Page>
370+
<Page Include="Views\Dialogs\WakeOnLANClientDialog.xaml">
371+
<Generator>MSBuild:Compile</Generator>
372+
<SubType>Designer</SubType>
373+
</Page>
366374
<Page Include="Views\Dialogs\IPScannerProfileDialog.xaml">
367375
<Generator>MSBuild:Compile</Generator>
368376
<SubType>Designer</SubType>

Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
<system:String x:Key="String_Header_EditProfile">Profil bearbeiten</system:String>
5959
<system:String x:Key="String_Header_CopyProfile">Profil kopieren</system:String>
6060
<system:String x:Key="String_Header_AddClient">Client hinzufügen</system:String>
61+
<system:String x:Key="String_Header_EditClient">Client bearbeiten</system:String>
62+
<system:String x:Key="String_Header_CopyClient">Client kopieren</system:String>
6163
<system:String x:Key="String_Header_Libraries">Bibliotheken</system:String>
6264
<system:String x:Key="String_Header_License">Lizenz</system:String>
6365
<system:String x:Key="String_Header_Search">Suche</system:String>

Source/NETworkManager/Resources/Localization/Resources.en-US.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
<system:String x:Key="String_Header_EditProfile">Edit profile</system:String>
5959
<system:String x:Key="String_Header_CopyProfile">Copy profile</system:String>
6060
<system:String x:Key="String_Header_AddClient">Add client</system:String>
61+
<system:String x:Key="String_Header_EditClient">Edit client</system:String>
62+
<system:String x:Key="String_Header_CopyClient">Copy client</system:String>
6163
<system:String x:Key="String_Header_Libraries">Libraries</system:String>
6264
<system:String x:Key="String_Header_License">License</system:String>
6365
<system:String x:Key="String_Header_Search">Search</system:String>

Source/NETworkManager/ViewModels/Applications/IPScannerViewModel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public ICommand AddProfileCommand
384384
}
385385

386386
private async void AddProfileAction()
387-
{
387+
{
388388
CustomDialog customDialog = new CustomDialog()
389389
{
390390
Title = Application.Current.Resources["String_Header_AddProfile"] as string
@@ -414,9 +414,8 @@ private async void AddProfileAction()
414414

415415
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
416416
}
417-
418417

419-
public ICommand EditProfileCommand
418+
public ICommand EditProfileCommand
420419
{
421420
get { return new RelayCommand(p => EditProfileAction()); }
422421
}
@@ -593,7 +592,7 @@ private void ScanFinished()
593592

594593
CancelScan = false;
595594
IsScanRunning = false;
596-
}
595+
}
597596
#endregion
598597

599598
#region Events

Source/NETworkManager/ViewModels/Applications/WakeOnLanViewModel.cs

Lines changed: 125 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using NETworkManager.Models.Network;
1111
using System.ComponentModel;
1212
using System.Windows.Data;
13+
using NETworkManager.ViewModels.Dialogs;
14+
using NETworkManager.Views.Dialogs;
1315

1416
namespace NETworkManager.ViewModels.Applications
1517
{
@@ -139,16 +141,39 @@ public ICollectionView WakeOnLANClients
139141
get { return _wakeOnLANClients; }
140142
}
141143

142-
private WakeOnLANClientInfo _selectedWakeOnLANClient;
143-
public WakeOnLANClientInfo SelectedWakeOnLANClient
144+
public List<string> WakeOnLANClientGroups
144145
{
145-
get { return _selectedWakeOnLANClient; }
146+
get
147+
{
148+
List<string> list = new List<string>();
149+
150+
foreach (WakeOnLANClientInfo client in WakeOnLANClientManager.Clients)
151+
{
152+
if (!list.Contains(client.Group))
153+
list.Add(client.Group);
154+
}
155+
156+
return list;
157+
}
158+
}
159+
160+
private WakeOnLANClientInfo _selectedClient;
161+
public WakeOnLANClientInfo SelectedClient
162+
{
163+
get { return _selectedClient; }
146164
set
147165
{
148-
if (value == _selectedWakeOnLANClient)
166+
if (value == _selectedClient)
149167
return;
150168

151-
_selectedWakeOnLANClient = value;
169+
if(value != null)
170+
{
171+
MACAddress = value.MACAddress;
172+
Broadcast = value.Broadcast;
173+
Port = value.Port;
174+
}
175+
176+
_selectedClient = value;
152177
OnPropertyChanged();
153178
}
154179
}
@@ -181,6 +206,8 @@ public WakeOnLANViewModel(IDialogCoordinator instance)
181206
WakeOnLANClientManager.Load();
182207

183208
_wakeOnLANClients = CollectionViewSource.GetDefaultView(WakeOnLANClientManager.Clients);
209+
_wakeOnLANClients.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
210+
_wakeOnLANClients.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
184211

185212
LoadSettings();
186213

@@ -244,67 +271,124 @@ public ICommand AddClientCommand
244271

245272
private async void AddClientAction()
246273
{
247-
MetroDialogSettings settings = AppearanceManager.MetroDialog;
274+
CustomDialog customDialog = new CustomDialog()
275+
{
276+
Title = Application.Current.Resources["String_Header_AddClient"] as string
277+
};
248278

249-
settings.AffirmativeButtonText = Application.Current.Resources["String_Button_Add"] as string;
250-
settings.NegativeButtonText = Application.Current.Resources["String_Button_Cancel"] as string;
251-
settings.DefaultButtonFocus = MessageDialogResult.Affirmative;
279+
WakeOnLANClientViewModel wakeOnLANClientViewModel = new WakeOnLANClientViewModel(instance =>
280+
{
281+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
252282

253-
string hostname = await dialogCoordinator.ShowInputAsync(this, Application.Current.Resources["String_Header_AddClient"] as string, Application.Current.Resources["String_EnterHostnameForClient"] as string, settings);
283+
WakeOnLANClientInfo wakeOnLANClientInfo = new WakeOnLANClientInfo
284+
{
285+
Name = instance.Name,
286+
MACAddress = instance.MACAddress,
287+
Broadcast = instance.Broadcast,
288+
Port = instance.Port,
289+
Group = instance.Group
290+
};
254291

255-
if (string.IsNullOrEmpty(hostname))
256-
return;
292+
WakeOnLANClientManager.AddClient(wakeOnLANClientInfo);
293+
}, instance =>
294+
{
295+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
296+
}, WakeOnLANClientGroups, new WakeOnLANClientInfo() { MACAddress = MACAddress, Broadcast = Broadcast, Port = Port });
257297

258-
WakeOnLANClientInfo client = new WakeOnLANClientInfo
298+
customDialog.Content = new WakeOnLANClientDialog
259299
{
260-
Hostname = hostname.ToUpper(),
261-
MACAddress = MACAddressHelper.GetDefaultFormat(MACAddress),
262-
Broadcast = Broadcast,
263-
Port = Port
300+
DataContext = wakeOnLANClientViewModel
264301
};
265302

266-
WakeOnLANClientManager.AddClient(client);
303+
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
267304
}
268305

269-
public ICommand WakeUpSelectedClientCommand
306+
public ICommand EditClientCommand
270307
{
271-
get { return new RelayCommand(p => WakeUpSelectedClientAction()); }
308+
get { return new RelayCommand(p => EditClientAction()); }
272309
}
273310

274-
public void WakeUpSelectedClientAction()
311+
private async void EditClientAction()
275312
{
276-
DisplayStatusMessage = false;
277-
StatusMessage = string.Empty;
313+
CustomDialog customDialog = new CustomDialog()
314+
{
315+
Title = Application.Current.Resources["String_Header_EditClient"] as string
316+
};
278317

279-
try
318+
WakeOnLANClientViewModel wakeOnLANClientViewModel = new WakeOnLANClientViewModel(instance =>
280319
{
281-
WakeOnLANInfo info = new WakeOnLANInfo
320+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
321+
322+
WakeOnLANClientManager.RemoveClient(SelectedClient);
323+
324+
WakeOnLANClientInfo wakeOnLANClientInfo = new WakeOnLANClientInfo
282325
{
283-
MagicPacket = MagicPacketHelper.Create(SelectedWakeOnLANClient.MACAddress),
284-
Broadcast = IPAddress.Parse(SelectedWakeOnLANClient.Broadcast),
285-
Port = SelectedWakeOnLANClient.Port
326+
Name = instance.Name,
327+
MACAddress = instance.MACAddress,
328+
Broadcast = instance.Broadcast,
329+
Port = instance.Port,
330+
Group = instance.Group
286331
};
287332

288-
WakeOnLAN.Send(info);
289-
}
290-
catch (Exception ex)
333+
WakeOnLANClientManager.AddClient(wakeOnLANClientInfo);
334+
}, instance =>
291335
{
292-
StatusMessage = ex.Message;
293-
DisplayStatusMessage = true;
336+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
337+
}, WakeOnLANClientGroups, SelectedClient);
294338

295-
return;
296-
}
339+
customDialog.Content = new WakeOnLANClientDialog
340+
{
341+
DataContext = wakeOnLANClientViewModel
342+
};
343+
344+
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
345+
}
346+
347+
public ICommand CopyAsClientCommand
348+
{
349+
get { return new RelayCommand(p => CopyAsProfileAction()); }
350+
}
351+
352+
private async void CopyAsProfileAction()
353+
{
354+
CustomDialog customDialog = new CustomDialog()
355+
{
356+
Title = Application.Current.Resources["String_Header_CopyClient"] as string
357+
};
358+
359+
WakeOnLANClientViewModel wakeOnLANClientViewModel = new WakeOnLANClientViewModel(instance =>
360+
{
361+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
362+
363+
WakeOnLANClientInfo wakeOnLANClientInfo = new WakeOnLANClientInfo
364+
{
365+
Name = instance.Name,
366+
MACAddress = instance.MACAddress,
367+
Broadcast = instance.Broadcast,
368+
Port = instance.Port,
369+
Group = instance.Group
370+
};
371+
372+
WakeOnLANClientManager.AddClient(wakeOnLANClientInfo);
373+
}, instance =>
374+
{
375+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
376+
}, WakeOnLANClientGroups, SelectedClient);
377+
378+
customDialog.Content = new WakeOnLANClientDialog
379+
{
380+
DataContext = wakeOnLANClientViewModel
381+
};
297382

298-
StatusMessage = Application.Current.Resources["String_MagicPacketSuccessfulSended"] as string;
299-
DisplayStatusMessage = true;
383+
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
300384
}
301385

302-
public ICommand DeleteSelectedClientCommand
386+
public ICommand DeleteClientCommand
303387
{
304-
get { return new RelayCommand(p => DeleteSelectedClientAction()); }
388+
get { return new RelayCommand(p => DeleteClientAction()); }
305389
}
306390

307-
private async void DeleteSelectedClientAction()
391+
private async void DeleteClientAction()
308392
{
309393
MetroDialogSettings settings = AppearanceManager.MetroDialog;
310394

@@ -316,7 +400,7 @@ private async void DeleteSelectedClientAction()
316400
if (MessageDialogResult.Negative == await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_AreYouSure"] as string, Application.Current.Resources["String_DeleteClientMessage"] as string, MessageDialogStyle.AffirmativeAndNegative, settings))
317401
return;
318402

319-
WakeOnLANClientManager.RemoveClient(SelectedWakeOnLANClient);
403+
WakeOnLANClientManager.RemoveClient(SelectedClient);
320404
}
321405
#endregion
322406
}

0 commit comments

Comments
 (0)