public void Run() { try { _log.Start(); var outputPath = _pathProvider.NewPath(); using (var progress = new Progress(_progress)) { progress.Update("Getting BCRs"); var bcr = _reader.Read(); progress.Complete(); var finalBcr = _middleware.Use(bcr); progress.Update("Writing to Excel"); _writer.Write(outputPath, finalBcr); progress.Complete(); } _progress.WriteLine("Success - {0}", outputPath); } catch (Exception e) { _log.Error(e); _progress.WriteLine(e.Message); _progress.WriteLine(_log.Path); } finally { _log.Close(); } }
public Task RunAsync() { var progress = new Progress(); progress.Changed += Progress_Changed; return(Task.Run(() => { try { this.isBusy = true; this.OnRun(progress, this.cancellation.Token); progress.Complete(); } catch (Exception e) { progress.Fail(e.Message); } finally { this.isBusy = false; } })); }
public static void Execute(OfficeApps apps, Input input) { if (Flow.Interrupted) { return; } Log.Info("Executing Script"); Log.Debug("Target: " + input.Workbook.FullName); Log.Debug("Template: " + input.Template.Name); Log.Debug("Checking which cells are numerical:"); Log.PushIndent(); var fullEnumerator = new RangeEnumerator(input.Template.UsedRange); bool[,] mask = new bool[fullEnumerator.Height, fullEnumerator.Width]; Progress.Init(Log.Debug); Progress.Reset(); while (fullEnumerator.MoveNext()) { Progress.Report(fullEnumerator.Progress); ExcelRange cell = fullEnumerator.Current; if (Flow.Interrupted) { break; } bool numeric = ExcelHelper.IsCellAnywhereNumeric(apps, cell.Row, cell.Column); mask[fullEnumerator.RowIndex, fullEnumerator.ColumnIndex] = numeric; } Progress.Complete(); fullEnumerator.Dispose(); Log.PopIndent(); if (Flow.Interrupted) { return; } Log.Debug("Creating summary sheets:"); // Strange to double these I know, but it makes it easier to keep track of // indents with interruptions this way. Log.PushIndent(); Log.PushIndent(); foreach (string formula in input.Formulae) { string name = ExcelHelper.CreateUniqueWorksheetName(input.Workbook, formula); Log.PopIndent(); Log.Debug($"Creating sheet \"{name}\":"); Log.PushIndent(); if (Flow.Interrupted) { break; } input.Template.Copy(After: input.Workbook.Sheets[apps.Excel.Sheets.Count]); if (Flow.Interrupted) { break; } Worksheet newSheet = (Worksheet)input.Workbook.ActiveSheet; newSheet.Name = name; var maskedEnumerator = new RangeEnumerator(newSheet.UsedRange); maskedEnumerator.ApplyMask(mask); Progress.Reset(); while (maskedEnumerator.MoveNext()) { Progress.Report(maskedEnumerator.Progress); ExcelRange cell = maskedEnumerator.Current; if (Flow.Interrupted) { break; } string range = $"'{input.SheetReference}'!{cell.Address}"; string formulaText = $"={formula}({range})"; cell.Value = formulaText; } Progress.Complete(); maskedEnumerator.Dispose(); if (Flow.Interrupted) { break; } } Log.PopIndent(); Log.PopIndent(); if (Flow.Interrupted) { return; } Log.Debug($"Saving {input.Workbook.FullName}"); input.Workbook.Save(); Log.Success("Script complete"); }
public static void Execute(OfficeApps apps, Input input) { if (Flow.Interrupted) { return; } Log.Info("Executing Script"); input.Template.Copy(After: input.Workbook.Sheets[apps.Excel.Sheets.Count]); if (Flow.Interrupted) { return; } Worksheet active = (Worksheet)apps.Excel.ActiveSheet; active.Name = ExcelHelper.CreateUniqueWorksheetName(input.Workbook, "Summary"); if (Flow.Interrupted) { return; } ExcelHelper.TryParseWorksheetRange(out IEnumerable <Worksheet> worksheets, input.Workbook, input.SheetReference, compareWords: true, verbrose: true); if (Flow.Interrupted) { return; } RangeEnumerator enumerator = new RangeEnumerator(active.UsedRange); Progress.Init(Log.Debug); Progress.Reset(); while (enumerator.MoveNext()) { if (Flow.Interrupted) { return; } ExcelRange cell = enumerator.Current; string text = cell.Value?.ToString(); if (text == null) { continue; } string command = text.Trim().ToLower(); string referencePattern = "\\$\\s*([\\d\\w]+)\\s*\\$"; if (command == "$sheetname$") { int i = 0; foreach (Worksheet sheet in worksheets) { if (Flow.Interrupted) { return; } // Note the self: .Cells[i,j] is 1-based, not 0-based! ExcelRange recordCell = (ExcelRange)active.Cells[1 + enumerator.RowIndex, 1 + enumerator.ColumnIndex + i]; recordCell.Value = sheet.Name; i++; } } else { Match match = Regex.Match(command.ToUpper(), referencePattern); if (match.Success) { string reference = match.Groups[1].Value; try { int i = 0; foreach (Worksheet sheet in worksheets) { if (Flow.Interrupted) { return; } ExcelRange sourceCell = (ExcelRange)sheet.Range[reference]; ExcelRange destinationCell = (ExcelRange)active.Cells[1 + enumerator.RowIndex, 1 + enumerator.ColumnIndex + i]; destinationCell.Value = sourceCell.Value?.ToString(); i++; } } catch (Exception e) { Log.Warning($"Failed to apply reference {reference}"); Log.Debug("(Is it a valid reference?)"); if (AppHelper.DebugFlag) { Log.Debug("Note to self:", e); } } } } Progress.Report(enumerator.Progress); } if (Flow.Interrupted) { return; } Progress.Complete(); Log.Debug($"Saving {input.Workbook.FullName}"); input.Workbook.Save(); Log.Success("Script complete"); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> /// <exception cref="System.TypeLoadException"/> public override void Run(JobConf job, TaskUmbilicalProtocol umbilical) { job.SetBoolean(JobContext.SkipRecords, IsSkipping()); if (IsMapOrReduce()) { copyPhase = GetProgress().AddPhase("copy"); sortPhase = GetProgress().AddPhase("sort"); reducePhase = GetProgress().AddPhase("reduce"); } // start thread that will handle communication with parent Task.TaskReporter reporter = StartReporter(umbilical); bool useNewApi = job.GetUseNewReducer(); Initialize(job, GetJobID(), reporter, useNewApi); // check if it is a cleanupJobTask if (jobCleanup) { RunJobCleanupTask(umbilical, reporter); return; } if (jobSetup) { RunJobSetupTask(umbilical, reporter); return; } if (taskCleanup) { RunTaskCleanupTask(umbilical, reporter); return; } // Initialize the codec codec = InitCodec(); RawKeyValueIterator rIter = null; ShuffleConsumerPlugin shuffleConsumerPlugin = null; Type combinerClass = conf.GetCombinerClass(); Task.CombineOutputCollector combineCollector = (null != combinerClass) ? new Task.CombineOutputCollector (reduceCombineOutputCounter, reporter, conf) : null; Type clazz = job.GetClass <ShuffleConsumerPlugin>(MRConfig.ShuffleConsumerPlugin, typeof(Shuffle)); shuffleConsumerPlugin = ReflectionUtils.NewInstance(clazz, job); Log.Info("Using ShuffleConsumerPlugin: " + shuffleConsumerPlugin); ShuffleConsumerPlugin.Context shuffleContext = new ShuffleConsumerPlugin.Context( GetTaskID(), job, FileSystem.GetLocal(job), umbilical, base.lDirAlloc, reporter, codec, combinerClass, combineCollector, spilledRecordsCounter, reduceCombineInputCounter , shuffledMapsCounter, reduceShuffleBytes, failedShuffleCounter, mergedMapOutputsCounter , taskStatus, copyPhase, sortPhase, this, mapOutputFile, localMapFiles); shuffleConsumerPlugin.Init(shuffleContext); rIter = shuffleConsumerPlugin.Run(); // free up the data structures mapOutputFilesOnDisk.Clear(); sortPhase.Complete(); // sort is complete SetPhase(TaskStatus.Phase.Reduce); StatusUpdate(umbilical); Type keyClass = job.GetMapOutputKeyClass(); Type valueClass = job.GetMapOutputValueClass(); RawComparator comparator = job.GetOutputValueGroupingComparator(); if (useNewApi) { RunNewReducer(job, umbilical, reporter, rIter, comparator, keyClass, valueClass); } else { RunOldReducer(job, umbilical, reporter, rIter, comparator, keyClass, valueClass); } shuffleConsumerPlugin.Close(); Done(umbilical, reporter); }