Example #1
0
        public void AfterDeploy(IDeployerEventSink host)
        {
            ServiceStatusWindow wnd = null;
            try
            {
                var msg = "Starting service...";
                wnd = new ServiceStatusWindow {StatusMessage = msg};
                wnd.Show();
                host.OnNotificationMessage(this, msg);

                Application.DoEvents();

                wnd.ProgressStep();

                // Start service
                var wc = new WebClient();
                var result = wc.DownloadString(_url + "&action=start");
                wnd.ProgressStep();
                if (!result.Contains("Running"))
                {
                    wnd.Hide();
                    MessageBox.Show("Failed to start service. You may need to restart it manually.", "Service controller",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    host.OnNotificationMessage(this, "Service started.");
                }

                wnd.Close();
                wnd = null;
            }
            finally
            {
                if(wnd != null)
                    wnd.Close();
            }
        }
Example #2
0
        public void BeforeDeploy(IDeployerEventSink host)
        {
            ServiceStatusWindow wnd = null;
            try
            {
                var msg = "Stopping service...";
                wnd = new ServiceStatusWindow {StatusMessage = msg};
                wnd.Show();
                host.OnNotificationMessage(this, msg);

                // Pump events to ensure window is shown
                Application.DoEvents();

                wnd.ProgressStep();

                // Stop service
                var wc = new WebClient();
                var result = wc.DownloadString(_url + "&action=stop");
                if(!result.Contains("Stopped"))
                {
                    wnd.Hide();

                    var dialogResult = MessageBox.Show("Unable to stop service. Do you want to deploy anyway?", "Service controller",
                                                       MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                    if(dialogResult == DialogResult.No)
                        throw new DeployCancelException("Unable to stop service.");
                }
                else
                {
                    wnd.ProgressStep();

                    // AFter stopping the service it takes a few seconds for it to proper shutdown so we wait a little extra
                    Thread.Sleep(TimeSpan.FromSeconds(5));

                    host.OnNotificationMessage(this, "Service stopped.");
                }

                wnd.Close();
                wnd = null;
            }
            finally
            {
                if(wnd != null)
                    wnd.Close();
            }
        }