private async void ImportSettingsAction() { MetroDialogSettings settings = AppearanceManager.MetroDialog; settings.AffirmativeButtonText = LocalizationManager.GetStringByKey("String_Button_Continue"); settings.NegativeButtonText = LocalizationManager.GetStringByKey("String_Button_Cancel"); settings.DefaultButtonFocus = MessageDialogResult.Affirmative; string message = LocalizationManager.GetStringByKey("String_SelectedSettingsAreOverwritten"); if (ImportApplicationSettingsExists && (ImportEverything || ImportApplicationSettings)) { message += Environment.NewLine + Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_ApplicationIsRestartedAfterwards")); } if (await dialogCoordinator.ShowMessageAsync(this, LocalizationManager.GetStringByKey("String_Header_AreYouSure"), message, MessageDialogStyle.AffirmativeAndNegative, settings) == MessageDialogResult.Affirmative) { List <ImportExportManager.ImportExportOptions> importOptions = new List <ImportExportManager.ImportExportOptions>(); if (ImportApplicationSettingsExists && (ImportEverything || ImportApplicationSettings)) { importOptions.Add(ImportExportManager.ImportExportOptions.ApplicationSettings); } if (ImportNetworkInterfaceProfilesExists && (ImportEverything || ImportNetworkInterfaceProfiles)) { importOptions.Add(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles); // Load network interface profile (option: add) if (NetworkInterfaceProfileManager.Profiles == null) { NetworkInterfaceProfileManager.Load(!ImportOverrideNetworkInterfaceProfiles); } } if (ImportIPScannerProfilesExists && (ImportEverything || ImportIPScannerProfiles)) { importOptions.Add(ImportExportManager.ImportExportOptions.IPScannerProfiles); // Load ip scanner profiles (option: add) if (IPScannerProfileManager.Profiles == null) { IPScannerProfileManager.Load(!ImportOverrideIPScannerProfiles); } } if (ImportPingProfilesExists && (ImportEverything || ImportPingProfiles)) { importOptions.Add(ImportExportManager.ImportExportOptions.PingProfiles); // Load ping profiles (option: add) if (PingProfileManager.Profiles == null) { PingProfileManager.Load(!ImportOverridePingProfiles); } } if (ImportTracerouteProfilesExists && (ImportEverything || ImportTracerouteProfiles)) { importOptions.Add(ImportExportManager.ImportExportOptions.TracerouteProfiles); // Load traceroute profiles (option: add) if (TracerouteProfileManager.Profiles == null) { TracerouteProfileManager.Load(!ImportOverrideTracerouteProfiles); } } if (ImportPortScannerProfilesExists && (ImportEverything || ImportPortScannerProfiles)) { importOptions.Add(ImportExportManager.ImportExportOptions.PortScannerProfiles); // Load port scanner profiles (option: add) if (PortScannerProfileManager.Profiles == null) { PortScannerProfileManager.Load(!ImportOverridePortScannerProfiles); } } if (ImportRemoteDesktopSessionsExists && (ImportEverything || ImportRemoteDesktopSessions)) { importOptions.Add(ImportExportManager.ImportExportOptions.RemoteDesktopSessions); // Load remote desktop sessions (option: add) if (RemoteDesktopSessionManager.Sessions == null) { RemoteDesktopSessionManager.Load(!ImportOverrideRemoteDesktopSessions); } } if (ImportPuTTYSessionsExists && (ImportEverything || ImportPuTTYSessions)) { importOptions.Add(ImportExportManager.ImportExportOptions.PuTTYSessions); // Load remote desktop sessions (option: add) if (PuTTYSessionManager.Sessions == null) { RemoteDesktopSessionManager.Load(!ImportOverridePuTTYSessions); } } if (ImportWakeOnLANClientsExists && (ImportEverything || ImportWakeOnLANClients)) { importOptions.Add(ImportExportManager.ImportExportOptions.WakeOnLANClients); // Load WoL clients (option: add) if (WakeOnLANClientManager.Clients == null) { WakeOnLANClientManager.Load(!ImportOverrideWakeOnLANClients); } } // Import (copy) files from zip archive ImportExportManager.Import(ImportFilePath, importOptions); // Do the import (replace or add) if (importOptions.Contains(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles)) { NetworkInterfaceProfileManager.Import(ImportEverything || ImportOverrideNetworkInterfaceProfiles); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.IPScannerProfiles)) { IPScannerProfileManager.Import(ImportEverything || ImportOverrideIPScannerProfiles); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.PortScannerProfiles)) { PortScannerProfileManager.Import(ImportEverything || ImportOverridePortScannerProfiles); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.PingProfiles)) { PingProfileManager.Import(ImportEverything || ImportOverridePingProfiles); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.TracerouteProfiles)) { TracerouteProfileManager.Import(ImportEverything || ImportOverrideTracerouteProfiles); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.RemoteDesktopSessions)) { RemoteDesktopSessionManager.Import(ImportEverything || ImportOverrideRemoteDesktopSessions); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.PuTTYSessions)) { PuTTYSessionManager.Import(ImportEverything || ImportOverridePuTTYSessions); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.WakeOnLANClients)) { WakeOnLANClientManager.Import(ImportEverything || ImportOverrideWakeOnLANClients); } // Show the user a message what happened if (!ImportExportManager.ForceRestart) { settings.AffirmativeButtonText = LocalizationManager.GetStringByKey("String_Button_OK"); message = LocalizationManager.GetStringByKey("String_SettingsSuccessfullyImported") + Environment.NewLine; if (importOptions.Contains(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles)) { message += Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_NetworkInterfaceProfilesReloaded")); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.IPScannerProfiles)) { message += Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_IPScannerProfilesReloaded")); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.PortScannerProfiles)) { message += Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_PortScannerProfilesReloaded")); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.PingProfiles)) { message += Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_PingProfilesReloaded")); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.TracerouteProfiles)) { message += Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_TracerouteProfilesReloaded")); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.RemoteDesktopSessions)) { message += Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_RemoteDesktopSessionsReloaded")); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.PuTTYSessions)) { message += Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_PuTTYSessionsReloaded")); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.WakeOnLANClients)) { message += Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_WakeOnLANClientsReloaded")); } await dialogCoordinator.ShowMessageAsync(this, LocalizationManager.GetStringByKey("String_Header_Success"), message, MessageDialogStyle.Affirmative, settings); return; } // Close this view (this will restart the application) CloseAction(); } }
private async void ImportSettingsAction() { MetroDialogSettings settings = AppearanceManager.MetroDialog; settings.AffirmativeButtonText = Application.Current.Resources["String_Button_Continue"] as string; settings.NegativeButtonText = Application.Current.Resources["String_Button_Cancel"] as string; settings.DefaultButtonFocus = MessageDialogResult.Affirmative; string message = Application.Current.Resources["String_SelectedSettingsAreOverwritten"] as string; if (ImportApplicationSettingsExists && (ImportEverything || ImportApplicationSettings)) { message += Environment.NewLine + Environment.NewLine + string.Format("* {0}", Application.Current.Resources["String_ApplicationIsRestartedAfterwards"] as string); } if (await dialogCoordinator.ShowMessageAsync(this, Application.Current.Resources["String_Header_AreYouSure"] as string, message, MessageDialogStyle.AffirmativeAndNegative, settings) == MessageDialogResult.Affirmative) { List <ImportExportManager.ImportExportOptions> importOptions = new List <ImportExportManager.ImportExportOptions>(); if (ImportApplicationSettingsExists && (ImportEverything || ImportApplicationSettings)) { importOptions.Add(ImportExportManager.ImportExportOptions.ApplicationSettings); } if (ImportNetworkInterfaceProfilesExists && (ImportEverything || ImportNetworkInterfaceProfiles)) { importOptions.Add(ImportExportManager.ImportExportOptions.NetworkInterfaceProfiles); } 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); // 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)) { message += Environment.NewLine + string.Format("* {0}", Application.Current.Resources["String_NetworkInterfaceProfilesReloaded"] as string); } if (importOptions.Contains(ImportExportManager.ImportExportOptions.WakeOnLANClients)) { 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(); } }