private void GetExecutionProgress()
        {
            ServiceOutcome serviceOutcome;

            ProgressState progressState;
            WebResponse   response = null;

            _executionTimer.Stop();
            WebRequest request = HttpWebRequest.Create(string.Format("{0}/Progress?sessionID={1}", _parentForm.BaseUri, _parentForm.Session));

            request.Timeout = 900000;

            try
            {
                response = request.GetResponse();
            }
            catch (Exception)
            {
                ///Read top 2 from log
                GetLog();
                progressExecute.Value = progressExecute.Maximum;;
            }

            DataContractSerializer serializer = new DataContractSerializer(typeof(ProgressState));

            using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
            {
                progressState = (ProgressState)serializer.ReadObject(reader, false);
                if (!string.IsNullOrEmpty(progressState.text))
                {
                    if (_lastText != progressState.text)
                    {
                        txtLog.Text += string.Format("\n{0}", progressState.text);
                        txtLog.Select(txtLog.Text.Length - 1, 0);
                        txtLog.ScrollToCaret();
                    }
                    _lastText = progressState.text;
                }
                txtLog.Text          += "...";
                progressExecute.Value = Convert.ToInt32((System.Math.Round((progressState.OverAllProgess * progressExecute.Maximum), 0)));
            }



            if (progressExecute.Value == progressExecute.Maximum)
            {
                progressExecute.Value = 0;

                request = HttpWebRequest.Create(string.Format("{0}/GetExecutorState?sessionID={1}", _parentForm.BaseUri, _parentForm.Session));

                try
                {
                    response = request.GetResponse();


                    serializer = new DataContractSerializer(typeof(ServiceOutcome));
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        serviceOutcome = (ServiceOutcome)serializer.ReadObject(reader, false);
                    }
                    switch (serviceOutcome)
                    {
                    case ServiceOutcome.Unspecified:
                    {
                        _executionTimer.Interval     = 1500;
                        _executionTimer.SourceObject = "Execute";
                        _executionTimer.Start();
                        System.Windows.Forms.Application.DoEvents();
                        break;
                    }

                    case ServiceOutcome.Success:
                    {
                        MessageBox.Show("Wizard Finished Successfuly!");
                        progressExecute.Value = 0;
                        break;
                    }

                    case ServiceOutcome.Failure:
                    {
                        MessageBox.Show("Execution failed!");
                        GetLog();

                        break;
                    }

                    case ServiceOutcome.Aborted:
                        break;

                    case ServiceOutcome.CouldNotBeScheduled:
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception)
                {
                    progressExecute.Value = 0;
                    MessageBox.Show("Wizard Finished");
                }
            }
            else
            {
                _executionTimer.Interval     = 3000;
                _executionTimer.SourceObject = "Execute";
                _executionTimer.Start();
                System.Windows.Forms.Application.DoEvents();
            }
        }
Beispiel #2
0
 void CheckServiceStateTimer_Tick(object sender, EventArgs e)
 {
     _serviceStateTimer.Stop();
     btnNewSession.Enabled = true;
 }