diff --git a/Source/NETworkManager/Models/Settings/NetworkInterfaceProfileManager.cs b/Source/NETworkManager/Models/Settings/NetworkInterfaceProfileManager.cs index ddd8ada22e..1824740335 100644 --- a/Source/NETworkManager/Models/Settings/NetworkInterfaceProfileManager.cs +++ b/Source/NETworkManager/Models/Settings/NetworkInterfaceProfileManager.cs @@ -18,18 +18,20 @@ public static string GetProfilesFilePath() return Path.Combine(SettingsManager.GetSettingsLocation(), ProfilesFileName); } - public static void Load() + public static void Load(bool deserialize = true) { Profiles = new ObservableCollection(); - Deserialize().ForEach(profile => AddProfile(profile)); - + if (deserialize) + Deserialize().ForEach(profile => AddProfile(profile)); + Profiles.CollectionChanged += Profiles_CollectionChanged; } - public static void Reload() + public static void Import(bool overwrite) { - Profiles.Clear(); + if (overwrite) + Profiles.Clear(); Deserialize().ForEach(profile => AddProfile(profile)); } diff --git a/Source/NETworkManager/Models/Settings/WakeOnLANClientManager.cs b/Source/NETworkManager/Models/Settings/WakeOnLANClientManager.cs index 56cc4890ae..d61d65cde5 100644 --- a/Source/NETworkManager/Models/Settings/WakeOnLANClientManager.cs +++ b/Source/NETworkManager/Models/Settings/WakeOnLANClientManager.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; +using System.Windows; using System.Xml.Serialization; namespace NETworkManager.Models.Settings @@ -17,18 +18,20 @@ public static string GetClientsFilePath() return Path.Combine(SettingsManager.GetSettingsLocation(), ClientsFileName); } - public static void Load() + public static void Load(bool deserialize = true) { Clients = new ObservableCollection(); - Deserialize().ForEach(client => AddClient(client)); + if (deserialize) + Deserialize().ForEach(client => AddClient(client)); Clients.CollectionChanged += WakeOnLANClients_CollectionChanged; } - public static void Reload() + public static void Import(bool overwrite) { - Clients.Clear(); + if (overwrite) + Clients.Clear(); Deserialize().ForEach(client => AddClient(client)); } diff --git a/Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml b/Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml index f1f72337d6..988705aa78 100644 --- a/Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml +++ b/Source/NETworkManager/Resources/Localization/Resources.de-DE.xaml @@ -119,7 +119,6 @@ Standardgateway Template hinzufügen Geben Sie den Hostnamen ein, um den Client später zu identifizieren. - Alle Rechte vorbehalten. Administrator Neustart als Administrator Zum ändern dieser Konfiguration werden administrative Rechte benötigt. @@ -224,7 +223,9 @@ Wake on LAN Clients neu geladen Netzwerkinterface Profile neu geladen Kommt demnächst! - + überschreiben + hinzufügen + Wechseln Standard diff --git a/Source/NETworkManager/Resources/Localization/Resources.en-US.xaml b/Source/NETworkManager/Resources/Localization/Resources.en-US.xaml index bd03e80ef3..212719e558 100644 --- a/Source/NETworkManager/Resources/Localization/Resources.en-US.xaml +++ b/Source/NETworkManager/Resources/Localization/Resources.en-US.xaml @@ -119,7 +119,6 @@ Default-Gateway Add template Enter the hostname to identify the client later. - All rights reserved. Administrator Restart as Administrator Administrative rights are required to change this configuration. @@ -224,6 +223,8 @@ Wake on LAN clients reloaded Network interface profiles reloaded Coming Soon! + override + add Change diff --git a/Source/NETworkManager/ViewModels/Applications/NetworkInterfaceViewModel.cs b/Source/NETworkManager/ViewModels/Applications/NetworkInterfaceViewModel.cs index 6d72eae628..fc79ece546 100644 --- a/Source/NETworkManager/ViewModels/Applications/NetworkInterfaceViewModel.cs +++ b/Source/NETworkManager/ViewModels/Applications/NetworkInterfaceViewModel.cs @@ -134,7 +134,7 @@ public NetworkInterfaceInfo SelectedNetworkInterface DetailsDNSServer = value.DNSServer; // Configuration - if(value.DhcpEnabled) + if (value.DhcpEnabled) { ConfigEnableDynamicIPAddress = true; } @@ -146,7 +146,7 @@ public NetworkInterfaceInfo SelectedNetworkInterface ConfigGateway = value.IPv4Gateway.FirstOrDefault().ToString(); } - if(value.DNSAutoconfigurationEnabled) + if (value.DNSAutoconfigurationEnabled) { ConfigEnableDynamicDNS = true; } @@ -155,7 +155,7 @@ public NetworkInterfaceInfo SelectedNetworkInterface ConfigEnableStaticDNS = true; List DNSServers = value.DNSServer.Where(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToList(); - ConfigPrimaryDNSServer = DNSServers.Count > 0 ? DNSServers[0].ToString() : string.Empty ; + ConfigPrimaryDNSServer = DNSServers.Count > 0 ? DNSServers[0].ToString() : string.Empty; ConfigSecondaryDNSServer = DNSServers.Count > 1 ? DNSServers[1].ToString() : string.Empty; } @@ -629,7 +629,9 @@ public NetworkInterfaceViewModel(IDialogCoordinator instance) LoadNetworkInterfaces(); // Load profiles - NetworkInterfaceProfileManager.Load(); + if (NetworkInterfaceProfileManager.Profiles == null) + NetworkInterfaceProfileManager.Load(); + _networkInterfaceProfiles = CollectionViewSource.GetDefaultView(NetworkInterfaceProfileManager.Profiles); LoadSettings(); diff --git a/Source/NETworkManager/ViewModels/Applications/WakeOnLanViewModel.cs b/Source/NETworkManager/ViewModels/Applications/WakeOnLanViewModel.cs index 9d7d07db68..ab3a76fe10 100644 --- a/Source/NETworkManager/ViewModels/Applications/WakeOnLanViewModel.cs +++ b/Source/NETworkManager/ViewModels/Applications/WakeOnLanViewModel.cs @@ -153,7 +153,9 @@ public WakeOnLANViewModel(IDialogCoordinator instance) { dialogCoordinator = instance; - WakeOnLANClientManager.Load(); + if (WakeOnLANClientManager.Clients == null) + WakeOnLANClientManager.Load(); + _wakeOnLANClients = CollectionViewSource.GetDefaultView(WakeOnLANClientManager.Clients); LoadSettings(); diff --git a/Source/NETworkManager/ViewModels/Settings/SettingsGeneralImportExportViewModel.cs b/Source/NETworkManager/ViewModels/Settings/SettingsGeneralImportExportViewModel.cs index 5a10311e56..caaf70e556 100644 --- a/Source/NETworkManager/ViewModels/Settings/SettingsGeneralImportExportViewModel.cs +++ b/Source/NETworkManager/ViewModels/Settings/SettingsGeneralImportExportViewModel.cs @@ -119,6 +119,20 @@ public bool ImportNetworkInterfaceProfiles } } + private bool _importOverrideNetworkInterfaceProfiles = true; + public bool ImportOverrideNetworkInterfaceProfiles + { + get { return _importOverrideNetworkInterfaceProfiles; } + set + { + if (value == _importOverrideNetworkInterfaceProfiles) + return; + + _importOverrideNetworkInterfaceProfiles = value; + OnPropertyChanged(); + } + } + private bool _importWakeOnLANClientsExists; public bool ImportWakeOnLANClientsExists { @@ -146,6 +160,20 @@ public bool ImportWakeOnLANClients OnPropertyChanged(); } } + + private bool _importOverrideWakeOnLANClients = true; + public bool ImportOverrideWakeOnLANClients + { + get { return _importOverrideWakeOnLANClients; } + set + { + if (value == _importOverrideWakeOnLANClients) + return; + + _importOverrideWakeOnLANClients = value; + OnPropertyChanged(); + } + } #endregion #region Export @@ -327,35 +355,44 @@ private async void ImportSettingsAction() if (ImportWakeOnLANClientsExists && (ImportEverything || ImportWakeOnLANClients)) importOptions.Add(ImportExportManager.ImportExportOptions.WakeOnLANClients); + // Load network interface profile (option: add) + if (NetworkInterfaceProfileManager.Profiles == null) + NetworkInterfaceProfileManager.Load(!ImportOverrideNetworkInterfaceProfiles); + + // Load WoL clients (option: add) + if (WakeOnLANClientManager.Clients == null) + WakeOnLANClientManager.Load(!ImportOverrideWakeOnLANClients); + + // Import (copy) files from zip archive ImportExportManager.Import(ImportLocationSelectedPath, importOptions); - // Restart if application settings are changed - if (ImportExportManager.ForceRestart) - { - CloseAction(); - } - else + // Do the import (replace or add) + if (importOptions.Contains(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles)) + NetworkInterfaceProfileManager.Import(ImportEverything || ImportOverrideNetworkInterfaceProfiles); + + if (importOptions.Contains(ImportExportManager.ImportExportOptions.WakeOnLANClients)) + WakeOnLANClientManager.Import(ImportEverything || ImportOverrideWakeOnLANClients); + + // Show the user a message what happened + if (!ImportExportManager.ForceRestart) { settings.AffirmativeButtonText = Application.Current.Resources["String_Button_OK"] as string; message = Application.Current.Resources["String_SettingsSuccessfullyImported"] as string + Environment.NewLine; if (importOptions.Contains(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles)) - { - NetworkInterfaceProfileManager.Reload(); - message += Environment.NewLine + string.Format("* {0}", Application.Current.Resources["String_NetworkInterfaceProfilesReloaded"] as string); - } if (importOptions.Contains(ImportExportManager.ImportExportOptions.WakeOnLANClients)) - { - WakeOnLANClientManager.Reload(); - message += Environment.NewLine + string.Format("* {0}", Application.Current.Resources["String_WakeOnLANClientsReloaded"] as string); - } await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_Success"] as string, message, MessageDialogStyle.Affirmative, settings); + + return; } + + // Close this view (this will restart the application) + CloseAction(); } } @@ -370,7 +407,7 @@ private async void ExportSettingsAction() if (ApplicationSettingsExists && (ExportEverything || ExportApplicationSettings)) exportOptions.Add(ImportExportManager.ImportExportOptions.ApplicationSettings); - + if (NetworkInterfaceProfilesExists && (ExportEverything || ExportNetworkInterfaceProfiles)) exportOptions.Add(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles); diff --git a/Source/NETworkManager/Views/Settings/SettingsGeneralImportExportView.xaml b/Source/NETworkManager/Views/Settings/SettingsGeneralImportExportView.xaml index dfa99a4a9d..85011c7311 100644 --- a/Source/NETworkManager/Views/Settings/SettingsGeneralImportExportView.xaml +++ b/Source/NETworkManager/Views/Settings/SettingsGeneralImportExportView.xaml @@ -44,7 +44,7 @@ - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +