/// <inheritdoc/> public async Task AnalyzeAsync(string path, string text, CancellationToken cancellationToken) { if (!this.canAnalyzeFile) { return; } var tasks = new List <Task <Stream> >(this.analyzers.Count()); foreach (IBackgroundAnalyzer analyzer in this.analyzers) { tasks.Add(analyzer.AnalyzeAsync(path, text, cancellationToken)); } Stream[] streams = await Task.WhenAll(tasks).ConfigureAwait(continueOnCapturedContext: false); try { await this.WriteStreamsToSinksAsync(path, streams, cleanAll : false).ConfigureAwait(continueOnCapturedContext: false); } finally { AnalysisCompleted?.Invoke(this, null); DisposeStreams(streams); } }
// Background job to analyze a mod private void BackgroundWork(object sender, DoWorkEventArgs e) { _modAnalysis = new ModAnalysis(); List <ModOption> archiveModOptions = e.Argument as List <ModOption>; // analyze each archive try { foreach (ModOption archiveModOption in archiveModOptions) { _backgroundWorker.ReportMessage("Analyzing " + archiveModOption.Name + "...", true); _backgroundWorker.ReportMessage("Calculating MD5 Hash.", false); archiveModOption.GetMD5Hash(); AnalyzeArchive(archiveModOption); AnalyzeEntries(archiveModOption); _backgroundWorker.ReportMessage(Environment.NewLine, false); } // save output SaveOutputFile(GetOutputFilename(archiveModOptions)); } catch (Exception x) { _backgroundWorker.ReportMessage(Environment.NewLine + x.Message, false); _backgroundWorker.ReportMessage(x.StackTrace, false); _backgroundWorker.ReportMessage("Analysis failed.", true); } // tell the view model we're done analyzing things AnalysisCompleted?.Invoke(this, EventArgs.Empty); }
protected void AnalysisComplete(int baudRate, int boostFrequencyAmount, AnalysisResult analysisResult, string resultingString = null, bool?matched = null) { var e = new AnalysisResultEventArgs { BaudRate = baudRate, BoostFrequencyAmount = boostFrequencyAmount, AnalysisResult = analysisResult, ResultingString = resultingString, Matched = matched }; AnalysisCompleted?.Invoke(this, e); }
/// <inheritdoc/> public async Task AnalyzeAsync(string logId, IEnumerable <string> targetFiles, CancellationToken cancellationToken) { this.canAnalyzeFile = false; var tasks = new List <Task <Stream> >(this.analyzers.Count()); foreach (IBackgroundAnalyzer analyzer in this.analyzers) { tasks.Add(analyzer.AnalyzeAsync(targetFiles, cancellationToken)); } Stream[] streams = await Task.WhenAll(tasks).ConfigureAwait(continueOnCapturedContext: false); try { await this.WriteStreamsToSinksAsync(logId, streams, cleanAll : true).ConfigureAwait(continueOnCapturedContext: false); } finally { AnalysisCompleted?.Invoke(this, null); this.canAnalyzeFile = true; DisposeStreams(streams); } }
private void InitializeHandlers() { _analyzedOperationsListChangedHandler = Observable.FromEventPattern<NotifyCollectionChangedEventArgs>( AnalyzedOperationsList, "CollectionChanged") .Where(e => { var completeStatus = new OperationStatus { Id = 3 }; bool opCountCheck = GetOperationsCount() == ((ObservableConcurrentDictionary<Guid, byte>)e.Sender).Skip(0).Count(); bool groupStatusCheck = Status.Id != completeStatus.Id; return e.EventArgs.Action == NotifyCollectionChangedAction.Add && opCountCheck && groupStatusCheck; }) .Take(1) .Subscribe( e => { var completeStatus = new OperationStatus { Id = 3 }; _analyzedOperationsListChangedHandler?.Dispose(); //TODO SET TO COMPLETE var time = DateTime.UtcNow; LastStatusChangedTime = time; CompleteTime = time; Status = completeStatus; var notificationCompleted = new AnalysisCompleted { OperationGroup = this }; _mediator?.Publish(notificationCompleted); }, ex => { Console.WriteLine("OnError: {0}", ex); }, () => Console.WriteLine("OnCompleted")); }