1010using NETworkManager . Models . Network ;
1111using System . ComponentModel ;
1212using System . Windows . Data ;
13+ using NETworkManager . ViewModels . Dialogs ;
14+ using NETworkManager . Views . Dialogs ;
1315
1416namespace 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