<PackageReference Include="Relativity.Server.Import.SDK" Version="2.9.2" />

ErrorFileWriter

using Castle.Core; using kCura.WinEDDS; using kCura.WinEDDS.Exporters; using Relativity.DataExchange.Export.VolumeManagerV2.Metadata.Paths; using Relativity.DataExchange.Logger; using Relativity.Logging; using System; using System.IO; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Relativity.DataExchange.Export.VolumeManagerV2.Metadata.Writers { public class ErrorFileWriter : IErrorFileWriter, IDisposable { public enum ExportFileType { Image, Native, Generic, Pdf } private StreamWriter _streamWriter; private readonly IStreamFactory _streamFactory; private readonly IDestinationPath _errorFileDestinationPath; private readonly IStatus _status; private readonly ILog _logger; public ErrorFileWriter(IStreamFactory streamFactory, ErrorFileDestinationPath errorFileDestinationPath, IStatus status, ILog logger) : this(streamFactory, (IDestinationPath)errorFileDestinationPath, status, logger) { } [DoNotSelect] public ErrorFileWriter(IStreamFactory streamFactory, IDestinationPath errorFileDestinationPath, IStatus status, ILog logger) { _streamFactory = streamFactory; _errorFileDestinationPath = errorFileDestinationPath; _logger = logger; _status = status; } public void Write(ExportFileType type, ObjectExportInfo documentInfo, string fileLocation, string errorText) { WriteAsync(type, documentInfo, fileLocation, errorText).ConfigureAwait(false).GetAwaiter().GetResult(); } [AsyncStateMachine(typeof(<WriteAsync>d__8))] public Task WriteAsync(ExportFileType type, ObjectExportInfo documentInfo, string fileLocation, string errorText) { <WriteAsync>d__8 stateMachine = default(<WriteAsync>d__8); stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.type = type; stateMachine.documentInfo = documentInfo; stateMachine.fileLocation = fileLocation; stateMachine.errorText = errorText; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } private void UpdateStatus(ObjectExportInfo documentInfo, ExportFileType type, string recordIdentifier, string fileLocation, string errorText) { string line = $"{type}""{recordIdentifier}""{fileLocation}""{Environment.NewLine}{errorText}"; if (documentInfo == null || !documentInfo.DocumentError) _status.WriteError(line); else _status.WriteWarning(line); } [AsyncStateMachine(typeof(<InitializeStreamAsync>d__10))] private Task InitializeStreamAsync() { <InitializeStreamAsync>d__10 stateMachine = default(<InitializeStreamAsync>d__10); stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } private Task WriteHeaderAsync() { string value = FormatErrorLine("File Type", "Document Identifier", "File Guid", "Error Description"); return _streamWriter.WriteLineAsync(value); } private Task WriteLineAsync(ExportFileType type, string recordIdentifier, string fileLocation, string errorText) { string value = FormatErrorLine(type.ToString(), recordIdentifier, fileLocation, errorText.ToCsvCellContents()); _logger.LogError("{fileType},{documentIdentifier},{fileGuid},{errorDescription}", new object[4] { type.ToString(), recordIdentifier, fileLocation.Secure(), errorText.ToCsvCellContents() }); return _streamWriter.WriteLineAsync(value); } private string FormatErrorLine(string fileType, string documentIdentifier, string fileGuid, string errorDescription) { return "\"" + fileType + "\",\"" + documentIdentifier + "\",\"" + fileGuid + "\",\"" + errorDescription + "\""; } public void Dispose() { _streamWriter?.Dispose(); } } }