Skip to content

Commit 234b058

Browse files
committed
Dialog added / improved (not working yet)
1 parent 0d5f037 commit 234b058

7 files changed

Lines changed: 255 additions & 73 deletions

File tree

Source/NETworkManager/Models/Settings/NetworkInterfaceProfileInfo.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@ public class NetworkInterfaceProfileInfo
1010
public bool EnableStaticDNS { get; set; }
1111
public string PrimaryDNSServer { get; set; }
1212
public string SecondaryDNSServer { get; set; }
13+
public string Group { get; set; }
1314

1415
public NetworkInterfaceProfileInfo()
1516
{
1617

1718
}
19+
20+
public NetworkInterfaceProfileInfo(string name, bool enableStaticIPAddress, string ipAddress, string subnetmask, string gateway, bool enableStaticDNS, string primaryDNSServer, string secondaryDNSServer, string group)
21+
{
22+
Name = name;
23+
EnableStaticIPAddress = enableStaticIPAddress;
24+
IPAddress = ipAddress;
25+
Subnetmask = subnetmask;
26+
Gateway = gateway;
27+
EnableStaticDNS = enableStaticDNS;
28+
PrimaryDNSServer = primaryDNSServer;
29+
SecondaryDNSServer = secondaryDNSServer;
30+
Group = group;
31+
}
1832
}
1933
}

Source/NETworkManager/Models/Settings/NetworkInterfaceProfileManager.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ public static string GetProfilesFilePath()
1818
return Path.Combine(SettingsManager.GetSettingsLocation(), ProfilesFileName);
1919
}
2020

21+
public static List<string> GetProfileGroups()
22+
{
23+
List<string> list = new List<string>();
24+
25+
foreach (NetworkInterfaceProfileInfo profile in Profiles)
26+
{
27+
if (!list.Contains(profile.Group))
28+
list.Add(profile.Group);
29+
}
30+
31+
return list;
32+
}
33+
2134
public static void Load(bool deserialize = true)
2235
{
2336
Profiles = new ObservableCollection<NetworkInterfaceProfileInfo>();

Source/NETworkManager/ViewModels/Applications/NetworkInterfaceViewModel.cs

Lines changed: 118 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using System.Windows.Data;
1313
using System.ComponentModel;
1414
using System.Diagnostics;
15+
using NETworkManager.ViewModels.Dialogs;
16+
using NETworkManager.Views.Dialogs;
1517

1618
namespace NETworkManager.ViewModels.Applications
1719
{
@@ -651,6 +653,7 @@ public NetworkInterfaceViewModel(IDialogCoordinator instance)
651653
NetworkInterfaceProfileManager.Load();
652654

653655
_networkInterfaceProfiles = CollectionViewSource.GetDefaultView(NetworkInterfaceProfileManager.Profiles);
656+
_networkInterfaceProfiles.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
654657
_networkInterfaceProfiles.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
655658
_networkInterfaceProfiles.Filter = o =>
656659
{
@@ -693,7 +696,7 @@ private async void LoadNetworkInterfaces()
693696
private void LoadSettings()
694697
{
695698
ExpandProfileView = SettingsManager.Current.NetworkInterface_ExpandProfileView;
696-
}
699+
}
697700
#endregion
698701

699702
#region ICommands & Actions
@@ -798,42 +801,136 @@ public async void ApplyNetworkInterfaceConfigAction()
798801
await progressDialogController.CloseAsync();
799802
}
800803
}
801-
804+
802805
public ICommand AddProfileCommand
803806
{
804807
get { return new RelayCommand(p => AddProfileAction()); }
805808
}
806809

