コード例 #1
0
        private async void App_Startup(object sender, StartupEventArgs e)
        {
            Settings = AppSettings.LoadFromFile(_settingsPath);
            if (Settings == null)
            {
                Settings = new AppSettings();
            }

            var mainWindow = new View.MainWindow();

            mainWindow.ViewModel = new ViewModel.MainWindowViewModel();

            bool exitApp = false;

            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                string address   = args[1];
                string uriScheme = ConfigurationManager.AppSettings["UriScheme"];
                address = address.Replace($"{uriScheme}:", "");
                OpenRdpResult openRdpResult = await RdpUtilities.OpenRdp(address, Settings.RDPFileSearchPath);

                switch (openRdpResult)
                {
                case OpenRdpResult.Success:
                    if (Settings.ExitOnSuccess)
                    {
                        exitApp = true;
                    }
                    break;

                case OpenRdpResult.NotFound:
                    MessageBoxResult messageBoxResult = MessageBox.Show($"Unable to find RDPfile for '{address}'.\nOpen new session?", "Information", MessageBoxButton.YesNo);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        RdpUtilities.StartNewRDP(address);
                        if (Settings.ExitOnSuccess)
                        {
                            exitApp = true;
                        }
                    }
                    break;
                }

                mainWindow.ViewModel.RDAddress = address;
            }

            if (exitApp)
            {
                App.Current.Shutdown();
            }
            else
            {
                mainWindow.Show();
            }
        }
コード例 #2
0
        private async void OpenRDP()
        {
            try
            {
                _openRDPCommand.Enabled = false;
                OpenRdpResult result = await RdpUtilities.OpenRdp(RDAddress, app.Settings.RDPFileSearchPath);

                switch (result)
                {
                case OpenRdpResult.Success:
                    if (app.Settings.ExitOnSuccess)
                    {
                        App.Current.Shutdown();
                    }
                    break;

                case OpenRdpResult.EmptyAddress:
                    MessageBox.Show($"The address cannot be empty.", "Error");
                    break;

                case OpenRdpResult.NotFound:
                    MessageBoxResult messageBoxResult = MessageBox.Show($"Unable to find RDPfile for '{RDAddress}'.\nOpen new session?", "Information", MessageBoxButton.YesNo);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        RdpUtilities.StartNewRDP(RDAddress);
                        if (app.Settings.ExitOnSuccess)
                        {
                            App.Current.Shutdown();
                        }
                    }
                    break;
                }
            }
            finally
            {
                _openRDPCommand.Enabled = true;
            }
        }