private void CustomizedReportGenerator_SectionsAdded(object sender, SectionsAddedEventArgs e) { Debug.WriteLine("QueueWorker [EVENT]: sections added [sender={0} report={1}]", sender, e.Report); CustomizedReportGenerator repGen = (CustomizedReportGenerator)sender; var repGenCustomizationId = repGen.CustomizationId; var matchHash = MatchHashGenerator.GenerateMatchHash(_man._matchManager.Match); string tmpReportPath; if (!repGen.Abort) { var renderer = IoC.Get <IReportRenderer>("PDF"); tmpReportPath = _man.TempFileScheme.TempPath + string.Format(_man.TempFileScheme.NameScheme, matchHash + repGenCustomizationId); bool fileExists = File.Exists(tmpReportPath); Debug.WriteLine("QueueWorker: report file (exists? {0}): {1}", fileExists, tmpReportPath); if (!fileExists) { using (var sink = File.Create(tmpReportPath)) { e.Report.RenderToStream(renderer, sink); } } } else { return; } if (!repGen.Abort) { Debug.WriteLine("QueueWorker: repGen={0} not aborted, invoking ReportGenerated event", repGen.GetHashCode()); repGen.Done = true; _renderedReportPath = tmpReportPath; _man.ReportGenerated?.Invoke(_man, new ReportGeneratedEventArgs(tmpReportPath, matchHash, repGenCustomizationId)); } else { Debug.WriteLine("QueueWorker: repGen={0} aborted, discarding.", repGen.GetHashCode()); } }
public void GenerateReport(object genEvent = null) { var matchOpened = MatchManager.Match != null; var customizationDict = matchOpened ? GetCustomizationDictionary() : null; var generateRepSettingsChangedEvent = genEvent as bool?; if (generateRepSettingsChangedEvent == null || generateRepSettingsChangedEvent.Value) { Events.PublishOnUIThread(new ReportSettingsChangedEvent(matchOpened, (string)customizationDict?["id"])); } if (matchOpened) { var gen = new CustomizedReportGenerator() { Customization = customizationDict, Match = MatchManager.Match }; _issuedReportId = MatchHashGenerator.GenerateMatchHash(MatchManager.Match) + gen.CustomizationId; ReportGenerationQueueManager.Enqueue(gen); } }
internal void WorkTheQueue() { while (Run || RunOnce || _man._notifyIcon != null && _man._notifyIcon.Visible) { if (_workList.Count != 0) { Debug.WriteLine("QueueWorker: queue not empty, starting report generation (queue.Count={0})", _workList.Count); IReportGenerator repGen; lock (WorkListLock) { repGen = _workList[_workList.Count - 1]; _workList.Clear(); } _renderedReportPath = null; if (_custRepGen != null) { _custRepGen.Abort = true; _custRepGen.SectionsAdded -= CustomizedReportGenerator_SectionsAdded; _custRepGen = null; } var gen = repGen as CustomizedReportGenerator; if (gen != null) { var matchHash = MatchHashGenerator.GenerateMatchHash(_man._matchManager.Match); var tmpFileName = string.Format(_man.TempFileScheme.NameScheme, matchHash + gen.CustomizationId); var tmpReportPath = _man.TempFileScheme.TempPath + tmpFileName; if (File.Exists(tmpReportPath)) { Debug.WriteLine($"QueueWorker: tmp file '{tmpFileName}' already exists, skipping generation and invoking ReportGenerated event (Thread '{Thread.CurrentThread.Name}')"); _renderedReportPath = tmpReportPath; _man.ReportGenerated?.Invoke(_man, new ReportGeneratedEventArgs(tmpReportPath, matchHash, gen.CustomizationId)); } else { if (gen.ShowNotification) { MakeNotifyIconVisible(); } _custRepGen = gen; _custRepGen.SectionsAdded += CustomizedReportGenerator_SectionsAdded; var custRepGenThread = new Thread(_custRepGen.GenerateReport) { Name = "CustomReportGenThread-" + _genId++ }; custRepGenThread.SetApartmentState(ApartmentState.STA); Debug.WriteLine("QueueWorker: starting {0}", args: custRepGenThread.Name); custRepGenThread.Start(); } } else { // TODO Generate report with non-customizable report generator // repGen.GenerateReport(man.matchManager.Match); } } CopyRenderedReportToUserPath(); if (RunOnce) { RunOnce = false; } Thread.Sleep(500); } }