807810
private async void AddProfileAction()
808811
{
809-
MetroDialogSettings settings = AppearanceManager.MetroDialog;
812+
CustomDialog customDialog = new CustomDialog()
813+
{
814+
Title = Application.Current.Resources["String_Header_AddProfile"] as string
815+
};
810816

811-
settings.AffirmativeButtonText = Application.Current.Resources["String_Button_Add"] as string;
812-
settings.NegativeButtonText = Application.Current.Resources["String_Button_Cancel"] as string;
817+
NetworkInterfaceProfileViewModel networkInterfaceProfileViewModel = new NetworkInterfaceProfileViewModel(instance =>
818+
{
819+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
813820

814-
string name = await dialogCoordinator.ShowInputAsync(this, Application.Current.Resources["String_Header_AddProfile"] as string, Application.Current.Resources["String_EnterNameForProfile"] as string, settings);
821+
NetworkInterfaceProfileInfo networkInterfaceProfileInfo = new NetworkInterfaceProfileInfo
822+
{
823+
Name = instance.Name,
824+
EnableStaticIPAddress = instance.EnableStaticIPAddress,
825+
IPAddress = instance.IPAddress,
826+
Subnetmask = instance.SubnetmaskOrCidr,
827+
Gateway = instance.Gateway,
828+
EnableStaticDNS = instance.EnableStaticDNS,
829+
PrimaryDNSServer = instance.PrimaryDNSServer,
830+
SecondaryDNSServer = instance.SecondaryDNSServer,
831+
Group = instance.Group
832+
};
833+
834+
NetworkInterfaceProfileManager.AddProfile(networkInterfaceProfileInfo);
835+
}, instance =>
836+
{
837+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
838+
}, NetworkInterfaceProfileManager.GetProfileGroups(), new NetworkInterfaceProfileInfo() { EnableStaticIPAddress = ConfigEnableStaticIPAddress, IPAddress = ConfigIPAddress, Subnetmask = ConfigSubnetmaskOrCidr, Gateway = ConfigGateway, EnableStaticDNS = ConfigEnableStaticDNS, PrimaryDNSServer = ConfigPrimaryDNSServer, SecondaryDNSServer = ConfigSecondaryDNSServer });
839+
840+
customDialog.Content = new NetworkInterfaceProfileDialog
841+
{
842+
DataContext = networkInterfaceProfileViewModel
843+
};
815844

816-
if (string.IsNullOrEmpty(name))
817-
return;
845+
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
846+
}
818847

819-
string configSubnetmask = ConfigSubnetmaskOrCidr;
848+
public ICommand EditProfileCommand
849+
{
850+
get { return new RelayCommand(p => EditProfileAction()); }
851+
}
820852

