public override ProcessingResult Process(FileInfo originalFile, MatchResultType matchResultType, string[] values, FileInfo[] generatedFiles, ProcessInput whatToProcess, CancellationToken token) { StringBuilder message = new StringBuilder(); List <FileInfo> outputFiles = new List <FileInfo>(); ProcessingResultType resultType = ProcessingResultType.Success; foreach (IProcessor processor in Processors) { token.ThrowIfCancellationRequested(); try { ProcessInput what = whatToProcess; if (processor.InputFileSource == InputFileSource.OriginalFile) { what = ProcessInput.OriginalFile; } ProcessingResult result = processor?.Process(originalFile, matchResultType, values, generatedFiles ?? new FileInfo[0], what, token); if (result != null) { if (result.OutputFiles != null) { outputFiles.AddRange(result.OutputFiles); } if (result.Type == ProcessingResultType.Failure) { resultType = ProcessingResultType.Failure; } if (result.Message != null) { if (message.Length > 0) { message.Append(" | "); } message.Append(result.Message); } } } catch (Exception ex) when(!(ex is OperationCanceledException)) { resultType = ProcessingResultType.Failure; if (message.Length > 0) { message.Append(" | "); } message.Append(ex.Message); RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, originalFile)); } } if (message.Length == 0) { message.Append(resultType.ToString()); } return(new ProcessingResult(resultType, message.ToString(), outputFiles.ToArray())); }
public override string ContentAsString() { string result; if (ProcessingResultType == DocumentProcessingResultType.AddFailed || ProcessingResultType == DocumentProcessingResultType.DeleteFailed || ProcessingResultType == DocumentProcessingResultType.UpdateFailed || ProcessingResultType == DocumentProcessingResultType.GetFailed) { result = $"{Regex.Replace(ProcessingResultType.ToString(), "([A-Z])", " $1").Trim()}."; } else { result = $"Document {ProcessingResultType}."; } if (!string.IsNullOrEmpty(Description)) { result += $" {Description}"; } return(result); }
public override ProcessingResult Process(FileInfo originalFile, MatchResultType matchResultType, string[] values, FileInfo[] generatedFiles, ProcessInput whatToProcess, CancellationToken token) { StringBuilder message = new StringBuilder(); List <FileInfo> resultFiles = new List <FileInfo>(); ProcessingResultType resultType = ProcessingResultType.Success; if (whatToProcess == ProcessInput.GeneratedFiles) { if (generatedFiles != null) { foreach (FileInfo f in generatedFiles) { token.ThrowIfCancellationRequested(); try { ProcessingResult result = Process(f, values, token); if (result != null) { if (result.Type == ProcessingResultType.Failure) { resultType = ProcessingResultType.Failure; } if (result.OutputFiles != null && result.OutputFiles.Length > 0) { resultFiles.AddRange(result.OutputFiles); } else { resultFiles.Add(f); } if (message.Length > 0) { message.Append(" | "); } message.Append(result.Message); } } catch (Exception ex) when(!(ex is OperationCanceledException)) { RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, f)); if (message.Length > 0) { message.Append(" | "); } message.Append(ex.Message); resultType = ProcessingResultType.Failure; } } } } else { token.ThrowIfCancellationRequested(); try { ProcessingResult tmp = Process(originalFile, values, token); if (tmp.Type == ProcessingResultType.Failure) { resultType = ProcessingResultType.Failure; } if (tmp.OutputFiles != null) { resultFiles.AddRange(tmp.OutputFiles); } message.Append(tmp.Message); } catch (Exception ex) when(!(ex is OperationCanceledException)) { resultType = ProcessingResultType.Failure; RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, originalFile)); message.Append(ex.Message); } } if (message.Length == 0) { message.Append(resultType.ToString()); } return(new ProcessingResult(resultType, message.ToString(), resultFiles.ToArray())); }