/// <summary>
 /// Update the test run details.
 /// </summary>
 /// <param name="sender">Object that raised the event.</param>
 /// <param name="e">Event arguments.</param>
 private void refreshTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (Project != null)
     {
         PackageDeployResult result = Project.Client.Meta.CheckPackageDeploy(DeployId);
         App.Instance.Dispatcher.Invoke(new Action(() => UpdateStatus(result)));
     }
 }
        /// <summary>
        /// Update the status and set timer for next update.
        /// </summary>
        private void UpdateStatus(PackageDeployResult result)
        {
            // deployment section
            View.StatusText  = result.Status.ToString();
            View.PackageText = Package.Name;
            View.TargetText  = Project.ProjectName;
            View.NotesText   = IsCheckOnly ? "This is a check only deployment" : null;

            // components section
            if (result.ComponentsTotalCount == 0)
            {
                View.ComponentProgressMaximum    = 1;
                View.ComponentProgressValue      = 0;
                View.ComponentProgressMessage    = "Pending";
                View.ComponentProgressForeground = System.Windows.Media.Brushes.Green;
                View.ComponentProgressBackground = System.Windows.Media.Brushes.White;
            }
            else
            {
                // in progress
                if (!result.DeploymentComplete && result.ComponentsPassCount + result.ComponentsFailCount < result.ComponentsTotalCount)
                {
                    View.ComponentProgressMaximum = result.ComponentsTotalCount;
                    View.ComponentProgressValue   = result.ComponentsPassCount + result.ComponentsFailCount;

                    View.ComponentProgressBackground = System.Windows.Media.Brushes.White;
                    if (result.ComponentsFailCount > 0)
                    {
                        View.ComponentProgressForeground = System.Windows.Media.Brushes.Red;
                    }
                    else
                    {
                        View.ComponentProgressForeground = System.Windows.Media.Brushes.Green;
                    }
                }
                // complete
                else
                {
                    View.ComponentProgressMaximum = 1;
                    View.ComponentProgressValue   = 0;

                    if (result.ComponentsFailCount > 0)
                    {
                        View.ComponentProgressForeground = System.Windows.Media.Brushes.Red;
                        View.ComponentProgressBackground = System.Windows.Media.Brushes.Red;
                    }
                    else if (result.ComponentsPassCount > 0)
                    {
                        View.ComponentProgressForeground = System.Windows.Media.Brushes.Green;
                        View.ComponentProgressBackground = System.Windows.Media.Brushes.Green;
                    }
                }

                View.ComponentProgressMessage = String.Format("{0} of {1} components deployed with {2} failure(s).",
                                                              result.ComponentsPassCount,
                                                              result.ComponentsTotalCount,
                                                              result.ComponentsFailCount);
            }

            // tests section
            if (!IsRunAllTests)
            {
                View.IsTestSectionVisible = false;
            }
            else
            {
                View.IsTestSectionVisible = true;

                if (result.TestsPassCount == 0)
                {
                    View.TestProgressMaximum    = 1;
                    View.TestProgressValue      = 0;
                    View.TestProgressMessage    = "Pending";
                    View.TestProgressForeground = System.Windows.Media.Brushes.Green;
                    View.TestProgressBackground = System.Windows.Media.Brushes.White;
                }
                else
                {
                    // in progress
                    if (!result.DeploymentComplete && result.TestsPassCount + result.TestsFailCount < result.TestsTotalCount)
                    {
                        View.TestProgressMaximum = result.TestsTotalCount;
                        View.TestProgressValue   = result.TestsPassCount + result.TestsFailCount;

                        View.TestProgressBackground = System.Windows.Media.Brushes.White;
                        if (result.TestsFailCount > 0)
                        {
                            View.TestProgressForeground = System.Windows.Media.Brushes.Red;
                        }
                        else
                        {
                            View.TestProgressForeground = System.Windows.Media.Brushes.Green;
                        }
                    }
                    // complete
                    else
                    {
                        View.TestProgressMaximum = 1;
                        View.TestProgressValue   = 0;

                        if (result.TestsFailCount > 0)
                        {
                            View.TestProgressForeground = System.Windows.Media.Brushes.Red;
                            View.TestProgressBackground = System.Windows.Media.Brushes.Red;
                        }
                        else if (result.TestsPassCount > 0)
                        {
                            View.TestProgressForeground = System.Windows.Media.Brushes.Green;
                            View.TestProgressBackground = System.Windows.Media.Brushes.Green;
                        }
                    }

                    View.TestProgressMessage = String.Format("{0} of {1} tests passed with {2} failure(s).",
                                                             result.TestsPassCount,
                                                             result.TestsTotalCount,
                                                             result.TestsFailCount);
                }
            }

            View.ResultText = result.ResultMessage;

            _updateCount++;
            if (!result.DeploymentComplete)
            {
                if (_updateCount == 11)
                {
                    _refreshTimer.Interval = TimeSpan.FromSeconds(15).TotalMilliseconds;
                }
                else if (_updateCount == 21)
                {
                    _refreshTimer.Interval = TimeSpan.FromSeconds(30).TotalMilliseconds;
                }

                _refreshTimer.Start();
            }
            else
            {
                IsDeploymentRunning = false;
                App.Instance.UpdateWorkspaces();
            }
        }