821-
if (ConfigEnableStaticIPAddress && ConfigSubnetmaskOrCidr.StartsWith("/"))
822-
configSubnetmask = Subnetmask.GetFromCidr(int.Parse(ConfigSubnetmaskOrCidr.TrimStart('/'))).Subnetmask;
853+
private async void EditProfileAction()
854+
{
855+
CustomDialog customDialog = new CustomDialog()
856+
{
857+
Title = Application.Current.Resources["String_Header_EditProfile"] as string
858+
};
823859

824-
NetworkInterfaceProfileInfo profile = new NetworkInterfaceProfileInfo
860+
NetworkInterfaceProfileViewModel networkInterfaceProfileViewModel = new NetworkInterfaceProfileViewModel(instance =>
825861
{
826-
Name = name,
827-
EnableStaticIPAddress = ConfigEnableStaticIPAddress,
828-
IPAddress = ConfigIPAddress,
829-
Gateway = ConfigGateway,
830-
Subnetmask = configSubnetmask,
831-
EnableStaticDNS = ConfigEnableStaticDNS,
832-
PrimaryDNSServer = ConfigPrimaryDNSServer,
833-
SecondaryDNSServer = ConfigSecondaryDNSServer
862+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
863+
864+
NetworkInterfaceProfileManager.RemoveProfile(SelectedProfile);
865+
866+
NetworkInterfaceProfileInfo networkInterfaceProfileInfo = new NetworkInterfaceProfileInfo
867+
{
868+
Name = instance.Name,
869+
EnableStaticIPAddress = instance.EnableStaticIPAddress,
870+
IPAddress = instance.IPAddress,
871+
Subnetmask = instance.SubnetmaskOrCidr,
872+
Gateway = instance.Gateway,
873+
EnableStaticDNS = instance.EnableStaticDNS,
874+
PrimaryDNSServer = instance.PrimaryDNSServer,
875+
SecondaryDNSServer = instance.SecondaryDNSServer,
876+
Group = instance.Group
877+
};
878+
879+
NetworkInterfaceProfileManager.AddProfile(networkInterfaceProfileInfo);
880+
}, instance =>
881+
{
882+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
883+
}, NetworkInterfaceProfileManager.GetProfileGroups(), SelectedProfile);
884+
885+
customDialog.Content = new NetworkInterfaceProfileDialog
886+
{
887+
DataContext = networkInterfaceProfileViewModel
888+
};
889+
890+
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
891+
}
892+
893+
public ICommand CopyAsProfileCommand
894+
{
895+
get { return new RelayCommand(p => CopyAsProfileAction()); }
896+
}
897+
898+
private async void CopyAsProfileAction()
899+
{
900+
CustomDialog customDialog = new CustomDialog()
901+
{
902+
Title = Application.Current.Resources["String_Header_CopyProfile"] as string
903+
};
904+
905+
NetworkInterfaceProfileViewModel networkInterfaceProfileViewModel = new NetworkInterfaceProfileViewModel(instance =>
906+
{
907+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
908+
909+
NetworkInterfaceProfileInfo networkInterfaceProfileInfo = new NetworkInterfaceProfileInfo
910+
{
911+
Name = instance.Name,
912+
EnableStaticIPAddress = instance.EnableStaticIPAddress,
913+
IPAddress = instance.IPAddress,
914+
Subnetmask = instance.SubnetmaskOrCidr,
915+
Gateway = instance.Gateway,
916+
EnableStaticDNS = instance.EnableStaticDNS,
917+
PrimaryDNSServer = instance.PrimaryDNSServer,
918+
SecondaryDNSServer = instance.SecondaryDNSServer,
919+
Group = instance.Group
920+
};
921+
922+
NetworkInterfaceProfileManager.AddProfile(networkInterfaceProfileInfo);
923+
}, instance =>
924+
{
925+
dialogCoordinator.HideMetroDialogAsync(this, customDialog);
926+
}, NetworkInterfaceProfileManager.GetProfileGroups(), SelectedProfile);
927+
928+
customDialog.Content = new NetworkInterfaceProfileDialog
929+
{
930+
DataContext = networkInterfaceProfileViewModel
834931
};
835932

836-
NetworkInterfaceProfileManager.AddProfile(profile);
933+
await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
837934
}
838935

839936
public ICommand DeleteProfileCommand

Source/NETworkManager/ViewModels/Dialogs/NetworkInterfaceProfileViewModel.cs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ public bool EnableStaticIPAddress
8080
}
8181
}
8282

83-
private string _ipv4Address;
84-
public string IPv4Address
83+
private string _ipAddress;
84+
public string IPAddress
8585
{
86-
get { return _ipv4Address; }
86+
get { return _ipAddress; }
8787
set
8888
{
89-
if (value == _ipv4Address)
89+
if (value == _ipAddress)
9090
return;
9191

92-
_ipv4Address = value;
93-
92+
_ipAddress = value;
93+
9494
if (!_isLoading)
9595
HasProfileInfoChanged();
96-
96+
9797
OnPropertyChanged();
9898
}
9999
}
@@ -205,14 +205,32 @@ public string SecondaryDNSServer
205205
OnPropertyChanged();
206206
}
207207
}
208-
208+
209+
private string _group;
210+
public string Group
211+
{
212+
get { return _group; }
213+
set
214+
{
215+
if (value == _group)
216+
return;
217+
218+
_group = value;
219+
220+
if (!_isLoading)
221+
HasProfileInfoChanged();
222+
223+
OnPropertyChanged();
224+
}
225+
}
226+
209227
ICollectionView _groups;
210228
public ICollectionView Groups
211229
{
212230
get { return _groups; }
213231
}
214232

