/// <summary> /// Report progress to the client. /// An updated progress is only sent for new integer percentage values. e.g. 1, 2, 3... /// If there are fewer events than 100 then you will see pecentage reported thus... 1, 4, 7... /// </summary> /// <param name="currentEvent">The current event number.</param> /// <param name="totalEvents">Total events to copy.</param> /// <param name="eventId">The event id of the last event copied.</param> private void reportProgress(long currentEvent, long totalEvents, int eventId) { // Don't bother reporting progress if only 1 event - only give progress when reporting products or whole index. if ((totalEvents == 0) || (totalEvents == 1)) { return; } int thisPercentageComplete = (int)((currentEvent * 100) / totalEvents); if (thisPercentageComplete > m_LastPercentageProgressReported) { StackHashBugReportProgressAdminReport progressReport = new StackHashBugReportProgressAdminReport(); progressReport.Operation = StackHashAdminOperation.BugReportProgress; progressReport.ClientData = m_TaskParameters.ClientData; progressReport.ContextId = m_TaskParameters.ContextId; progressReport.CurrentEvent = currentEvent; progressReport.TotalEvents = totalEvents; progressReport.CurrentEventId = eventId; m_LastPercentageProgressReported = thisPercentageComplete; if (Reporter.CurrentReporter != null) { AdminReportEventArgs adminReportArgs = new AdminReportEventArgs(progressReport, false); Reporter.CurrentReporter.ReportEvent(adminReportArgs); } } }
public void RunBugReportSpecificFileProgressCheckManyEventsAbortTest() { m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateAndSetNewContext(ErrorIndexType.SqlExpress); GetContextBugTrackerPlugInSettingsResponse resp = m_Utils.GetContextBugTrackerPlugInSettings(0); Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings); Assert.AreNotEqual(null, resp.BugTrackerPlugInSettings.PlugInSettings); Assert.AreEqual(0, resp.BugTrackerPlugInSettings.PlugInSettings.Count); resp.BugTrackerPlugInSettings.PlugInSettings.Add(new StackHashBugTrackerPlugIn()); resp.BugTrackerPlugInSettings.PlugInSettings[0].Enabled = true; resp.BugTrackerPlugInSettings.PlugInSettings[0].Name = "TestPlugIn"; resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties = new StackHashNameValueCollection(); resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair() { Name = "TestParam1", Value = "TestValue1" }); resp.BugTrackerPlugInSettings.PlugInSettings[0].Properties.Add(new StackHashNameValuePair() { Name = "TestParam2", Value = "TestValue2" }); m_Utils.SetContextBugTrackerPlugInSettings(0, resp.BugTrackerPlugInSettings); m_Utils.RestartService(); m_Utils.ActivateContext(0); StackHashTestIndexData indexData = new StackHashTestIndexData(); indexData.NumberOfProducts = 1; indexData.NumberOfFiles = 1; indexData.NumberOfEvents = 200; indexData.NumberOfCabs = 1; indexData.NumberOfEventInfos = 1; m_Utils.CreateTestIndex(0, indexData); try { StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashFileCollection files = m_Utils.GetFiles(0, products[0].Product).Files; StackHashEventPackageCollection events = m_Utils.GetProductEventPackages(0, products[0].Product).EventPackages; StackHashCabPackageCollection cabs = events[0].Cabs; StackHashBugReportDataCollection bugReportDataCollection = new StackHashBugReportDataCollection(); bugReportDataCollection.Add(new StackHashBugReportData() { Product = products[0].Product, File = files[0], TheEvent = null, Cab = null, ScriptName = null, Options = StackHashReportOptions.IncludeAllObjects }); m_Utils.RunBugReportTask(0, bugReportDataCollection, 0, false); // Don't wait. m_Utils.WaitForBugReportProgress(30000); m_Utils.AbortTask(0, StackHashTaskType.BugReportTask); m_Utils.WaitForBugReportTaskCompleted(30000); // Check the progress reports. Assert.AreEqual(true, m_Utils.BugReportProgressReports.Count < 100); long lastProgress = -1; foreach (StackHashAdminReport report in m_Utils.BugReportProgressReports) { StackHashBugReportProgressAdminReport progress = report as StackHashBugReportProgressAdminReport; Assert.AreEqual(true, progress.CurrentEvent > lastProgress); Assert.AreEqual(true, progress.CurrentEvent < progress.TotalEvents); lastProgress = progress.CurrentEvent; } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }