Beispiel #1
0
        /// <summary>
        ///     Check if a server is still running before closing the GUI
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!ProcessHandler.IsRunning)
            {
                return;
            }

            if (ProcessHandler.CurrentState == ServerState.Starting ||
                ProcessHandler.CurrentState == ServerState.Running)
            {
                // if windows is shutting down or app is killed from task manager
                if (e.CloseReason == CloseReason.TaskManagerClosing || e.CloseReason == CloseReason.WindowsShutDown)
                {
                    // make sure to stop server to prevent data loss
                    ProcessHandler.StopServer();
                    return;
                }
                // ask what to do
                DialogResult result = MetroMessageBox.Show(this,
                                                           Locale.Tr(
                                                               "The server is still running. Closing it without a proper stop might result in data loss. Send stop command first?"),
                                                           Locale.Tr("Server still running"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);

                // execute a correct action based upon user input
                switch (result)
                {
                case DialogResult.Yes:
                    ProcessHandler.ServerStopped += SafeFormClose;
                    ProcessHandler.StopServer();
                    e.Cancel = true;
                    break;

                case DialogResult.No:
                    // close form
                    break;

                case DialogResult.Cancel:
                    e.Cancel = true;
                    break;
                }
            }
            else
            {
                // wait for server to stop
                ServerStopDialog serverStopDialog = new ServerStopDialog();
                DialogResult     result           = serverStopDialog.ShowDialog();
                // if waiting cancelled, don't shutdown
                if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Check if a server is still running before closing the GUI
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!ProcessHandler.IsRunning) return;

            if (ProcessHandler.CurrentState == ServerState.Starting ||
                ProcessHandler.CurrentState == ServerState.Running)
            {
                // if windows is shutting down or app is killed from task manager
                if (e.CloseReason == CloseReason.TaskManagerClosing || e.CloseReason == CloseReason.WindowsShutDown)
                {
                    // make sure to stop server to prevent data loss
                    ProcessHandler.StopServer();
                    return;
                }
                // ask what to do
                DialogResult result = MetroMessageBox.Show(this,
                    Locale.Tr(
                        "The server is still running. Closing it without a proper stop might result in data loss. Send stop command first?"),
                    Locale.Tr("Server still running"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);

                // execute a correct action based upon user input
                switch (result)
                {
                    case DialogResult.Yes:
                        ProcessHandler.ServerStopped += SafeFormClose;
                        ProcessHandler.StopServer();
                        e.Cancel = true;
                        break;
                    case DialogResult.No:
                        // close form
                        break;
                    case DialogResult.Cancel:
                        e.Cancel = true;
                        break;
                }
            }
            else
            {
                // wait for server to stop
                ServerStopDialog serverStopDialog = new ServerStopDialog();
                DialogResult result = serverStopDialog.ShowDialog();
                // if waiting cancelled, don't shutdown
                if (result == DialogResult.Cancel) e.Cancel = true;
            }
        }
 /// <summary>
 ///     Show a messagebox asking to stop the server, and if the user agrees, wait for the server to stop
 /// </summary>
 /// <returns>Returns true if the server has been stopped</returns>
 public static bool RequestServerStop()
 {
     if (IsRunning)
     {
         if (MetroMessageBox.Show(Application.OpenForms[0],
             "You want to perform an operation, which can't be executed while the server is running. Stop the server now?",
             "Server has to be stopped",
             MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return false;
         ServerStopDialog ssd = new ServerStopDialog();
         DialogResult result = ssd.ShowDialog();
         if (result != DialogResult.OK) return false;
     }
     return true;
 }