예제 #1
0
 private void OnExit_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to quit?", "Confirm quit", MessageBoxButtons.YesNo,
                         MessageBoxIcon.Question) == DialogResult.Yes)
     {
         bool quit = this.StopMailpile();
         if (quit)
         {
             this.mailpile.Close();
             Application.Exit();
         }
         SplashForm.CloseSplashScreen();
     }
 }
예제 #2
0
        private bool StopMailpile()
        {
            bool ok = true;

            if (!this.mailpile.HasExited)
            {
                SplashForm.ShowSplashScreen();
                string          value = ConfigurationManager.AppSettings["REQ_Quit"];
                HttpWebRequest  request;
                HttpWebResponse response;

                if (!value.Equals(""))
                {
                    try
                    {
                        request = (HttpWebRequest)WebRequest.Create(value);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Unable to stop Mailpile." + Environment.NewLine +
                                        "Exception: " + ex.Message, "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        request = null;
                        ok      = false;
                    }

                    if (ok)
                    {
                        try
                        {
                            response = (HttpWebResponse)request.GetResponse();
                        }
                        catch (Exception ex)
                        {
                            ok       = false;
                            response = null;
                        }
                    }
                    else
                    {
                        response = null;
                    }

                    if (!ok)
                    {
                        // no response from connection
                        return(true);
                    }

                    int statusCode = (int)response.StatusCode;

                    if (statusCode == (int)Status.OK)
                    {
                        string wait_s = ConfigurationManager.AppSettings["Quit_wait"];
                        int    wait;

                        try
                        {
                            wait = Convert.ToInt32(wait_s);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Cannot convert \"Quit_wait\" to int32."
                                            + Environment.NewLine +
                                            "Exception: " + ex.Message, "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            wait = 0;
                        }

                        Thread.Sleep(wait);
                        return(true);
                    }
                    else
                    {
                        MessageBox.Show("Unable to stop mailpile, HTTP response: " + statusCode.ToString(),
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SplashForm.CloseSplashScreen();
                        return(false);
                    }
                }
                else
                {
                    if (!this.mailpile.CloseMainWindow())
                    {
                        ok = false;
                    }
                }
            }

            return(ok);
        }