Skip to content

Commit a96bfc7

Browse files
committed
Dialog removed, progress bar added
1 parent ff9a349 commit a96bfc7

5 files changed

Lines changed: 172 additions & 127 deletions

File tree

‎Source/NETworkManager/Models/Network/NetworkInterface.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void ConfigureNetworkInterface(NetworkInterfaceConfig config)
158158
[DllImport("dnsapi.dll", EntryPoint = "DnsFlushResolverCache")]
159159
private static extern UInt32 DnsFlushResolverCache();
160160

161-
public static void FlusDnsResolverCache()
161+
public static void FlushDnsResolverCache()
162162
{
163163
UInt32 result = DnsFlushResolverCache();
164164
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
<system:String x:Key="String_Header_AddCredential">Anmeldeinformation hinzufügen</system:String>
9292
<system:String x:Key="String_Header_EditCredential">Anmeldeinformation bearbeiten</system:String>
9393
<system:String x:Key="String_Header_DeleteCredential">Anmeldeinformation löschen</system:String>
94-
<system:String x:Key="String_Header_ConfigureNetworkInterface">Konfiguriere Netzwerkinterface</system:String>
9594
<system:String x:Key="String_Header_Authentication">Authentifizierung</system:String>
9695
<system:String x:Key="String_Header_CredentialNotFound">Anmeldeinformation nicht gefunden!</system:String>
9796
<system:String x:Key="String_Header_ConnectAs">Verbinden als</system:String>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
<system:String x:Key="String_Header_AddCredential">Add credential</system:String>
9292
<system:String x:Key="String_Header_EditCredential">Edit credential</system:String>
9393
<system:String x:Key="String_Header_DeleteCredential">Delete credential</system:String>
94-
<system:String x:Key="String_Header_ConfigureNetworkInterface">Configure Network Interface</system:String>
9594
<system:String x:Key="String_Header_Authentication">Authentication</system:String>
9695
<system:String x:Key="String_Header_CredentialNotFound">Credential not found!</system:String>
9796
<system:String x:Key="String_Header_ConnectAs">Connect as</system:String>

‎Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs‎

Lines changed: 148 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -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

‎Source/NETworkManager/Views/NetworkInterfaceView.xaml‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
xmlns:IconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
88
xmlns:Converter="clr-namespace:NETworkManager.Converters"
99
xmlns:Validator="clr-namespace:NETworkManager.Validators"
10+
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
1011
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
1112
xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
1213
Dialog:DialogParticipation.Register="{Binding}"
@@ -46,7 +47,7 @@
4647
</Style.Triggers>
4748
</Style>
4849
</UserControl.Resources>
49-
<TabControl Style="{StaticResource DefaultTabControl}">
50+
<TabControl Style="{StaticResource DefaultTabControl}">
5051
<TabItem Header="{DynamicResource String_Header_Information}">
5152
<ScrollViewer Margin="10" Style="{StaticResource DefaultScrollViewer}">
5253
<Grid>
@@ -304,6 +305,8 @@
304305
<RowDefinition Height="*" />
305306
<RowDefinition Height="10" />
306307
<RowDefinition Height="Auto" />
308+
<RowDefinition Height="Auto" />
309+
<RowDefinition Height="Auto" />
307310
</Grid.RowDefinitions>
308311
<ScrollViewer Grid.Row="0" Style="{StaticResource DefaultScrollViewer}">
309312
<Grid>
@@ -403,7 +406,6 @@
403406
</Rectangle>
404407
</Button>
405408
<TextBlock Grid.Column="0" Grid.Row="1" Foreground="{DynamicResource AccentColorBrush}" Text="{DynamicResource String_ConnectTheNetworkCardToConfigureIt}" Visibility="{Binding CanConfigure, Converter={StaticResource BooleanReverseToVisibilityConverter}}" Style="{DynamicResource DefaultTextBlock}" Margin="0,10,0,0" />
406-
<TextBlock Grid.Column="0" Grid.Row="2" Foreground="{DynamicResource AccentColorBrush}" Text="{Binding StatusMessage}" Visibility="{Binding DisplayStatusMessage, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{DynamicResource DefaultTextBlock}" Margin="0,10,0,0" />
407409
</Grid>
408410
</StackPanel>
409411
<TextBlock Grid.Row="1" Style="{StaticResource HeaderTextBlock}" Text="{DynamicResource String_Header_Configure}" />
@@ -533,13 +535,26 @@
533535
</GroupBox>
534536
</StackPanel>
535537
</Grid>
536-
</ScrollViewer>
537-
<Grid Grid.Row="3">
538+
</ScrollViewer>
539+
<Controls:MetroProgressBar Grid.Row="2" Foreground="{DynamicResource AccentColorBrush}" IsIndeterminate="True" Margin="0,0,0,10">
540+
<Controls:MetroProgressBar.Style>
541+
<Style TargetType="{x:Type Controls:MetroProgressBar}">
542+
<Setter Property="Visibility" Value="Collapsed" />
543+
<Style.Triggers>
544+
<DataTrigger Binding="{Binding IsConfigurationRunning}" Value="True">
545+
<Setter Property="Visibility" Value="Visible" />
546+
</DataTrigger>
547+
</Style.Triggers>
548+
</Style>
549+
</Controls:MetroProgressBar.Style>
550+
</Controls:MetroProgressBar>
551+
<TextBlock Grid.Row="3" Foreground="{DynamicResource AccentColorBrush}" Text="{Binding StatusMessage}" Visibility="{Binding DisplayStatusMessage, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{DynamicResource DefaultTextBlock}" Margin="0,0,0,10" />
552+
<Grid Grid.Row="4">
538553
<Grid.ColumnDefinitions>
539554
<ColumnDefinition Width="*" />
540555
<ColumnDefinition Width="Auto" />
541556
</Grid.ColumnDefinitions>
542-
<Button Grid.Column="0" HorizontalAlignment="Left" Command="{Binding FlushDNSCommand}" Style="{StaticResource ImageWithTextButton}">
557+
<Button Grid.Column="0" HorizontalAlignment="Left" Command="{Binding FlushDNSCacheCommand}" IsEnabled="{Binding IsConfigurationRunning, Converter={StaticResource BooleanReverseConverter}}" Style="{StaticResource ImageWithTextButton}">
543558
<Button.Content>
544559
<Grid>
545560
<Grid.ColumnDefinitions>
@@ -590,6 +605,9 @@
590605
</DataTrigger.Binding>
591606
<Setter Property="IsEnabled" Value="False" />
592607
</DataTrigger>
608+
<DataTrigger Binding="{Binding IsConfigurationRunning}" Value="True">
609+
<Setter Property="IsEnabled" Value="False" />
610+
</DataTrigger>
593611
</Style.Triggers>
594612
</Style>
595613
</Button.Style>

0 commit comments

Comments
 (0)