private void _backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (!e.Cancelled && this.Visible) { _recordingsTreeView.Nodes.Clear(); _loadingPanel.Visible = false; if (e.Error != null) { _diskSpaceProgressBar.Value = 0; MessageBox.Show(this, e.Error.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (e.Result != null) { BackgroundWorkerResult result = (BackgroundWorkerResult)e.Result; if (result.RecordingDisksInfo == null) { _diskSpaceProgressBar.Value = 0; _toolTip.SetToolTip(_diskSpaceProgressBar, "Error getting recording shares:" + Environment.NewLine + Environment.NewLine + result.RecordingDisksInfoException.Message); } else { RefreshDiskUsage(result.RecordingDisksInfo); } _recordingNodes = result.RecordingNodes.ToArray(); _recordingsTreeView.Nodes.AddRange(_recordingNodes); _exportButton.Enabled = true; } else { _diskSpaceProgressBar.Value = 0; } } }
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorkerResult result = new BackgroundWorkerResult(); try { BackgroundWorker bw = sender as BackgroundWorker; bw.ReportProgress(0, $"Translating to EM3 format ..."); new ExeCaller().RunTransfomer(countries, out List <string> errors); AddErrors(errors, result); if (bw.CancellationPending) { e.Cancel = true; return; } foreach (string country in countries) { foreach (string year in years) { if (!GenerateHHotData(country, year, out string dataFullPath, result)) { continue; } if (bw.CancellationPending) { break; } GenerateOutput(country, year, dataFullPath, result); if (bw.CancellationPending) { break; } } if (bw.CancellationPending) { break; } } if (bw.CancellationPending) { e.Cancel = true; } } catch (Exception exception) { AddErrors(new List <string>() { exception.Message }, result); } e.Result = result; }
private void AddErrors(List <string> errors, BackgroundWorkerResult bwResult, string country = null, string year = null) { if (errors == null || errors.Count == 0) { return; } string key = $"{country ?? "General"} {year ?? string.Empty}".Trim(); if (!bwResult.errors.ContainsKey(key)) { bwResult.errors.Add(key, new List <string>()); } bwResult.errors[key].AddRange(errors); }
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { CleanUp(); if (!e.Cancelled) { BackgroundWorkerResult result = e.Result as BackgroundWorkerResult; ReportErrors(result.generatedOutputFiles.Count > 0, result.errors); if (result.generatedOutputFiles.Count == 0) { return; } generatedOutputFiles = result.generatedOutputFiles; Close(); } else { MessageBox.Show("Generation of Statistics was cancelled."); } }
private bool GenerateHHotData(string country, string year, out string dataFullPath, BackgroundWorkerResult bwResult) { backgroundWorker.ReportProgress(0, $"Generating data for {country} {year} ..."); dataFullPath = null; List <string> err = new List <string>(); string dataName = dataGenerator.generateCountryYearData(tempPathData, country, year, generationDetails.fileDetails[country], err); AddErrors(err, bwResult, country, year); if (!string.IsNullOrEmpty(dataName) && File.Exists(Path.Combine(tempPathData, dataName))) { dataFullPath = Path.Combine(tempPathData, dataName); } return(dataFullPath != null); }
private void GenerateOutput(string country, string year, string dataFullPath, BackgroundWorkerResult result) { backgroundWorker.ReportProgress(0, $"Generating output for {country} {year} ..."); bool success = new ExeCaller().RunExe(country, year, dataFullPath, chkOutputInEuro.Checked, out List <string> errors); AddErrors(errors, result, country, year); string outputFile = Path.Combine(UISessionInfo.GetOutputFolder(), $"{country}_{year}_std.txt"); if (success && File.Exists(outputFile)) { result.generatedOutputFiles.Add(outputFile); } }
private void _backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { DateTime startTime = DateTime.Now; BackgroundWorkerArgs args = (BackgroundWorkerArgs)e.Argument; BackgroundWorkerResult result = new BackgroundWorkerResult(); result.RecordingNodes = new List<TreeNode>(); try { result.RecordingDisksInfo = Proxies.ControlService.GetRecordingDisksInfo().Result; } catch (Exception ex) { result.RecordingDisksInfo = null; result.RecordingDisksInfoException = ex; } IList<RecordingGroup> groups = Proxies.ControlService.GetAllRecordingGroups(args.ChannelType, args.RecordingGroupMode).Result; foreach (RecordingGroup group in groups) { if (_backgroundWorker.CancellationPending) { break; } bool nodeAdded = false; List<RecordingSummary> recordings = null; if (!args.IncludeNonExisting) { recordings = GetRecordingsInGroup(group, args); } if (args.IncludeNonExisting || recordings != null) { int count = recordings == null ? group.RecordingsCount : recordings.Count; if (count == 0) { nodeAdded = true; } else if (group.RecordingGroupMode != RecordingGroupMode.GroupByChannel && group.RecordingGroupMode != RecordingGroupMode.GroupByCategory && count == 1) { if (recordings == null) { recordings = GetRecordingsInGroup(group, args); } if (recordings != null && recordings.Count > 0) { TreeNode recordingNode = AddRecordingNode(result.RecordingNodes, recordings[0], true); } nodeAdded = true; } } if (!nodeAdded) { TreeNode groupNode = new TreeNode(GetGroupDisplayText(group)); result.RecordingNodes.Add(groupNode); groupNode.Tag = group; RefreshGroupNodeImage(groupNode); groupNode.Nodes.Add(String.Empty); } } Utility.EnsureMinimumTime(startTime, 250); if (!_backgroundWorker.CancellationPending) { e.Result = result; } }
private void _backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { DateTime startTime = DateTime.Now; BackgroundWorkerArgs args = (BackgroundWorkerArgs)e.Argument; BackgroundWorkerResult result = new BackgroundWorkerResult(); result.RecordingNodes = new List <TreeNode>(); try { result.RecordingDisksInfo = Proxies.ControlService.GetRecordingDisksInfo().Result; } catch (Exception ex) { result.RecordingDisksInfo = null; result.RecordingDisksInfoException = ex; } IList <RecordingGroup> groups = Proxies.ControlService.GetAllRecordingGroups(args.ChannelType, args.RecordingGroupMode).Result; foreach (RecordingGroup group in groups) { if (_backgroundWorker.CancellationPending) { break; } bool nodeAdded = false; List <RecordingSummary> recordings = null; if (!args.IncludeNonExisting) { recordings = GetRecordingsInGroup(group, args); } if (args.IncludeNonExisting || recordings != null) { int count = recordings == null ? group.RecordingsCount : recordings.Count; if (count == 0) { nodeAdded = true; } else if (group.RecordingGroupMode != RecordingGroupMode.GroupByChannel && group.RecordingGroupMode != RecordingGroupMode.GroupByCategory && count == 1) { if (recordings == null) { recordings = GetRecordingsInGroup(group, args); } if (recordings != null && recordings.Count > 0) { TreeNode recordingNode = AddRecordingNode(result.RecordingNodes, recordings[0], true); } nodeAdded = true; } } if (!nodeAdded) { TreeNode groupNode = new TreeNode(GetGroupDisplayText(group)); result.RecordingNodes.Add(groupNode); groupNode.Tag = group; RefreshGroupNodeImage(groupNode); groupNode.Nodes.Add(String.Empty); } } Utility.EnsureMinimumTime(startTime, 250); if (!_backgroundWorker.CancellationPending) { e.Result = result; } }