private ExcelContextForPhaseOne( ParametersPack args, AnalysisLaunchContext launchContext, FileInfo outputExcelFile, string sheetName, Func <ParametersPack, TAnalysisPhaseOne> analysisFactory) { Args = args.ThrowIfNull(nameof(args)); LaunchContext = launchContext.ThrowIfNull(nameof(launchContext)); OutputExcelFile = outputExcelFile.ThrowIfNull(nameof(outputExcelFile)); SheetName = sheetName.ThrowIfNullOrEmpty(nameof(sheetName)); _partOneFactory = analysisFactory.ThrowIfNull(nameof(analysisFactory)); }
public AnalysisIterationContextPhaseTwo( ParametersPack args, AnalysisLaunchContext launchContext, LocalFileWorker fileWorker, string analysisInputArgs, FileInfo finalOutputFile) { Args = args.ThrowIfNull(nameof(args)); LaunchContext = launchContext.ThrowIfNull(nameof(launchContext)); FileWorker = fileWorker.ThrowIfNull(nameof(fileWorker)); AnalysisInputArgs = analysisInputArgs.ThrowIfNullOrWhiteSpace(nameof(analysisInputArgs)); FinalOutputFile = finalOutputFile.ThrowIfNull(nameof(finalOutputFile)); }
public async static Task PerformFullAnalysisForPhaseTwoAsync(ParametersPack args, AnalysisLaunchContext launchContext, LocalFileWorker fileWorker, Func <FileObject, Task> asyncCallback) { args.ThrowIfNull(nameof(args)); launchContext.ThrowIfNull(nameof(launchContext)); fileWorker.ThrowIfNull(nameof(fileWorker)); asyncCallback.ThrowIfNull(nameof(asyncCallback)); _logger.Info("Preparing to run full analysis for phase two."); // Contract: output files are located in the same directory as our app. IReadOnlyList <FileInfo> finalOutputFiles = args.GetOutputFilenames(phaseNumber: 2); using var fileDeleter = new FileDeleter(finalOutputFiles); IReadOnlyList <string> analysisInputArgsCollection = args.CollectionPackAsInputArgumentsForPhaseTwo(); var limitedScheduler = new LimitedConcurrencyLevelTaskScheduler(launchContext.MaxDegreeOfParallelism); var processingTasks = new List <Task <FileObject> >(analysisInputArgsCollection.Count); // The last is common analysis data file. // We don't need to read/use the last one. for (int index = 0; index < analysisInputArgsCollection.Count; ++index) { var iterationContext = new AnalysisIterationContextPhaseTwo( args: args, launchContext: launchContext, fileWorker: fileWorker, analysisInputArgs: analysisInputArgsCollection[index], finalOutputFile: finalOutputFiles[index] ); Task <FileObject> processingTask = TaskHelper.StartNew( () => PerformOneIterationOfPhaseTwoAsync(iterationContext), limitedScheduler ); processingTasks.Add(processingTask); } await Task.WhenAll( processingTasks.Select(task => AwaitAndProcessAsync(task, asyncCallback)) ); }
public static async Task <FileObject> PerformOneIterationOfPhaseOneAsync(ParametersPack args, AnalysisLaunchContext launchContext, LocalFileWorker fileWorker) { args.ThrowIfNull(nameof(args)); launchContext.ThrowIfNull(nameof(launchContext)); fileWorker.ThrowIfNull(nameof(fileWorker)); _logger.Info("Preparing to run one iteration of phase one."); // Contract: output files are located in the same directory as our app. IReadOnlyList <FileInfo> finalOutputFiles = args.GetOutputFilenames(phaseNumber: 1); CheckExpectedFilenamesNumber(upperBound: 2, finalOutputFiles); var fileDeleter = new FileDeleter(finalOutputFiles); // Contract: the analysis program is located in the same directory as our app. var processLaunchContext = ProcessLaunchContext.Create( file: args.AnalysisProgramName, args: args.PackAsInputArgumentsForPhaseOne(), showWindow: launchContext.ShowAnalysisWindow ); _logger.Info( $"Starting analysis program. Launch context: {processLaunchContext.ToLogString()}" ); using (var analysisRunner = ProgramRunner.RunProgram(processLaunchContext)) { _logger.Info("Waiting to finish one iteration of phase one."); await analysisRunner.WaitAsync(); } // The first data file is iteration result, the last is common analysis data file. // We don't need to read/use the last one. FileInfo finalOutputFile = finalOutputFiles.First(); DataObject <OutputFileData> data = fileWorker.ReadDataFile(finalOutputFile); _logger.Info("Finished one iteration of phase one."); return(new FileObject(fileDeleter, data)); }