@@ -58,6 +58,20 @@ public bool CanConfigure
5858 }
5959 }
6060
61+ private bool _isConfigurationRunning ;
62+ public bool IsConfigurationRunning
63+ {
64+ get { return _isConfigurationRunning ; }
65+ set
66+ {
67+ if ( value == _isConfigurationRunning )
68+ return ;
69+
70+ _isConfigurationRunning = value ;
71+ OnPropertyChanged ( ) ;
72+ }
73+ }
74+
6175 private bool _displayStatusMessage ;
6276 public bool DisplayStatusMessage
6377 {
@@ -752,61 +766,9 @@ public ICommand ApplyNetworkInterfaceConfigCommand
752766 get { return new RelayCommand ( p => ApplyNetworkInterfaceConfigAction ( ) ) ; }
753767 }
754768
755- public async void ApplyNetworkInterfaceConfigAction ( )
769+ public void ApplyNetworkInterfaceConfigAction ( )
756770 {
757- DisplayStatusMessage = false ;
758-
759- progressDialogController = await dialogCoordinator . ShowProgressAsync ( this , Application . Current . Resources [ "String_Header_ConfigureNetworkInterface" ] as string , string . Empty ) ;
760- progressDialogController . SetIndeterminate ( ) ;
761-
762- string subnetmask = ConfigSubnetmaskOrCidr ;
763-
764- // CIDR to subnetmask
765- if ( ConfigEnableStaticIPAddress && subnetmask . StartsWith ( "/" ) )
766- subnetmask = Subnetmask . GetFromCidr ( int . Parse ( subnetmask . TrimStart ( '/' ) ) ) . Subnetmask ;
767-
768- // If primary and secondary DNS are empty --> autoconfiguration
769- if ( ConfigEnableStaticDNS && string . IsNullOrEmpty ( ConfigPrimaryDNSServer ) && string . IsNullOrEmpty ( ConfigSecondaryDNSServer ) )
770- ConfigEnableDynamicDNS = true ;
771-
772- // When primary DNS is empty, swap it with secondary (if not empty)
773- if ( ConfigEnableStaticDNS && string . IsNullOrEmpty ( ConfigPrimaryDNSServer ) && ! string . IsNullOrEmpty ( ConfigSecondaryDNSServer ) )
774- {
775- ConfigPrimaryDNSServer = ConfigSecondaryDNSServer ;
776- ConfigSecondaryDNSServer = string . Empty ;
777- }
778-
779- NetworkInterfaceConfig config = new NetworkInterfaceConfig
780- {
781- Name = SelectedNetworkInterface . Name ,
782- EnableStaticIPAddress = ConfigEnableStaticIPAddress ,
783- IPAddress = ConfigIPAddress ,
784- Subnetmask = subnetmask ,
785- Gateway = ConfigGateway ,
786- EnableStaticDNS = ConfigEnableStaticDNS ,
787- PrimaryDNSServer = ConfigPrimaryDNSServer ,
788- SecondaryDNSServer = ConfigSecondaryDNSServer
789- } ;
790-
791- try
792- {
793- Models . Network . NetworkInterface networkInterface = new Models . Network . NetworkInterface ( ) ;
794-
795- networkInterface . UserHasCanceled += NetworkInterface_UserHasCanceled ;
796-
797- await networkInterface . ConfigureNetworkInterfaceAsync ( config ) ;
798-
799- ReloadNetworkInterfacesAction ( ) ;
800- }
801- catch ( Exception ex )
802- {
803- StatusMessage = ex . Message ;
804- DisplayStatusMessage = true ;
805- }
806- finally
807- {
808- await progressDialogController . CloseAsync ( ) ;
809- }
771+ ApplyNetworkInterfaceConfig ( ) ;
810772 }
811773
812774 public ICommand ApplyProfileCommand
@@ -816,67 +778,7 @@ public ICommand ApplyProfileCommand
816778
817779 private async void ApplyProfileAction ( )
818780 {
819- DisplayStatusMessage = false ;
820-
821- progressDialogController = await dialogCoordinator . ShowProgressAsync ( this , Application . Current . Resources [ "String_Header_ConfigureNetworkInterface" ] as string , string . Empty ) ;
822- progressDialogController . SetIndeterminate ( ) ;
823-
824- string subnetmask = SelectedProfile . Subnetmask ;
825-
826- // CIDR to subnetmask
827- if ( SelectedProfile . EnableStaticIPAddress && subnetmask . StartsWith ( "/" ) )
828- subnetmask = Subnetmask . GetFromCidr ( int . Parse ( subnetmask . TrimStart ( '/' ) ) ) . Subnetmask ;
829-
830- bool enableStaticDNS = SelectedProfile . EnableStaticDNS ;
831-
832- string primaryDNSServer = SelectedProfile . PrimaryDNSServer ;
833- string secondaryDNSServer = SelectedProfile . SecondaryDNSServer ;
834-
835- Debug . WriteLine ( primaryDNSServer ) ;
836- Debug . WriteLine ( secondaryDNSServer ) ;
837-
838- // If primary and secondary DNS are empty --> autoconfiguration
839- if ( enableStaticDNS && string . IsNullOrEmpty ( primaryDNSServer ) && string . IsNullOrEmpty ( secondaryDNSServer ) )
840- enableStaticDNS = false ;
841-
842- // When primary DNS is empty, swap it with secondary (if not empty)
843- if ( SelectedProfile . EnableStaticDNS && string . IsNullOrEmpty ( primaryDNSServer ) && ! string . IsNullOrEmpty ( secondaryDNSServer ) )
844- {
845- primaryDNSServer = secondaryDNSServer ;
846- secondaryDNSServer = string . Empty ;
847- }
848-
849- NetworkInterfaceConfig config = new NetworkInterfaceConfig
850- {
851- Name = SelectedNetworkInterface . Name ,
852- EnableStaticIPAddress = SelectedProfile . EnableStaticIPAddress ,
853- IPAddress = SelectedProfile . IPAddress ,
854- Subnetmask = subnetmask ,
855- Gateway = SelectedProfile . Gateway ,
856- EnableStaticDNS = enableStaticDNS ,
857- PrimaryDNSServer = primaryDNSServer ,
858- SecondaryDNSServer = secondaryDNSServer
859- } ;
860-
861- try
862- {
863- Models . Network . NetworkInterface networkInterface = new Models . Network . NetworkInterface ( ) ;
864-
865- networkInterface . UserHasCanceled += NetworkInterface_UserHasCanceled ;
866-
867- await networkInterface . ConfigureNetworkInterfaceAsync ( config ) ;
868-
869- ReloadNetworkInterfacesAction ( ) ;
870- }
871- catch ( Exception ex )
872- {
873- StatusMessage = ex . Message ;
874- DisplayStatusMessage = true ;
875- }
876- finally
877- {
878- await progressDialogController . CloseAsync ( ) ;
879- }
781+ ApplyProfile ( ) ;
880782 }
881783
882784 public ICommand AddProfileCommand
@@ -1072,14 +974,141 @@ private async void EditGroupAction(object group)
1072974 await dialogCoordinator . ShowMetroDialogAsync ( this , customDialog ) ;
1073975 }
1074976
1075- public ICommand FlushDNSCommand
977+ public ICommand FlushDNSCacheCommand
1076978 {
1077- get { return new RelayCommand ( p => FlushDNSAction ( ) ) ; }
979+ get { return new RelayCommand ( p => FlushDNSCacheAction ( ) ) ; }
1078980 }
1079981
1080- private void FlushDNSAction ( )
982+ private void FlushDNSCacheAction ( )
1081983 {
1082- Models . Network . NetworkInterface . FlusDnsResolverCache ( ) ;
984+ FlushDNSCache ( ) ;
985+ }
986+ #endregion
987+
988+ #region Methods
989+ public async void ApplyNetworkInterfaceConfig ( )
990+ {
991+ IsConfigurationRunning = true ;
992+ DisplayStatusMessage = false ;
993+
994+ string subnetmask = ConfigSubnetmaskOrCidr ;
995+
996+ // CIDR to subnetmask
997+ if ( ConfigEnableStaticIPAddress && subnetmask . StartsWith ( "/" ) )
998+ subnetmask = Subnetmask . GetFromCidr ( int . Parse ( subnetmask . TrimStart ( '/' ) ) ) . Subnetmask ;
999+
1000+ // If primary and secondary DNS are empty --> autoconfiguration
1001+ if ( ConfigEnableStaticDNS && string . IsNullOrEmpty ( ConfigPrimaryDNSServer ) && string . IsNullOrEmpty ( ConfigSecondaryDNSServer ) )
1002+ ConfigEnableDynamicDNS = true ;
1003+
1004+ // When primary DNS is empty, swap it with secondary (if not empty)
1005+ if ( ConfigEnableStaticDNS && string . IsNullOrEmpty ( ConfigPrimaryDNSServer ) && ! string . IsNullOrEmpty ( ConfigSecondaryDNSServer ) )
1006+ {
1007+ ConfigPrimaryDNSServer = ConfigSecondaryDNSServer ;
1008+ ConfigSecondaryDNSServer = string . Empty ;
1009+ }
1010+
1011+ NetworkInterfaceConfig config = new NetworkInterfaceConfig
1012+ {
1013+ Name = SelectedNetworkInterface . Name ,
1014+ EnableStaticIPAddress = ConfigEnableStaticIPAddress ,
1015+ IPAddress = ConfigIPAddress ,
1016+ Subnetmask = subnetmask ,
1017+ Gateway = ConfigGateway ,
1018+ EnableStaticDNS = ConfigEnableStaticDNS ,
1019+ PrimaryDNSServer = ConfigPrimaryDNSServer ,
1020+ SecondaryDNSServer = ConfigSecondaryDNSServer
1021+ } ;
1022+
1023+ try
1024+ {
1025+ Models . Network . NetworkInterface networkInterface = new Models . Network . NetworkInterface ( ) ;
1026+
1027+ networkInterface . UserHasCanceled += NetworkInterface_UserHasCanceled ;
1028+
1029+ await networkInterface . ConfigureNetworkInterfaceAsync ( config ) ;
1030+
1031+ ReloadNetworkInterfacesAction ( ) ;
1032+ }
1033+ catch ( Exception ex )
1034+ {
1035+ StatusMessage = ex . Message ;
1036+ DisplayStatusMessage = true ;
1037+ }
1038+ finally
1039+ {
1040+ IsConfigurationRunning = false ;
1041+ }
1042+ }
1043+
1044+ public async void ApplyProfile ( )
1045+ {
1046+ IsConfigurationRunning = true ;
1047+ DisplayStatusMessage = false ;
1048+
1049+ string subnetmask = SelectedProfile . Subnetmask ;
1050+
1051+ // CIDR to subnetmask
1052+ if ( SelectedProfile . EnableStaticIPAddress && subnetmask . StartsWith ( "/" ) )
1053+ subnetmask = Subnetmask . GetFromCidr ( int . Parse ( subnetmask . TrimStart ( '/' ) ) ) . Subnetmask ;
1054+
1055+ bool enableStaticDNS = SelectedProfile . EnableStaticDNS ;
1056+
1057+ string primaryDNSServer = SelectedProfile . PrimaryDNSServer ;
1058+ string secondaryDNSServer = SelectedProfile . SecondaryDNSServer ;
1059+
1060+ // If primary and secondary DNS are empty --> autoconfiguration
1061+ if ( enableStaticDNS && string . IsNullOrEmpty ( primaryDNSServer ) && string . IsNullOrEmpty ( secondaryDNSServer ) )
1062+ enableStaticDNS = false ;
1063+
1064+ // When primary DNS is empty, swap it with secondary (if not empty)
1065+ if ( SelectedProfile . EnableStaticDNS && string . IsNullOrEmpty ( primaryDNSServer ) && ! string . IsNullOrEmpty ( secondaryDNSServer ) )
1066+ {
1067+ primaryDNSServer = secondaryDNSServer ;
1068+ secondaryDNSServer = string . Empty ;
1069+ }
1070+
1071+ NetworkInterfaceConfig config = new NetworkInterfaceConfig
1072+ {
1073+ Name = SelectedNetworkInterface . Name ,
1074+ EnableStaticIPAddress = SelectedProfile . EnableStaticIPAddress ,
1075+ IPAddress = SelectedProfile . IPAddress ,
1076+ Subnetmask = subnetmask ,
1077+ Gateway = SelectedProfile . Gateway ,
1078+ EnableStaticDNS = enableStaticDNS ,
1079+ PrimaryDNSServer = primaryDNSServer ,
1080+ SecondaryDNSServer = secondaryDNSServer
1081+ } ;
1082+
1083+ try
1084+ {
1085+ Models . Network . NetworkInterface networkInterface = new Models . Network . NetworkInterface ( ) ;
1086+
1087+ networkInterface . UserHasCanceled += NetworkInterface_UserHasCanceled ;
1088+
1089+ await networkInterface . ConfigureNetworkInterfaceAsync ( config ) ;
1090+
1091+ ReloadNetworkInterfacesAction ( ) ;
1092+ }
1093+ catch ( Exception ex )
1094+ {
1095+ StatusMessage = ex . Message ;
1096+ DisplayStatusMessage = true ;
1097+ }
1098+ finally
1099+ {
1100+ IsConfigurationRunning = false ;
1101+ }
1102+ }
1103+
1104+ public void FlushDNSCache ( )
1105+ {
1106+ IsConfigurationRunning = true ;
1107+ DisplayStatusMessage = false ;
1108+
1109+ Models . Network . NetworkInterface . FlushDnsResolverCache ( ) ;
1110+
1111+ IsConfigurationRunning = false ;
10831112 }
10841113 #endregion
10851114
0 commit comments