Exemplo n.º 1
0
 protected virtual void OnGenerationFinished(IGeneration e)
 {
     GenerationFinished?.Invoke(this, e);
 }
Exemplo n.º 2
0
 protected virtual void OnFinished(EventArgs e)
 {
     ChangeProgress(100, 100, "");
     GenerationFinished?.Invoke(this, e);
     BeginInvoke(new CloseDelegate(CloseD));
 }
        //
        // Start the process of generating the stats
        //
        public static void Start(Form owner, string fileList, string reportName, Logging logger, bool injectPaths, GenerationFinished generationFinished)
        {
            // Track our properties
            s_logger = logger;

            // Kick off the background threads
            BackgroundWorker updateThread = new BackgroundWorker();

            // Does the work of the request
            updateThread.DoWork += (object objectSender, DoWorkEventArgs args) =>
            {
                logger.Log(@"Starting stats generation");
                try
                {
                    // Check if we're authenticated
                    Simple reviewBoardCredentials = CheckRBServerAuthentication(owner);
                    if (reviewBoardCredentials == null)
                    {
                        return;
                    }
                    Simple jiraCredentials = CheckJiraServerAuthentication(owner);
                    if (reviewBoardCredentials == null)
                    {
                        return;
                    }

                    // Get the list of paths to review
                    string[] pathsToReview = ParseFileList(fileList, injectPaths);
                    if (pathsToReview == null)
                    {
                        return;
                    }

                    // Get the revision list for each path
                    RevisionList.Revisions[] revisionLists = RequestRevisionLists(pathsToReview);
                    if (revisionLists == null)
                    {
                        return;
                    }

                    // Spin through each revision list and do the work for each path selected
                    foreach (RevisionList.Revisions thisRevisionList in revisionLists)
                    {
                        // Identify which path we'll go through
                        s_logger.Log(@"Generating stats for\n{0}", thisRevisionList.Path);

                        // We need to time this review
                        Stopwatch stopWatch = new Stopwatch();
                        stopWatch.Start();

                        // Get the logs for the given set of revisions
                        SvnLogs.Log[] revisionLogs = GetLogsFromRevisions(thisRevisionList);
                        if (revisionLogs == null)
                        {
                            return;
                        }

                        ReviewState.GetCommitStatsResult commitStats = GetCommitStats(revisionLogs);
                        if (commitStats == null)
                        {
                            return;
                        }

                        // Verify would could get the review information
                        bool reviewInformationValid = CheckReviewInformation(commitStats);
                        if (reviewInformationValid == false)
                        {
                            return;
                        }

                        // Now generate information about the reviews
                        ReviewState.ReviewStatistics[] reviewStats = GetReviewStats(commitStats.Reviews, thisRevisionList.Path, reviewBoardCredentials);
                        if (reviewStats == null)
                        {
                            return;
                        }

                        // Get the Jira information from the commits
                        JiraState.JiraStatistics jiraStats = GetJiraStats(revisionLogs, jiraCredentials);
                        if (jiraStats == null)
                        {
                            return;
                        }

                        // Create the review
                        bool reportGenerated = CreateReviewReport(reportName, thisRevisionList, revisionLogs, commitStats, reviewStats, jiraStats, stopWatch);
                        if (reportGenerated == false)
                        {
                            return;
                        }
                    }
                }
                catch (Exception e)
                {
                    s_logger.Log("Exception raised when generating review stats\n\n{0}\n", e.Message);
                    s_errorMessage = string.Format("Unable to generate review statistics for the given path\n\n{0}", e.Message);
                }
            };

            // Called when it's all been generated
            updateThread.RunWorkerCompleted += (object objectSender, RunWorkerCompletedEventArgs args) =>
            {
                s_logger.Log("Review generation complete");

                // Inform the user something went wrong?
                if (string.IsNullOrEmpty(s_errorMessage) == false)
                {
                    s_logger.Log(@"* Error encountered when running\n{0}\n", s_errorMessage);
                    MessageBox.Show(s_errorMessage, @"Stats Generation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                // Done
                generationFinished();
            };

            // Off it goes
            updateThread.RunWorkerAsync();
        }