215-
private IPScannerProfileInfo _profileInfo;
233+
private NetworkInterfaceProfileInfo _profileInfo;
216234

217235
private bool _profileInfoChanged;
218236
public bool ProfileInfoChanged
@@ -228,16 +246,22 @@ public bool ProfileInfoChanged
228246
}
229247
}
230248

231-
public NetworkInterfaceProfileViewModel(Action<NetworkInterfaceProfileViewModel> saveCommand, Action<NetworkInterfaceProfileViewModel> cancelHandler, List<string> groups, IPScannerProfileInfo profileInfo = null)
249+
public NetworkInterfaceProfileViewModel(Action<NetworkInterfaceProfileViewModel> saveCommand, Action<NetworkInterfaceProfileViewModel> cancelHandler, List<string> groups, NetworkInterfaceProfileInfo profileInfo = null)
232250
{
233251
_saveCommand = new RelayCommand(p => saveCommand(this));
234252
_cancelCommand = new RelayCommand(p => cancelHandler(this));
235253

236-
_profileInfo = profileInfo ?? new IPScannerProfileInfo();
254+
_profileInfo = profileInfo ?? new NetworkInterfaceProfileInfo();
237255

238256
Name = _profileInfo.Name;
239-
SubnetmaskOrCidr = _profileInfo.IPRange;
240-
Gateway = string.IsNullOrEmpty(_profileInfo.Group) ? Application.Current.Resources["String_Default"] as string : _profileInfo.Group;
257+
EnableStaticIPAddress = _profileInfo.EnableStaticIPAddress;
258+
IPAddress = profileInfo.IPAddress;
259+
SubnetmaskOrCidr = _profileInfo.Subnetmask;
260+
Gateway = _profileInfo.Gateway;
261+
EnableStaticDNS = _profileInfo.EnableStaticDNS;
262+
PrimaryDNSServer = _profileInfo.PrimaryDNSServer;
263+
SecondaryDNSServer = _profileInfo.SecondaryDNSServer;
264+
Group = string.IsNullOrEmpty(_profileInfo.Group) ? Application.Current.Resources["String_Default"] as string : _profileInfo.Group;
241265

242266
_groups = CollectionViewSource.GetDefaultView(groups);
243267
_groups.SortDescriptions.Add(new SortDescription());
@@ -247,7 +271,7 @@ public NetworkInterfaceProfileViewModel(Action<NetworkInterfaceProfileViewModel>
247271

248272
private void HasProfileInfoChanged()
249273
{
250-
ProfileInfoChanged = (_profileInfo.Name != Name) || (_profileInfo.IPRange != SubnetmaskOrCidr) || (_profileInfo.Group != Gateway);
274+
ProfileInfoChanged = (_profileInfo.Name != Name) || (_profileInfo.EnableStaticIPAddress != EnableStaticIPAddress) || (_profileInfo.IPAddress != IPAddress) || (_profileInfo.Subnetmask != SubnetmaskOrCidr) || (_profileInfo.Gateway != Gateway) || (_profileInfo.EnableStaticDNS != EnableStaticDNS) || (_profileInfo.PrimaryDNSServer != PrimaryDNSServer) || (_profileInfo.SecondaryDNSServer != SecondaryDNSServer);
251275
}
252276
}
253277
}

Source/NETworkManager/Views/Applications/IPScannerView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@
417417
</Style>
418418
</TextBlock.Style>
419419
</TextBlock>
420-
<Button x:Name="btnAddProfile" Grid.Column="0" Grid.Row="4" Command="{Binding AddProfileCommand}" Style="{StaticResource ImageWithTextButton}">
420+
<Button x:Name="btnAddProfile" Grid.Column="0" Grid.Row="4" Command="{Binding AddProfileCommand}" Style="{StaticResource ImageWithTextButton}">
421421
<Button.Content>
422422
<Grid>
423423
<Grid.ColumnDefinitions>

0 commit comments

Comments
 (0)