Exemplo n.º 1
0
        private async void EditGroupAction(object group)
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = LocalizationManager.GetStringByKey("String_Header_EditGroup")
            };

            GroupViewModel editGroupViewModel = new GroupViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                PingProfileManager.RenameGroup(instance.OldGroup, instance.Group);

                _pingProfiles.Refresh();
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, group.ToString());

            customDialog.Content = new GroupDialog
            {
                DataContext = editGroupViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
Exemplo n.º 2
0
        private async void CopyAsProfileAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = LocalizationManager.GetStringByKey("String_Header_CopyProfile")
            };

            PingProfileViewModel pingProfileViewModel = new PingProfileViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                PingProfileInfo pingProfileInfo = new PingProfileInfo
                {
                    Name  = instance.Name,
                    Host  = instance.Host,
                    Group = instance.Group,
                    Tags  = instance.Tags
                };

                PingProfileManager.AddProfile(pingProfileInfo);
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, PingProfileManager.GetProfileGroups(), SelectedProfile);

            customDialog.Content = new PingProfileDialog
            {
                DataContext = pingProfileViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
Exemplo n.º 3
0
        public void SaveAndCheckSettings()
        {
            // Save everything
            if (SettingsManager.Current.SettingsChanged)
            {
                SettingsManager.Save();
            }

            if (NetworkInterfaceProfileManager.ProfilesChanged)
            {
                NetworkInterfaceProfileManager.Save();
            }

            if (IPScannerProfileManager.ProfilesChanged)
            {
                IPScannerProfileManager.Save();
            }

            if (PortScannerProfileManager.ProfilesChanged)
            {
                PortScannerProfileManager.Save();
            }

            if (PingProfileManager.ProfilesChanged)
            {
                PingProfileManager.Save();
            }

            if (TracerouteProfileManager.ProfilesChanged)
            {
                TracerouteProfileManager.Save();
            }

            if (RemoteDesktopSessionManager.SessionsChanged)
            {
                RemoteDesktopSessionManager.Save();
            }

            if (PuTTYSessionManager.SessionsChanged)
            {
                PuTTYSessionManager.Save();
            }

            if (WakeOnLANClientManager.ClientsChanged)
            {
                WakeOnLANClientManager.Save();
            }

            // Check if files exist
            ApplicationSettingsExists      = File.Exists(SettingsManager.GetSettingsFilePath());
            NetworkInterfaceProfilesExists = File.Exists(NetworkInterfaceProfileManager.GetProfilesFilePath());
            IPScannerProfilesExists        = File.Exists(IPScannerProfileManager.GetProfilesFilePath());
            PortScannerProfilesExists      = File.Exists(PortScannerProfileManager.GetProfilesFilePath());
            PingProfilesExists             = File.Exists(PingProfileManager.GetProfilesFilePath());
            TracerouteProfilesExists       = File.Exists(TracerouteProfileManager.GetProfilesFilePath());
            RemoteDesktopSessionsExists    = File.Exists(RemoteDesktopSessionManager.GetSessionsFilePath());
            PuTTYSessionsExists            = File.Exists(PuTTYSessionManager.GetSessionsFilePath());
            WakeOnLANClientsExists         = File.Exists(WakeOnLANClientManager.GetClientsFilePath());
        }
Exemplo n.º 4
0
        private void Application_Exit(object sender, ExitEventArgs e)
        {
            // Save settings, when the application is normally closed
            if (!_singleInstanceClose && !ImportExportManager.ForceRestart && !CommandLineManager.Current.Help)
            {
                // Save local settings (custom settings path in AppData/Local)
                Settings.Default.Save();

                if (SettingsManager.Current.SettingsChanged) // This will also create the "Settings" folder, if it does not exist
                {
                    SettingsManager.Save();
                }

                if (CredentialManager.CredentialsChanged)
                {
                    CredentialManager.Save();
                }

                if (NetworkInterfaceProfileManager.ProfilesChanged)
                {
                    NetworkInterfaceProfileManager.Save();
                }

                if (IPScannerProfileManager.ProfilesChanged)
                {
                    IPScannerProfileManager.Save();
                }

                if (PortScannerProfileManager.ProfilesChanged)
                {
                    PortScannerProfileManager.Save();
                }

                if (PingProfileManager.ProfilesChanged)
                {
                    PingProfileManager.Save();
                }

                if (TracerouteProfileManager.ProfilesChanged)
                {
                    TracerouteProfileManager.Save();
                }

                if (RemoteDesktopSessionManager.SessionsChanged)
                {
                    RemoteDesktopSessionManager.Save();
                }

                if (PuTTYSessionManager.SessionsChanged)
                {
                    PuTTYSessionManager.Save();
                }

                if (WakeOnLANClientManager.ClientsChanged)
                {
                    WakeOnLANClientManager.Save();
                }
            }
        }
Exemplo n.º 5
0
        public PingHostViewModel(IDialogCoordinator instance)
        {
            dialogCoordinator = instance;

            InterTabClient = new DragablzInterTabClient(ApplicationViewManager.Name.Ping);

            TabItems = new ObservableCollection <DragablzTabItem>()
            {
                new DragablzTabItem(LocalizationManager.GetStringByKey("String_Header_NewTab"), new PingView(_tabId), _tabId)
            };

            // Load profiles
            if (PingProfileManager.Profiles == null)
            {
                PingProfileManager.Load();
            }

            _pingProfiles = CollectionViewSource.GetDefaultView(PingProfileManager.Profiles);
            _pingProfiles.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
            _pingProfiles.SortDescriptions.Add(new SortDescription("Group", ListSortDirection.Ascending));
            _pingProfiles.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
            _pingProfiles.Filter = o =>
            {
                if (string.IsNullOrEmpty(Search))
                {
                    return(true);
                }

                PingProfileInfo info = o as PingProfileInfo;

                string search = Search.Trim();

                // Search by: Tag
                if (search.StartsWith(tagIdentifier, StringComparison.OrdinalIgnoreCase))
                {
                    if (string.IsNullOrEmpty(info.Tags))
                    {
                        return(false);
                    }
                    else
                    {
                        return(info.Tags.Replace(" ", "").Split(';').Any(str => search.Substring(tagIdentifier.Length, search.Length - tagIdentifier.Length).IndexOf(str, StringComparison.OrdinalIgnoreCase) > -1));
                    }
                }
                else // Search by: Name, Hostname
                {
                    return(info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1 || info.Host.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1);
                }
            };

            LoadSettings();

            _isLoading = false;
        }
Exemplo n.º 6
0
        private async void DeleteProfileAction()
        {
            CustomDialog customDialog = new CustomDialog()
            {
                Title = LocalizationManager.GetStringByKey("String_Header_DeleteProfile")
            };

            ConfirmRemoveViewModel confirmRemoveViewModel = new ConfirmRemoveViewModel(instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);

                PingProfileManager.RemoveProfile(SelectedProfile);
            }, instance =>
            {
                dialogCoordinator.HideMetroDialogAsync(this, customDialog);
            }, LocalizationManager.GetStringByKey("String_DeleteProfileMessage"));

            customDialog.Content = new ConfirmRemoveDialog
            {
                DataContext = confirmRemoveViewModel
            };

            await dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        public async void ResetSettingsAction()
        {
            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_SelectedSettingsAreReset");

            if (ResetEverything || ResetApplicationSettings)
            {
                message += Environment.NewLine + Environment.NewLine + string.Format("* {0}", LocalizationManager.GetStringByKey("String_TheSettingsLocationIsNotAffected"));
                message += 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)
            {
                return;
            }

            bool forceRestart = false;

            if (ApplicationSettingsExists && (ResetEverything || ResetApplicationSettings))
            {
                SettingsManager.Reset();
                forceRestart = true;
            }

            if (NetworkInterfaceProfilesExists && (ResetEverything || ResetNetworkInterfaceProfiles))
            {
                NetworkInterfaceProfileManager.Reset();
            }

            if (IPScannerProfilesExists && (ResetEverything || ResetIPScannerProfiles))
            {
                IPScannerProfileManager.Reset();
            }

            if (PortScannerProfilesExists && (ResetEverything || ResetPortScannerProfiles))
            {
                PortScannerProfileManager.Reset();
            }

            if (PingProfilesExists && (ResetEverything || ResetPingProfiles))
            {
                PingProfileManager.Reset();
            }

            if (TracerouteProfilesExists && (ResetEverything || ResetTracerouteProfiles))
            {
                TracerouteProfileManager.Reset();
            }

            if (RemoteDesktopSessionsExists && (ResetEverything || ResetRemoteDesktopSessions))
            {
                RemoteDesktopSessionManager.Reset();
            }

            if (PuTTYSessionsExists && (ResetEverything || ResetPuTTYSessions))
            {
                PuTTYSessionManager.Reset();
            }

            if (WakeOnLANClientsExists && (ResetEverything || ResetWakeOnLANClients))
            {
                WakeOnLANClientManager.Reset();
            }

            // Restart after reset or show a completed message
            if (forceRestart)
            {
                CloseAction();
            }
            else
            {
                settings.AffirmativeButtonText = LocalizationManager.GetStringByKey("String_Button_OK");

                await dialogCoordinator.ShowMessageAsync(this, LocalizationManager.GetStringByKey("String_Header_Success"), LocalizationManager.GetStringByKey("String_SettingsSuccessfullyReset"), MessageDialogStyle.Affirmative, settings);
            }
        }