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

PdfFileBatchValidator

using kCura.WinEDDS.Exporters; using Relativity.DataExchange.Export.VolumeManagerV2.Metadata.Writers; using Relativity.DataExchange.Io; using Relativity.DataExchange.Logger; using Relativity.DataExchange.Resources; using Relativity.Logging; using System.Globalization; using System.Threading; namespace Relativity.DataExchange.Export.VolumeManagerV2.Batches { public class PdfFileBatchValidator : IBatchValidator { private readonly IErrorFileWriter _errorFileWriter; private readonly IFile _fileWrapper; private readonly IAppSettings _settings; private readonly ILog _logger; public PdfFileBatchValidator(IErrorFileWriter errorFileWriter, IFile fileWrapper, ILog logger) : this(errorFileWriter, fileWrapper, AppSettings.Instance, logger) { } public PdfFileBatchValidator(IErrorFileWriter errorFileWriter, IFile fileWrapper, IAppSettings settings, ILog logger) { _errorFileWriter = errorFileWriter.ThrowIfNull("errorFileWriter"); _fileWrapper = fileWrapper.ThrowIfNull("fileWrapper"); _settings = settings.ThrowIfNull("settings"); _logger = logger.ThrowIfNull<ILog>("logger"); } public void ValidateExportedBatch(ObjectExportInfo[] artifacts, CancellationToken cancellationToken) { foreach (ObjectExportInfo artifact in artifacts) { if (cancellationToken.IsCancellationRequested) break; ValidatePdfsForArtifact(artifact); } } private void ValidatePdfsForArtifact(ObjectExportInfo artifact) { if (!string.IsNullOrWhiteSpace(artifact.PdfDestinationLocation)) { bool flag = _fileWrapper.Exists(artifact.PdfDestinationLocation); if (!flag || _fileWrapper.GetFileSize(artifact.PdfDestinationLocation) == 0) { if (flag && !_settings.CreateErrorForEmptyPdfFile) _logger.LogVerbose("PDF file {File} contains zero bytes for artifact {ArtifactId} but the export is configured to skip creating an error.", new object[2] { artifact.PdfDestinationLocation.Secure(), artifact.ArtifactID }); else { string errorText = string.Format(CultureInfo.CurrentCulture, flag ? ExportStrings.FileValidationZeroByteFile : ExportStrings.FileValidationFileMissing, artifact.ArtifactID); if (string.IsNullOrWhiteSpace(artifact.PdfSourceLocation)) { errorText = string.Format(CultureInfo.CurrentCulture, ExportStrings.FileValidationEmptyRemoteSourcePath, artifact.ArtifactID); _logger.LogError("PDF file remote source path is null or whitespace for PDF artifact {ArtifactId} and indicates a problem with the artifact data.", new object[1] { artifact.ArtifactID }); } else _logger.LogError(flag ? "PDF file contains zero bytes for artifact {ArtifactId}." : "PDF file is missing for artifact {ArtifactId}.", new object[1] { artifact.ArtifactID }); _errorFileWriter.Write(ErrorFileWriter.ExportFileType.Pdf, artifact, artifact.PdfDestinationLocation, errorText); } } } } } }