示例#1
0
        /// <summary>
        /// Raises the <see cref="Application.Exit" /> event.
        /// </summary>
        /// <param name="e">An <see cref="ExitEventArgs" /> that contains the event data.</param>
        protected override void OnExit(ExitEventArgs e)
        {
            this.logger.LogInformation("Exiting the application with exit code '{0}'", e.ApplicationExitCode);

            TunnelRelayStateManager.SaveSettingsToFile();
            TunnelRelayStateManager.ShutdownTunnelRelayAsync().ConfigureAwait(false).GetAwaiter().GetResult();
        }
        /// <summary>
        /// Starts the relay engine.
        /// </summary>
        private void StartRelayEngine()
        {
            Thread backGroundThread = new Thread(new ThreadStart(() =>
            {
                try
                {
                    TunnelRelayStateManager.InitializePlugins();
                    TunnelRelayStateManager.RelayRequestEventListener = this;
                    TunnelRelayStateManager.StartTunnelRelayAsync().ConfigureAwait(false).GetAwaiter().GetResult();

                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        this.txtProxyDetails.Text        = TunnelRelayStateManager.ApplicationData.HybridConnectionUrl + TunnelRelayStateManager.ApplicationData.HybridConnectionName;
                        this.btnExportSettings.IsEnabled = true;
                    }));
                }
                catch (Exception ex)
                {
                    this.logger.LogError(ex, "Failed to establish connection to Azure Relay");

                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        this.txtProxyDetails.Text        = "FAILED TO START AZURE PROXY!!!!";
                        this.btnExportSettings.IsEnabled = false;
                    }));
                }
            }));

            backGroundThread.Start();
        }
        /// <summary>
        /// Handles the Click event of the BtnLogin control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void BtnLogout_Click(object sender, RoutedEventArgs e)
        {
            TunnelRelayStateManager.LogoutAsync().ConfigureAwait(false).GetAwaiter().GetResult();

            MessageBox.Show("Logout Complete. Application will now close to complete cleanup. Open again to login");
            Application.Current.Shutdown();
        }
        /// <summary>
        /// Raises the <see cref="Window.Closed" /> event.
        /// </summary>
        /// <param name="e">An <see cref="EventArgs" /> that contains the event data.</param>
        protected override void OnClosed(EventArgs e)
        {
            try
            {
                Parallel.ForEach(TunnelRelayStateManager.Plugins.Where(plugin => plugin.IsEnabled), (plugin) => plugin.InitializePlugin());

                // Reload if the plugin configuration was changed.
                Task.Run(async() => await TunnelRelayStateManager.StartTunnelRelayAsync().ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, "Failed to set plugin settings");
                MessageBox.Show("Plugin initialization failed!!", "Plugin management", MessageBoxButton.OKCancel, MessageBoxImage.Error);
            }

            base.OnClosed(e);
        }