|
12 | 12 | using System.Windows.Data; |
13 | 13 | using System.ComponentModel; |
14 | 14 | using System.Diagnostics; |
| 15 | +using NETworkManager.ViewModels.Dialogs; |
| 16 | +using NETworkManager.Views.Dialogs; |
15 | 17 |
|
16 | 18 | namespace NETworkManager.ViewModels.Applications |
17 | 19 | { |
@@ -651,6 +653,7 @@ public NetworkInterfaceViewModel(IDialogCoordinator instance) |
651 | 653 | NetworkInterfaceProfileManager.Load(); |
652 | 654 |
|
653 | 655 | _networkInterfaceProfiles = CollectionViewSource.GetDefaultView(NetworkInterfaceProfileManager.Profiles); |
| 656 | + _networkInterfaceProfiles.GroupDescriptions.Add(new PropertyGroupDescription("Group")); |
654 | 657 | _networkInterfaceProfiles.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending)); |
655 | 658 | _networkInterfaceProfiles.Filter = o => |
656 | 659 | { |
@@ -693,7 +696,7 @@ private async void LoadNetworkInterfaces() |
693 | 696 | private void LoadSettings() |
694 | 697 | { |
695 | 698 | ExpandProfileView = SettingsManager.Current.NetworkInterface_ExpandProfileView; |
696 | | - } |
| 699 | + } |
697 | 700 | #endregion |
698 | 701 |
|
699 | 702 | #region ICommands & Actions |
@@ -798,42 +801,136 @@ public async void ApplyNetworkInterfaceConfigAction() |
798 | 801 | await progressDialogController.CloseAsync(); |
799 | 802 | } |
800 | 803 | } |
801 | | - |
| 804 | + |
802 | 805 | public ICommand AddProfileCommand |
803 | 806 | { |
804 | 807 | get { return new RelayCommand(p => AddProfileAction()); } |
805 | 808 | } |
806 | 809 |
|
807 | 810 | private async void AddProfileAction() |
808 | 811 | { |
809 | | - MetroDialogSettings settings = AppearanceManager.MetroDialog; |
| 812 | + CustomDialog customDialog = new CustomDialog() |
| 813 | + { |
| 814 | + Title = Application.Current.Resources["String_Header_AddProfile"] as string |
| 815 | + }; |
810 | 816 |
|
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); |
813 | 820 |
|
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 | + }; |
815 | 844 |
|
816 | | - if (string.IsNullOrEmpty(name)) |
817 | | - return; |
| 845 | + await dialogCoordinator.ShowMetroDialogAsync(this, customDialog); |
| 846 | + } |
818 | 847 |
|
819 | | - string configSubnetmask = ConfigSubnetmaskOrCidr; |
| 848 | + public ICommand EditProfileCommand |
| 849 | + { |
| 850 | + get { return new RelayCommand(p => EditProfileAction()); } |
| 851 | + } |
820 | 852 |
|
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 | + }; |
823 | 859 |
|
824 | | - NetworkInterfaceProfileInfo profile = new NetworkInterfaceProfileInfo |
| 860 | + NetworkInterfaceProfileViewModel networkInterfaceProfileViewModel = new NetworkInterfaceProfileViewModel(instance => |
825 | 861 | { |
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 |
834 | 931 | }; |
835 | 932 |
|
836 | | - NetworkInterfaceProfileManager.AddProfile(profile); |
| 933 | + await dialogCoordinator.ShowMetroDialogAsync(this, customDialog); |
837 | 934 | } |
838 | 935 |
|
839 | 936 | public ICommand DeleteProfileCommand |
|
0 commit comments