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

NativeFileBatchValidator

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 NativeFileBatchValidator : IBatchValidator { private readonly IErrorFileWriter _errorFileWriter; private readonly IFile _fileWrapper; private readonly IAppSettings _settings; private readonly ILog _logger; public NativeFileBatchValidator(IErrorFileWriter errorFileWriter, IFile fileWrapper, ILog logger) : this(errorFileWriter, fileWrapper, AppSettings.Instance, logger) { } public NativeFileBatchValidator(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) { for (int i = 0; i < artifacts.Length; i++) { if (cancellationToken.IsCancellationRequested) break; ValidateNativesForArtifact(artifacts[i]); } } private void ValidateNativesForArtifact(ObjectExportInfo artifact) { if (!string.IsNullOrWhiteSpace(artifact.NativeTempLocation)) { bool flag = _fileWrapper.Exists(artifact.NativeTempLocation); if (!flag || _fileWrapper.GetFileSize(artifact.NativeTempLocation) == 0) { if (flag && !_settings.CreateErrorForEmptyNativeFile) _logger.LogVerbose("Native file {File} contains zero bytes for artifact {ArtifactId} but the export but the export is configured to skip creating an error.", new object[2] { artifact.NativeTempLocation.Secure(), artifact.ArtifactID }); else { string errorText = string.Format(CultureInfo.CurrentCulture, flag ? ExportStrings.FileValidationZeroByteFile : ExportStrings.FileValidationFileMissing, artifact.ArtifactID); if (string.IsNullOrWhiteSpace(artifact.NativeSourceLocation)) { errorText = string.Format(CultureInfo.CurrentCulture, ExportStrings.FileValidationEmptyRemoteSourcePath, artifact.ArtifactID); _logger.LogError("Native file remote source path is null or whitespace for native artifact {ArtifactId} and indicates a problem with the artifact data.", new object[1] { artifact.ArtifactID }); } else _logger.LogError(flag ? "Native file contains zero bytes for artifact {ArtifactId}." : "Native file is missing for artifact {ArtifactId}.", new object[1] { artifact.ArtifactID }); _errorFileWriter.Write(ErrorFileWriter.ExportFileType.Native, artifact, artifact.NativeTempLocation, errorText); } } } } } }