/// <summary> /// Установка логики анализа в "фоне" /// </summary> private void TuneBackgroundWorker() { if (_testWorker != null) { _testWorker.Dispose(); _testWorker = null; } _testWorker = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true }; _testWorker.DoWork += (workerSender, workEventArgs) => { Interlocked.Exchange(ref _isRunningNow, 1); using (var controller = new AnalyzerController(_currentSelectedSolutions)) { controller.AnalysisManagers.CollectionChanged += (ctrlSender, changedEventArgs) => // "Подписываемся" на добавление менеджера анализа { if (changedEventArgs.Action != NotifyCollectionChangedAction.Add) { return; } var newManager = changedEventArgs.NewItems.Cast <AnalysisManager>().FirstOrDefault(); if (newManager == null) { throw new InvalidOperationException("newManager can't be null"); } newManager.AnalysisStatusChanged += (manSender, analysisEventArgs) => // "Подписываемся" на смену статуса анализа для очередного добавленного менеджера { SetNewStatusValue( analysisEventArgs.StartupMode, analysisEventArgs.SolutionInfo, analysisEventArgs.NewStatus); if (_testWorker.IsBusy && _testWorker.CancellationPending) { workEventArgs.Cancel = true; } }; }; controller.CurrentAnalysisDone += (ctrl, currentAnalysisDoneEventArgs) => // "Подписываемся" на завершение анализа для текущего менеджера { var currentFinishedCount = currentAnalysisDoneEventArgs.CurrentFinishedCount; var progress = (int)(currentFinishedCount / (double)_currentTotalCount * 100); _testWorker.ReportProgress(progress); }; controller.RunAll(AnalysisStatus.InPending); } }; _testWorker.RunWorkerCompleted += (sender, completedEventArgs) => { var ex = completedEventArgs.Error; if (ex != null) { AppEventLogger.Log(ex.ToString(), EventLogEntryType.Warning); } if (!completedEventArgs.Cancelled) { SetUiCompletedState(); UiUtils.ResetActiveStatuses(_currentSelectedSolutions); } else { UiUtils.ResetActiveStatuses(_currentSelectedSolutions, true); } ProcessUtils.MandatoryKill(Process.GetCurrentProcess(), false); if (!StartStopButton.IsEnabled) { StartStopButton.IsEnabled = true; } UiUtils.TurnButtonState(ButtonState.Running, StartStopButton, StartStopImage); if (!completedEventArgs.Cancelled && ShutdownCheckBox.IsChecked == true) { AnalyzerUtilities.ShutdownPc(); } }; _testWorker.ProgressChanged += (sender, changedEventArgs) => { TestingProgressBar.Value = changedEventArgs.ProgressPercentage; }; }
internal static int Start(IEnumerable <string> args) { var summaryWrapper = new SummaryWrapper(); var selectionMode = ParseArgs(args); var testedViewModels = TestedSolutionsManager.RetrieveSlnInfoViewModels(); var summaryResults = summaryWrapper.SummaryResults; switch (selectionMode) { case RunSelectionMode.All: using (var controller = new AnalyzerController(testedViewModels)) { controller.AnalysisManagers.CollectionChanged += (sender, changedEventArgs) => { if (changedEventArgs.Action != NotifyCollectionChangedAction.Add) { return; } var newManager = changedEventArgs.NewItems.Cast <AnalysisManager>().FirstOrDefault(); if (newManager == null) { throw new InvalidOperationException("newManager can't be null"); } newManager.AnalysisStatusChanged += (o, e) => { var localSlnInfo = e.SolutionInfo; var startupMode = e.StartupMode; var newStatus = e.NewStatus; var exitCode = e.DevenvExitCode; var statDesc = newStatus.GetAnalysisStatusDescription(); var slnFileName = newManager.SolutionInfo.SolutionFileName; StatWrapper summaryResult; if (summaryResults.TryGetValue(startupMode, out summaryResult)) { switch (newStatus) { case AnalysisStatus.OkFinished: Interlocked.Increment(ref summaryResult.OkCount); CisTsLog(() => { _DefaultWriter.WriteLine(CisFormatString, startupMode, slnFileName, statDesc); }); break; case AnalysisStatus.DiffFinished: Interlocked.Increment(ref summaryResult.DiffCount); CisTsLog(() => { _DefaultWriter.WriteLine(CisFormatString, startupMode, slnFileName, statDesc); }); break; case AnalysisStatus.PluginCrashed: Interlocked.Increment(ref summaryResult.FailCount); CisTsLog(() => { _DefaultWriter.WriteLine(CisFormatString, startupMode, slnFileName, statDesc); _DefaultWriter.WriteLine(Resources.CisFailMsg, slnFileName, startupMode, e.CrashReason.GetCrashMessage()); _DefaultWriter.WriteLine(Resources.WatchActivityLog, newManager.LogFileName.GetDevenvActivityLog()); if (exitCode != default(int)) { _DefaultWriter.WriteLine(Resources.ExitCodeMessage, exitCode); } }); break; } } localSlnInfo.SetStatusValue(startupMode, newStatus); }; }; controller.RunAll(); } break; default: _DefaultWriter.WriteLine("Unknown option {0}. Press any key to exit...", selectionMode); Environment.Exit(0); break; } _DefaultWriter.WriteLine( "----------------------------------------------------------Stat----------------------------------------------------------"); foreach (var mode in summaryResults.Keys) { var oks = summaryResults[mode].OkCount; var diffs = summaryResults[mode].DiffCount; var fails = summaryResults[mode].FailCount; _DefaultWriter.WriteLine("Mode: {0}. Oks: {1}. Diffs: {2}. Fails: {3}", mode, oks, diffs, fails); } return (summaryResults.Keys.Sum(startMode => summaryResults[startMode].DiffCount) + // Кол-во Diff'ов... summaryResults.Keys.Sum(startMode => summaryResults[startMode].FailCount)); // ... + Кол-во Fail'ов }