diff --git a/Relativity.Export.Samples.RelConsole/Relativity.Export.Samples.RelConsole.csproj b/Relativity.Export.Samples.RelConsole/Relativity.Export.Samples.RelConsole.csproj index debb446..a33d5fd 100644 --- a/Relativity.Export.Samples.RelConsole/Relativity.Export.Samples.RelConsole.csproj +++ b/Relativity.Export.Samples.RelConsole/Relativity.Export.Samples.RelConsole.csproj @@ -8,7 +8,7 @@ - + diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/BaseExportService.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/BaseExportService.cs index 4e4c283..f806529 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/BaseExportService.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/BaseExportService.cs @@ -1,106 +1,106 @@ -using System.Diagnostics; -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Model; -using Relativity.Services.ServiceProxy; -using Spectre.Console; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - private readonly Logger _logger; - private readonly IServiceFactory _serviceFactory; - private readonly string _host; - private readonly string _username; - private readonly string _password; - - public BaseExportService(string host, string username, string password, string[] args = default!) - { - this._host = host; - this._username = username; - this._password = password; - - this._serviceFactory = this.GetServiceFactory(); - - _logger = new Logger(args); - } - - protected IServiceFactory GetServiceFactory() - { - Uri relativityRestUri = new Uri($"{this._host}relativity.rest/api"); - Credentials credentials = new UsernamePasswordCredentials(this._username, this._password); - - ServiceFactorySettings settings = new ServiceFactorySettings(relativityRestUri, credentials); - - return new ServiceFactory(settings); - } - - private async Task> WaitForJobToBeCompletedAsync(Func>> job, bool updateStatus = true, int frequency = 5_000) - { - ValueResponse? jobStatus = null; - CancellationTokenSource tokenSource = new(); - Stopwatch watch = Stopwatch.StartNew(); - int retries = 3; - - if (updateStatus) - { - // request time measurement - Task watchUpdater = Task.Run(async () => - { - while (!tokenSource.IsCancellationRequested) - { - OutputHelper.UpdateStatus($"Fetching updates ({watch.ElapsedMilliseconds} ms)"); - await Task.Delay(100); - } - }, tokenSource.Token); - } - - do - { - try - { - jobStatus = await job(); - - if (jobStatus is null) - throw new Exception("The response was incorrect"); - - string logData = - $"Export job ID: {jobStatus.ExportJobID}\n" - + $"Job status: [aquamarine1]{jobStatus.Value.JobStatus}[/]"; - - _logger.LogInformation(logData); - - await Task.Delay(frequency); - retries = 3; - } - catch (Exception) when (retries > 0) - { - retries--; - _logger.LogWarning($"Retrying job status fetching ({retries} retries left)"); - await Task.Delay(3000); - - } - catch (Exception ex) - { - AnsiConsole.WriteException(ex); - throw; - } - finally - { - watch.Restart(); - } - } while (jobStatus?.Value.JobStatus is not ExportStatus.Completed - and not ExportStatus.CompletedWithErrors - and not ExportStatus.Failed - and not ExportStatus.Cancelled); - - tokenSource.Cancel(); - - if (jobStatus.Value.JobStatus == ExportStatus.Failed) - { - _logger.LogError($"{jobStatus.Value.ErrorCode} - {jobStatus.Value.ErrorMessage}"); - } - - return jobStatus; - } -} +using System.Diagnostics; +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Model; +using Relativity.Services.ServiceProxy; +using Spectre.Console; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + private readonly Logger _logger; + private readonly IServiceFactory _serviceFactory; + private readonly string _host; + private readonly string _username; + private readonly string _password; + + public BaseExportService(string host, string username, string password, string[] args = default!) + { + this._host = host; + this._username = username; + this._password = password; + + this._serviceFactory = this.GetServiceFactory(); + + _logger = new Logger(args); + } + + protected IServiceFactory GetServiceFactory() + { + Uri relativityRestUri = new Uri($"{this._host}relativity.rest/api"); + Credentials credentials = new UsernamePasswordCredentials(this._username, this._password); + + ServiceFactorySettings settings = new ServiceFactorySettings(relativityRestUri, credentials); + + return new ServiceFactory(settings); + } + + private async Task> WaitForJobToBeCompletedAsync(Func>> job, bool updateStatus = true, int frequency = 5_000) + { + ValueResponse? jobStatus = null; + CancellationTokenSource tokenSource = new(); + Stopwatch watch = Stopwatch.StartNew(); + int retries = 3; + + if (updateStatus) + { + // request time measurement + Task watchUpdater = Task.Run(async () => + { + while (!tokenSource.IsCancellationRequested) + { + OutputHelper.UpdateStatus($"Fetching updates ({watch.ElapsedMilliseconds} ms)"); + await Task.Delay(100); + } + }, tokenSource.Token); + } + + do + { + try + { + jobStatus = await job(); + + if (jobStatus is null) + throw new Exception("The response was incorrect"); + + string logData = + $"Export job ID: {jobStatus.ExportJobID}\n" + + $"Job status: [aquamarine1]{jobStatus.Value.JobStatus}[/]"; + + _logger.LogInformation(logData); + + await Task.Delay(frequency); + retries = 3; + } + catch (Exception) when (retries > 0) + { + retries--; + _logger.LogWarning($"Retrying job status fetching ({retries} retries left)"); + await Task.Delay(3000); + + } + catch (Exception ex) + { + AnsiConsole.WriteException(ex); + throw; + } + finally + { + watch.Restart(); + } + } while (jobStatus?.Value.JobStatus is not ExportStatus.Completed + and not ExportStatus.CompletedWithErrors + and not ExportStatus.Failed + and not ExportStatus.Cancelled); + + tokenSource.Cancel(); + + if (jobStatus.Value.JobStatus == ExportStatus.Failed) + { + _logger.LogError($"{jobStatus.Value.ErrorCode} - {jobStatus.Value.ErrorMessage}"); + } + + return jobStatus; + } +} diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All.cs index ad6098e..3a313b2 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All.cs @@ -1,202 +1,203 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(5, nameof(Export_FromFolder_All), "Exports native, fulltext, images and PDF files from folder")] - public async Task Export_FromFolder_All() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = "Sample-Job-0001"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithSubfolders() // include subfolders - .WithCustomStartAtDocumentNumber(1) - .Build(); - - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings - .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images - .WithTypeOfImage(ImageType.Pdf)) - .ExportFullText(settings => settings - .ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) - .ExportNative(settings => settings - .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files - .ExportPdf() // Export PDF files - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - // Optional overrides - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - prefixes.NativeSubdirectoryPrefix = "NATIVE_"; - prefixes.ImageSubdirectoryPrefix = "IMAGE_"; - prefixes.PdfSubdirectoryPrefix = "PDF_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong. Received empty response."); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(5, nameof(Export_FromFolder_All), "Exports native, fulltext, images and PDF files from folder")] + public async Task Export_FromFolder_All() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = "Sample-Job-0001"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithSubfolders() // include subfolders + .WithCustomStartAtDocumentNumber(1) + .Build(); + + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings + .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images + .WithTypeOfImage(ImageType.Pdf)) + .ExportFullText(settings => settings + .ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) + .ExportNative(settings => settings + .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files + .ExportPdf() // Export PDF files + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + // Optional overrides + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + prefixes.NativeSubdirectoryPrefix = "NATIVE_"; + prefixes.ImageSubdirectoryPrefix = "IMAGE_"; + prefixes.PdfSubdirectoryPrefix = "PDF_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong. Received empty response."); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_With_DataSource_Name_In_Loadfile.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_With_DataSource_Name_In_Loadfile.cs index 262a9ea..1756644 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_With_DataSource_Name_In_Loadfile.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_With_DataSource_Name_In_Loadfile.cs @@ -6,198 +6,199 @@ namespace Relativity.Export.Samples.RelConsole.SampleCollection; public partial class BaseExportService { - [SampleMetadata(21, nameof(Export_Folder_All_With_DataSource_Name_In_Loadfile), "Exports native, fulltext, images and PDF files from folder. Exported laodfiles names contians DataSource name and date.")] - public async Task Export_Folder_All_With_DataSource_Name_In_Loadfile() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = "Sample-Job-0001"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithSubfolders() // include subfolders - .WithCustomStartAtDocumentNumber(1) - .Build(); - - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings - .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images - .WithTypeOfImage(ImageType.Pdf)) - .ExportFullText(settings => settings - .ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) - .ExportNative(settings => settings - .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files - .ExportPdf() // Export PDF files - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - // Optional overrides - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - prefixes.NativeSubdirectoryPrefix = "NATIVE_"; - prefixes.ImageSubdirectoryPrefix = "IMAGE_"; - prefixes.PdfSubdirectoryPrefix = "PDF_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadfileNameFormat(LoadfileNameFormat.WithDataSourceNameAndDate) // exported loadfiles names with following naming convention: #TypeOfExport#_#SourceName#_#DateTime#_export.dat - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong. Received empty response."); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } + [SampleMetadata(21, nameof(Export_Folder_All_With_DataSource_Name_In_Loadfile), "Exports native, fulltext, images and PDF files from folder. Exported laodfiles names contians DataSource name and date.")] + public async Task Export_Folder_All_With_DataSource_Name_In_Loadfile() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = "Sample-Job-0001"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithSubfolders() // include subfolders + .WithCustomStartAtDocumentNumber(1) + .Build(); + + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings + .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images + .WithTypeOfImage(ImageType.Pdf)) + .ExportFullText(settings => settings + .ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) + .ExportNative(settings => settings + .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files + .ExportPdf() // Export PDF files + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + // Optional overrides + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + prefixes.NativeSubdirectoryPrefix = "NATIVE_"; + prefixes.ImageSubdirectoryPrefix = "IMAGE_"; + prefixes.PdfSubdirectoryPrefix = "PDF_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadfileNameFormat(LoadfileNameFormat.WithDataSourceNameAndDate) // exported loadfiles names with following naming convention: #TypeOfExport#_#SourceName#_#DateTime#_export.dat + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong. Received empty response."); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_FullText.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_FullText.cs index 6afd193..12a5c0f 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_FullText.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_FullText.cs @@ -1,192 +1,193 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(4, nameof(Export_FromFolder_FullText), "Exports Fulltext from folder")] - public async Task Export_FromFolder_FullText() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromFolder_FullText)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List precedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .ExportFullText(settings => settings.ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(precedenceFieldsArtifactIds)) - .WithoutExportingNative() - .WithoutExportingPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(4, nameof(Export_FromFolder_FullText), "Exports Fulltext from folder")] + public async Task Export_FromFolder_FullText() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromFolder_FullText)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List precedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .ExportFullText(settings => settings.ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(precedenceFieldsArtifactIds)) + .WithoutExportingNative() + .WithoutExportingPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_Images.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_Images.cs index 362c8c4..7e62428 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_Images.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_Images.cs @@ -1,186 +1,187 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(2, nameof(Export_FromFolder_Images), "Exports images from folder")] - public async Task Export_FromFolder_Images() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromFolder_Images)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings.WithImagePrecedenceArtifactIDs(new List { -1 }) // exports only images - .WithTypeOfImage(ImageType.Pdf)) - .WithoutExportingFullText() - .WithoutExportingNative() - .WithoutExportingPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.ImageSubdirectoryPrefix = "Image_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO) - .WithDelimiterSettings(delimiters => - delimiters.WithCustomRecordDelimiters('A') - .WithQuoteDelimiter('B') - .WithNewLineDelimiter('C') - .WithNestedValueDelimiter('D') - .WithMultiValueDelimiter('E')) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(2, nameof(Export_FromFolder_Images), "Exports images from folder")] + public async Task Export_FromFolder_Images() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromFolder_Images)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings.WithImagePrecedenceArtifactIDs(new List { -1 }) // exports only images + .WithTypeOfImage(ImageType.Pdf)) + .WithoutExportingFullText() + .WithoutExportingNative() + .WithoutExportingPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.ImageSubdirectoryPrefix = "Image_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO) + .WithDelimiterSettings(delimiters => + delimiters.WithCustomRecordDelimiters('A') + .WithQuoteDelimiter('B') + .WithNewLineDelimiter('C') + .WithNestedValueDelimiter('D') + .WithMultiValueDelimiter('E')) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_NativeFiles.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_NativeFiles.cs index 285b4ce..d55e47d 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_NativeFiles.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_NativeFiles.cs @@ -1,182 +1,183 @@ -using System; -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(1, nameof(Export_FromFolder_NativeFiles), "Exports native files from folder")] - public async Task Export_FromFolder_NativeFiles() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromFolder_NativeFiles)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID","10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .WithoutExportingFullText() - .ExportNative(settings => settings.WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports only native files - .WithoutExportingPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.NativeSubdirectoryPrefix = "Native_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithCustomDateTimeFormat("O") - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using System; +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(1, nameof(Export_FromFolder_NativeFiles), "Exports native files from folder")] + public async Task Export_FromFolder_NativeFiles() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromFolder_NativeFiles)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID","10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .WithoutExportingFullText() + .ExportNative(settings => settings.WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports only native files + .WithoutExportingPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.NativeSubdirectoryPrefix = "Native_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithCustomDateTimeFormat("O") + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_PDF.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_PDF.cs index d79953b..7e66bfa 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_PDF.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_PDF.cs @@ -1,180 +1,181 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(3, nameof(Export_FromFolder_PDF), "Exports PDF files from folder")] - public async Task Export_FromFolder_PDF() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromFolder_PDF)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .WithoutExportingFullText() - .WithoutExportingNative() - .ExportPdf() // Exports only PDF - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.PdfSubdirectoryPrefix = "PDF_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(3, nameof(Export_FromFolder_PDF), "Exports PDF files from folder")] + public async Task Export_FromFolder_PDF() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromFolder_PDF)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .WithoutExportingFullText() + .WithoutExportingNative() + .ExportPdf() // Exports only PDF + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.PdfSubdirectoryPrefix = "PDF_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_All.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_All.cs index ecd1ae1..3aef206 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_All.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_All.cs @@ -1,206 +1,207 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(15, nameof(Export_FromProduction_All), "Exports native, fulltext, images and PDF files from production set")] - public async Task Export_FromProduction_All() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your production set ID - int productionID = 1042542; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_All)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Production ID", productionID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromProduction(exportSourceArtifactID: productionID) - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings - .WithImagePrecedenceArtifactIDs(new List { productionID }) // Exports images - .WithTypeOfImage(ImageType.Pdf)) - .ExportFullText(settings => settings - .ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) - .ExportNative(settings => settings - .WithNativePrecedenceArtifactIDs(new List { productionID })) // Exports native files - .ExportPdf() // Export PDF files - .WithFieldArtifactIDs(new List { 1003676, 1003667, 1035354 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - // Optional overrides - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - prefixes.NativeSubdirectoryPrefix = "NATIVE_"; - prefixes.ImageSubdirectoryPrefix = "IMAGE_"; - prefixes.PdfSubdirectoryPrefix = "PDF_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - Action volumeSettingsBuilder = (settingsBuilder) => - { - settingsBuilder.WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5); - }; - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO_FullText) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithCustomRecordDelimiters(',') - .WithQuoteDelimiter('"') - .WithNewLineDelimiter('\n') - .WithNestedValueDelimiter(';') - .WithMultiValueDelimiter('|')) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(15, nameof(Export_FromProduction_All), "Exports native, fulltext, images and PDF files from production set")] + public async Task Export_FromProduction_All() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your production set ID + int productionID = 1042542; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_All)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Production ID", productionID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromProduction(exportSourceArtifactID: productionID) + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings + .WithImagePrecedenceArtifactIDs(new List { productionID }) // Exports images + .WithTypeOfImage(ImageType.Pdf)) + .ExportFullText(settings => settings + .ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) + .ExportNative(settings => settings + .WithNativePrecedenceArtifactIDs(new List { productionID })) // Exports native files + .ExportPdf() // Export PDF files + .WithFieldArtifactIDs(new List { 1003676, 1003667, 1035354 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + // Optional overrides + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + prefixes.NativeSubdirectoryPrefix = "NATIVE_"; + prefixes.ImageSubdirectoryPrefix = "IMAGE_"; + prefixes.PdfSubdirectoryPrefix = "PDF_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + Action volumeSettingsBuilder = (settingsBuilder) => + { + settingsBuilder.WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5); + }; + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO_FullText) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithCustomRecordDelimiters(',') + .WithQuoteDelimiter('"') + .WithNewLineDelimiter('\n') + .WithNestedValueDelimiter(';') + .WithMultiValueDelimiter('|')) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_FullText.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_FullText.cs index ece06b4..3a88943 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_FullText.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_FullText.cs @@ -1,186 +1,187 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(14, nameof(Export_FromProduction_Fulltext), "Exports fulltext from production")] - public async Task Export_FromProduction_Fulltext() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your production set ID - int productionID = 1042542; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_Fulltext)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Production ID", productionID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromProduction(exportSourceArtifactID: productionID) - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .ExportFullText(settings => settings - .ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) - .WithoutExportingNative() - .WithoutExportingPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(14, nameof(Export_FromProduction_Fulltext), "Exports fulltext from production")] + public async Task Export_FromProduction_Fulltext() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your production set ID + int productionID = 1042542; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_Fulltext)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Production ID", productionID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromProduction(exportSourceArtifactID: productionID) + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .ExportFullText(settings => settings + .ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) + .WithoutExportingNative() + .WithoutExportingPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_Images.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_Images.cs index 824e316..1534ef6 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_Images.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_Images.cs @@ -1,176 +1,177 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(12, nameof(Export_FromProduction_Images), "Exports images from folder")] - public async Task Export_FromProduction_Images() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your production set ID - int productionID = 1042542; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_Images)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Production ID", productionID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromProduction(exportSourceArtifactID: productionID) - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings - .WithImagePrecedenceArtifactIDs(new List { productionID }) // Exports images - .WithTypeOfImage(ImageType.SinglePage)) - .WithoutExportingFullText() - .WithoutExportingNative() - .WithoutExportingPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.ImageSubdirectoryPrefix = "IMAGE_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(12, nameof(Export_FromProduction_Images), "Exports images from folder")] + public async Task Export_FromProduction_Images() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your production set ID + int productionID = 1042542; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_Images)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Production ID", productionID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromProduction(exportSourceArtifactID: productionID) + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings + .WithImagePrecedenceArtifactIDs(new List { productionID }) // Exports images + .WithTypeOfImage(ImageType.SinglePage)) + .WithoutExportingFullText() + .WithoutExportingNative() + .WithoutExportingPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.ImageSubdirectoryPrefix = "IMAGE_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_NativeFiles.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_NativeFiles.cs index 018ebf1..c47bafc 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_NativeFiles.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_NativeFiles.cs @@ -1,174 +1,175 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(11, nameof(Export_FromProduction_NativeFiles), "Exports native files from production")] - public async Task Export_FromProduction_NativeFiles() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your production set ID - int productionID = 1042542; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_NativeFiles)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Production ID", productionID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromProduction(exportSourceArtifactID: productionID) - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .WithoutExportingFullText() - .ExportNative(settings => settings.WithNativePrecedenceArtifactIDs(new List { productionID })) // Exports native files - .WithoutExportingPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.NativeSubdirectoryPrefix = "Native_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(11, nameof(Export_FromProduction_NativeFiles), "Exports native files from production")] + public async Task Export_FromProduction_NativeFiles() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your production set ID + int productionID = 1042542; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_NativeFiles)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Production ID", productionID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromProduction(exportSourceArtifactID: productionID) + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .WithoutExportingFullText() + .ExportNative(settings => settings.WithNativePrecedenceArtifactIDs(new List { productionID })) // Exports native files + .WithoutExportingPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.NativeSubdirectoryPrefix = "Native_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_PDF.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_PDF.cs index 544c8e0..c236742 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_PDF.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_PDF.cs @@ -1,173 +1,174 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(13, nameof(Export_FromProduction_PDF), "Exports PDF files from a production")] - public async Task Export_FromProduction_PDF() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your production set ID - int productionID = 1042542; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_PDF)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Production ID", productionID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromProduction(exportSourceArtifactID: productionID) - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .WithoutExportingFullText() - .WithoutExportingNative() - .ExportPdf() // Export PDF files - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.PdfSubdirectoryPrefix = "PDF_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(13, nameof(Export_FromProduction_PDF), "Exports PDF files from a production")] + public async Task Export_FromProduction_PDF() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your production set ID + int productionID = 1042542; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromProduction_PDF)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Production ID", productionID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromProduction(exportSourceArtifactID: productionID) + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .WithoutExportingFullText() + .WithoutExportingNative() + .ExportPdf() // Export PDF files + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.PdfSubdirectoryPrefix = "PDF_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_RDO.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_RDO.cs index 0ca08ee..1d581f1 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_RDO.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_RDO.cs @@ -1,198 +1,199 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(16, nameof(Export_RDO), "Exports RDO objects")] - public async Task Export_RDO() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - // int workspaceID = 1020245; - int workspaceID = 6648897; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - // int viewID = 1042316; - int viewID = 1036791; // Dev view - - // Artifact type ID of entities to export. - // In this case we export import/export job so we set the ID to 1001057. - // int artifactTypeID = 1001057; - int artifactTypeID = 1000022; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_RDO)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Artifact Type ID", artifactTypeID.ToString() }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // This represents alternative approach of using export SDK builders - // Export source settings - Action sourceSettingsBuilder = (settingsBuilder) => - { - // Set object type ID, Folder ID and View ID - settingsBuilder.FromObjects(artifactTypeID: artifactTypeID, viewID) - .WithCustomStartAtDocumentNumber(1); - }; - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - Action artifactSettingsBuilder = (settingsBuilder) => - { - settingsBuilder.WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .WithoutExportingFullText() - .WithoutExportingNative() - .WithoutExportingPdf() // Export PDF files - .WithFieldArtifactIDs(new List() { 1036665 }) // Fields to export - .ExportMultiChoicesAsNested(); - }; - - // Subdirectory settings - Action subdirectorySettingsBuilder = (settingsBuilder) => - { - settingsBuilder.WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .WithSubdirectoryDigitPadding(5); - }; - - // Volume settings - Action volumeSettingsBuilder = (settingsBuilder) => - { - settingsBuilder.WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5); - }; - - // Loadfile settings - Action loadFileSettingsBuilder = (settingsBuilder) => - { - settingsBuilder.WithoutExportingMsAccess() - .WithCustomCultureInfo("en-US") - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.Opticon) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()); - }; - - // Output settings - Action outputSettingsBuilder = (settingsBuilder) => - { - settingsBuilder.WithArchiveCreation() - .WithCustomFolderStructure(FolderStructure.Classic) - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettingsBuilder) - .WithVolumeSettings(volumeSettingsBuilder) - .WithLoadFileSettings(loadFileSettingsBuilder); - }; - - // Connect all settings in the Job builder - var settingsBuilder = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettingsBuilder) - .WithExportArtifactSettings(artifactSettingsBuilder) - .WithExportOutputSettings(outputSettingsBuilder); - - // Build settings from builder - var jobSettings = settingsBuilder.Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(16, nameof(Export_RDO), "Exports RDO objects")] + public async Task Export_RDO() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + // int workspaceID = 1020245; + int workspaceID = 6648897; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + // int viewID = 1042316; + int viewID = 1036791; // Dev view + + // Artifact type ID of entities to export. + // In this case we export import/export job so we set the ID to 1001057. + // int artifactTypeID = 1001057; + int artifactTypeID = 1000022; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_RDO)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Artifact Type ID", artifactTypeID.ToString() }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // This represents alternative approach of using export SDK builders + // Export source settings + Action sourceSettingsBuilder = (settingsBuilder) => + { + // Set object type ID, Folder ID and View ID + settingsBuilder.FromObjects(artifactTypeID: artifactTypeID, viewID) + .WithCustomStartAtDocumentNumber(1); + }; + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + Action artifactSettingsBuilder = (settingsBuilder) => + { + settingsBuilder.WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .WithoutExportingFullText() + .WithoutExportingNative() + .WithoutExportingPdf() // Export PDF files + .WithFieldArtifactIDs(new List() { 1036665 }) // Fields to export + .WithoutFieldAliases() + .ExportMultiChoicesAsNested(); + }; + + // Subdirectory settings + Action subdirectorySettingsBuilder = (settingsBuilder) => + { + settingsBuilder.WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .WithSubdirectoryDigitPadding(5); + }; + + // Volume settings + Action volumeSettingsBuilder = (settingsBuilder) => + { + settingsBuilder.WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5); + }; + + // Loadfile settings + Action loadFileSettingsBuilder = (settingsBuilder) => + { + settingsBuilder.WithoutExportingMsAccess() + .WithCustomCultureInfo("en-US") + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.Opticon) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()); + }; + + // Output settings + Action outputSettingsBuilder = (settingsBuilder) => + { + settingsBuilder.WithArchiveCreation(ArchiveNameFormat.WithDataSourceNameAndDate) + .WithCustomFolderStructure(FolderStructure.Classic) + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettingsBuilder) + .WithVolumeSettings(volumeSettingsBuilder) + .WithLoadFileSettings(loadFileSettingsBuilder); + }; + + // Connect all settings in the Job builder + var settingsBuilder = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettingsBuilder) + .WithExportArtifactSettings(artifactSettingsBuilder) + .WithExportOutputSettings(outputSettingsBuilder); + + // Build settings from builder + var jobSettings = settingsBuilder.Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_All.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_All.cs index 6085b27..b3b7ffc 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_All.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_All.cs @@ -1,172 +1,173 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(10, nameof(Export_FromSavedSearch_All), "Exports native, fulltext, images and PDF files from saved search")] - public async Task Export_FromSavedSearch_All() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your saved search ID. - int savedSearchID = 1042325; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_All)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Saved Search ID", savedSearchID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // This represents alternative approach of using export SDK builders - var settingsBuilder = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(exportSourceSettings => // Export Source Settings - exportSourceSettings.FromSavedSearch(exportSourceArtifactID: savedSearchID) - .WithDefaultStartAtDocumentNumber()) - .WithExportArtifactSettings(artifactSettings => // Artifact Settings - artifactSettings.WithCustomPatternBuilder('_') - .AppendIdentifier() - .AppendCustomText("CustomPatternText") - .AppendOriginalFileName() - .BuildPattern() // Ends building the file pattern and applies it to the resulting object - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings.WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images - .WithTypeOfImage(ImageType.Pdf)) - .ExportFullText(settings => settings.ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) - .ExportNative(settings => settings.WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files - .ExportPdf() // Export PDF files - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .ExportMultiChoicesAsNested()) - .WithExportOutputSettings(settings => // Export output settings - settings.WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subSettings => // Subdirectory settings - subSettings.WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(10) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - // Optional overrides - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - prefixes.NativeSubdirectoryPrefix = "NATIVE_"; - prefixes.ImageSubdirectoryPrefix = "IMAGE_"; - prefixes.PdfSubdirectoryPrefix = "PDF_"; - }) - .WithSubdirectoryDigitPadding(5)) - .WithVolumeSettings(volumeSettings => // Volume settings - volumeSettings.WithVolumePrefix("VOL_SEARCH_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5)) - .WithLoadFileSettings(loadFileSettings => // Loadfile settings - loadFileSettings.WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO) - .WithDelimiterSettings(delimiterSettings => // Delimiter settings - delimiterSettings.WithDefaultDelimiters()))); - - // Build settings from builder - var jobSettings = settingsBuilder.Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } -} +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(10, nameof(Export_FromSavedSearch_All), "Exports native, fulltext, images and PDF files from saved search")] + public async Task Export_FromSavedSearch_All() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your saved search ID. + int savedSearchID = 1042325; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_All)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Saved Search ID", savedSearchID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // This represents alternative approach of using export SDK builders + var settingsBuilder = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(exportSourceSettings => // Export Source Settings + exportSourceSettings.FromSavedSearch(exportSourceArtifactID: savedSearchID) + .WithDefaultStartAtDocumentNumber()) + .WithExportArtifactSettings(artifactSettings => // Artifact Settings + artifactSettings.WithCustomPatternBuilder('_') + .AppendIdentifier() + .AppendCustomText("CustomPatternText") + .AppendOriginalFileName() + .BuildPattern() // Ends building the file pattern and applies it to the resulting object + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings.WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images + .WithTypeOfImage(ImageType.Pdf)) + .ExportFullText(settings => settings.ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) + .ExportNative(settings => settings.WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files + .ExportPdf() // Export PDF files + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .ExportMultiChoicesAsNested()) + .WithExportOutputSettings(settings => // Export output settings + settings.WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subSettings => // Subdirectory settings + subSettings.WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(10) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + // Optional overrides + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + prefixes.NativeSubdirectoryPrefix = "NATIVE_"; + prefixes.ImageSubdirectoryPrefix = "IMAGE_"; + prefixes.PdfSubdirectoryPrefix = "PDF_"; + }) + .WithSubdirectoryDigitPadding(5)) + .WithVolumeSettings(volumeSettings => // Volume settings + volumeSettings.WithVolumePrefix("VOL_SEARCH_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5)) + .WithLoadFileSettings(loadFileSettings => // Loadfile settings + loadFileSettings.WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO) + .WithDelimiterSettings(delimiterSettings => // Delimiter settings + delimiterSettings.WithDefaultDelimiters()))); + + // Build settings from builder + var jobSettings = settingsBuilder.Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } +} diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_FullText.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_FullText.cs index bcd15cb..b14c123 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_FullText.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_FullText.cs @@ -1,190 +1,191 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(9, nameof(Export_FromSavedSearch_FullText), "Exports fulltext from saved search")] - public async Task Export_FromSavedSearch_FullText() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your saved search ID. - int savedSearchID = 1042325; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_FullText)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Saved Search ID", savedSearchID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List precedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromSavedSearch(exportSourceArtifactID: savedSearchID) - .WithDefaultStartAtDocumentNumber() - .Build(); - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithCustomPatternBuilder('_') - .AppendIdentifier() - .AppendCustomText("CustomPatternText") - .AppendOriginalFileName() - .BuildPattern() // Ends building the file pattern and applies it to the resulting object - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .ExportFullText(settings => settings - .ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(precedenceFieldsArtifactIds)) - .WithoutExportingNative() - .WithoutExportingPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .ExportMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_SEARCH_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.DAT) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } -} +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(9, nameof(Export_FromSavedSearch_FullText), "Exports fulltext from saved search")] + public async Task Export_FromSavedSearch_FullText() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your saved search ID. + int savedSearchID = 1042325; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_FullText)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Saved Search ID", savedSearchID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List precedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromSavedSearch(exportSourceArtifactID: savedSearchID) + .WithDefaultStartAtDocumentNumber() + .Build(); + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithCustomPatternBuilder('_') + .AppendIdentifier() + .AppendCustomText("CustomPatternText") + .AppendOriginalFileName() + .BuildPattern() // Ends building the file pattern and applies it to the resulting object + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .ExportFullText(settings => settings + .ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(precedenceFieldsArtifactIds)) + .WithoutExportingNative() + .WithoutExportingPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .ExportMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_SEARCH_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.DAT) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } +} diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_Images.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_Images.cs index 6859c96..376ac38 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_Images.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_Images.cs @@ -1,156 +1,157 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(7, nameof(Export_FromSavedSearch_Images), "Exports images from saved search")] - public async Task Export_FromSavedSearch_Images() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your saved search ID. - int savedSearchID = 1042325; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_Images)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Saved Search ID", savedSearchID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - var settingsBuilder = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(exportSourceSettings => // Export Source Settings - exportSourceSettings.FromSavedSearch(exportSourceArtifactID: savedSearchID) - .WithDefaultStartAtDocumentNumber()) - .WithExportArtifactSettings(artifactSettings => // Artifact Settings - artifactSettings.WithCustomPatternBuilder('_') - .AppendIdentifier() - .AppendCustomText("CustomPatternText") - .AppendOriginalFileName() - .BuildPattern() // Ends building the file pattern and applies it to the resulting object - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings.WithImagePrecedenceArtifactIDs(new List { -1 }) // exports only images - .WithTypeOfImage(ImageType.Pdf)) - .WithoutExportingFullText() - .WithoutExportingNative() - .WithoutExportingPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .ExportMultiChoicesAsNested()) - .WithExportOutputSettings(settings => // Export output settings - settings.WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subSettings => // Subdirectory settings - subSettings.WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(10) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.ImageSubdirectoryPrefix = "IMG_"; - }) - .WithSubdirectoryDigitPadding(5)) - .WithVolumeSettings(volumeSettings => // Volume settings - volumeSettings.WithVolumePrefix("VOL_SEARCH_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5)) - .WithLoadFileSettings(loadFileSettings => // Loadfile settings - loadFileSettings.WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO) - .WithDelimiterSettings(delimiterSettings => // Delimiter settings - delimiterSettings.WithDefaultDelimiters()))); - - // Build settings from builder - var jobSettings = settingsBuilder.Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } -} +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(7, nameof(Export_FromSavedSearch_Images), "Exports images from saved search")] + public async Task Export_FromSavedSearch_Images() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your saved search ID. + int savedSearchID = 1042325; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_Images)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Saved Search ID", savedSearchID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + var settingsBuilder = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(exportSourceSettings => // Export Source Settings + exportSourceSettings.FromSavedSearch(exportSourceArtifactID: savedSearchID) + .WithDefaultStartAtDocumentNumber()) + .WithExportArtifactSettings(artifactSettings => // Artifact Settings + artifactSettings.WithCustomPatternBuilder('_') + .AppendIdentifier() + .AppendCustomText("CustomPatternText") + .AppendOriginalFileName() + .BuildPattern() // Ends building the file pattern and applies it to the resulting object + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings.WithImagePrecedenceArtifactIDs(new List { -1 }) // exports only images + .WithTypeOfImage(ImageType.Pdf)) + .WithoutExportingFullText() + .WithoutExportingNative() + .WithoutExportingPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .ExportMultiChoicesAsNested()) + .WithExportOutputSettings(settings => // Export output settings + settings.WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subSettings => // Subdirectory settings + subSettings.WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(10) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.ImageSubdirectoryPrefix = "IMG_"; + }) + .WithSubdirectoryDigitPadding(5)) + .WithVolumeSettings(volumeSettings => // Volume settings + volumeSettings.WithVolumePrefix("VOL_SEARCH_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5)) + .WithLoadFileSettings(loadFileSettings => // Loadfile settings + loadFileSettings.WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO) + .WithDelimiterSettings(delimiterSettings => // Delimiter settings + delimiterSettings.WithDefaultDelimiters()))); + + // Build settings from builder + var jobSettings = settingsBuilder.Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } +} diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_NativeFiles.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_NativeFiles.cs index 263f608..a783b8f 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_NativeFiles.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_NativeFiles.cs @@ -1,179 +1,180 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(6, nameof(Export_FromSavedSearch_NativeFiles), "Exports native files from saved search")] - public async Task Export_FromSavedSearch_NativeFiles() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your saved search ID. - int savedSearchID = 1042325; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_NativeFiles)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Saved Search ID", savedSearchID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromSavedSearch(exportSourceArtifactID: savedSearchID) - .WithDefaultStartAtDocumentNumber() - .Build(); - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithCustomPatternBuilder('_') // Initializes the pattern builder - .AppendIdentifier() - .AppendCustomText("CustomPatternText") - .AppendOriginalFileName() - .BuildPattern() // Ends building the file pattern and applies it to the resulting object - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .WithoutExportingFullText() - .ExportNative(settings => settings.WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports only native files - .WithoutExportingPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.NativeSubdirectoryPrefix = "Native_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_SEARCH_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } -} +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(6, nameof(Export_FromSavedSearch_NativeFiles), "Exports native files from saved search")] + public async Task Export_FromSavedSearch_NativeFiles() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your saved search ID. + int savedSearchID = 1042325; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_NativeFiles)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Saved Search ID", savedSearchID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromSavedSearch(exportSourceArtifactID: savedSearchID) + .WithDefaultStartAtDocumentNumber() + .Build(); + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithCustomPatternBuilder('_') // Initializes the pattern builder + .AppendIdentifier() + .AppendCustomText("CustomPatternText") + .AppendOriginalFileName() + .BuildPattern() // Ends building the file pattern and applies it to the resulting object + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .WithoutExportingFullText() + .ExportNative(settings => settings.WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports only native files + .WithoutExportingPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.NativeSubdirectoryPrefix = "Native_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_SEARCH_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } +} diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_PDF.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_PDF.cs index 49a70d6..97dd961 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_PDF.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_PDF.cs @@ -1,155 +1,156 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(8, nameof(Export_FromSavedSearch_PDF), "Exports PDF files from saved search")] - public async Task Export_FromSavedSearch_PDF() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Your saved search ID. - int savedSearchID = 1042325; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_PDF)}"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"Saved Search ID", savedSearchID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // This represents alternative approach of using export SDK builders - var settingsBuilder = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(exportSourceSettings => // Export Source Settings - exportSourceSettings.FromSavedSearch(exportSourceArtifactID: savedSearchID) - .WithDefaultStartAtDocumentNumber()) - .WithExportArtifactSettings(artifactSettings => // Artifact Settings - artifactSettings.WithCustomPatternBuilder('_') - .AppendIdentifier() - .AppendCustomText("CustomPatternText") - .AppendOriginalFileName() - .BuildPattern() // Ends building the file pattern and applies it to the resulting object - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .WithoutExportingFullText() - .WithoutExportingNative() - .ExportPdf() - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .ExportMultiChoicesAsNested()) - .WithExportOutputSettings(settings => // Export output settings - settings.WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subSettings => // Subdirectory settings - subSettings.WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(10) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - prefixes.ImageSubdirectoryPrefix = "PDF_FILES_"; - }) - .WithSubdirectoryDigitPadding(5)) - .WithVolumeSettings(volumeSettings => // Volume settings - volumeSettings.WithVolumePrefix("VOL_SEARCH_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5)) - .WithLoadFileSettings(loadFileSettings => // Loadfile settings - loadFileSettings.WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO) - .WithDelimiterSettings(delimiterSettings => // Delimiter settings - delimiterSettings.WithDefaultDelimiters()))); - - // Build settings from builder - var jobSettings = settingsBuilder.Build(); - - // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - _logger.PrintJobJson(jobSettings); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - - // Start export job - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return; - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - _logger.PrintExportJobResult(resultData, jobResult.Value); - } -} +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(8, nameof(Export_FromSavedSearch_PDF), "Exports PDF files from saved search")] + public async Task Export_FromSavedSearch_PDF() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Your saved search ID. + int savedSearchID = 1042325; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = $"Sample-Job-{nameof(Export_FromSavedSearch_PDF)}"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"Saved Search ID", savedSearchID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // This represents alternative approach of using export SDK builders + var settingsBuilder = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(exportSourceSettings => // Export Source Settings + exportSourceSettings.FromSavedSearch(exportSourceArtifactID: savedSearchID) + .WithDefaultStartAtDocumentNumber()) + .WithExportArtifactSettings(artifactSettings => // Artifact Settings + artifactSettings.WithCustomPatternBuilder('_') + .AppendIdentifier() + .AppendCustomText("CustomPatternText") + .AppendOriginalFileName() + .BuildPattern() // Ends building the file pattern and applies it to the resulting object + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .WithoutExportingFullText() + .WithoutExportingNative() + .ExportPdf() + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .ExportMultiChoicesAsNested()) + .WithExportOutputSettings(settings => // Export output settings + settings.WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subSettings => // Subdirectory settings + subSettings.WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(10) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + prefixes.ImageSubdirectoryPrefix = "PDF_FILES_"; + }) + .WithSubdirectoryDigitPadding(5)) + .WithVolumeSettings(volumeSettings => // Volume settings + volumeSettings.WithVolumePrefix("VOL_SEARCH_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5)) + .WithLoadFileSettings(loadFileSettings => // Loadfile settings + loadFileSettings.WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO) + .WithDelimiterSettings(delimiterSettings => // Delimiter settings + delimiterSettings.WithDefaultDelimiters()))); + + // Build settings from builder + var jobSettings = settingsBuilder.Build(); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + _logger.PrintJobJson(jobSettings); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + + // Start export job + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return; + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + _logger.PrintExportJobResult(resultData, jobResult.Value); + } +} diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Cancel.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Cancel.cs index f187d76..7ec3925 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Cancel.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Cancel.cs @@ -1,176 +1,177 @@ -using System.Collections.Concurrent; -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(20, nameof(Job_Cancel), "Cancels running export job")] - public async Task Job_Cancel() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Job GUID - Guid jobID = Guid.NewGuid(); - - // Create job manager from service factory - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - // Create and run the job to cancel - await ListSample_CreateJobAsync(jobManager, workspaceID, jobID); - _logger.LogInformation("Job created"); - - // Job must be running to be canceled - await jobManager.StartAsync(workspaceID, jobID); - _logger.LogInformation($"Job with {jobID} ID started"); - - // Cancel the job - var result = await jobManager.CancelAsync(workspaceID, jobID); - _logger.LogInformation($"Job with {jobID} ID canceled"); - - OutputHelper.UpdateStatus("Fetching resulting state"); - var jobResult = await jobManager.GetAsync(workspaceID, jobID); - - string resultData = $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}"; - - _logger.LogInformation(resultData); - } - - private async Task ListSample_CreateJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, Guid jobID) - { - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = "Sample-Job-0001"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithSubfolders() // include subfolders - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .WithoutExportingImages() - .WithoutExportingFullText() - .WithoutExportingNative() - .ExportPdf() // Export PDF files - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - } +using System.Collections.Concurrent; +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(20, nameof(Job_Cancel), "Cancels running export job")] + public async Task Job_Cancel() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Job GUID + Guid jobID = Guid.NewGuid(); + + // Create job manager from service factory + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + // Create and run the job to cancel + await ListSample_CreateJobAsync(jobManager, workspaceID, jobID); + _logger.LogInformation("Job created"); + + // Job must be running to be canceled + await jobManager.StartAsync(workspaceID, jobID); + _logger.LogInformation($"Job with {jobID} ID started"); + + // Cancel the job + var result = await jobManager.CancelAsync(workspaceID, jobID); + _logger.LogInformation($"Job with {jobID} ID canceled"); + + OutputHelper.UpdateStatus("Fetching resulting state"); + var jobResult = await jobManager.GetAsync(workspaceID, jobID); + + string resultData = $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}"; + + _logger.LogInformation(resultData); + } + + private async Task ListSample_CreateJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, Guid jobID) + { + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = "Sample-Job-0001"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithSubfolders() // include subfolders + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .WithoutExportingImages() + .WithoutExportingFullText() + .WithoutExportingNative() + .ExportPdf() // Export PDF files + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Delete_Files.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Delete_Files.cs index d5de818..4ae9e8b 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Delete_Files.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Delete_Files.cs @@ -1,56 +1,56 @@ -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(22, nameof(Job_Delete_Files), "Deletes exported files of specified export job")] - public async Task Job_Delete_Files() - { - // Your workspace ID. - int workspaceID = 1020245; - - // Job GUID - Guid jobId = Guid.Parse("00000000-0000-0000-0000-000000000000"); - - // Create job manager from service factory - using IExportJobManager jobManager = _serviceFactory.CreateProxy(); - - _logger.LogInformation("Job details before deleting files:"); - await PrintJobDetailsAsync(jobManager, workspaceID, jobId); - - // Delete files of the export job - OutputHelper.UpdateStatus("Deleting files of the export job"); - var result = await jobManager.DeleteAsync(workspaceID, jobId); - - _logger.LogInformation("Job details after deleting files:"); - await PrintJobDetailsAsync(jobManager, workspaceID, jobId); - - if (result.IsSuccess) - { - _logger.LogInformation("Files deleted successfully"); - } - else - { - string errorMessage = $"<{result.ErrorCode}> {result.ErrorMessage}"; - _logger.LogError($"Failed to delete files\n{errorMessage}"); - } - } - - private async Task PrintJobDetailsAsync(IExportJobManager jobManager, int workspaceID, Guid jobId) - { - OutputHelper.UpdateStatus("Fetching job details"); - var job = (await jobManager.GetAsync(workspaceID, jobId)).Value; - - string jobDataString = $"Job ID: {job.ID}\n" - + $"Application Name: {job.ApplicationName}\n" - + $"Job Status: [aquamarine1]{job.JobStatus}[/]\n" - + $"Output URL: [orange1]{job.ExportJobOutput.OutputUrl ?? ""}[/]\n" - + $"Is output deleted: [orange1]{job.IsOutputDeleted}[/]\n"; - - _logger.PrintExportJobResult(jobDataString, job); - - OutputHelper.ClearStatus(); - } +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(22, nameof(Job_Delete_Files), "Deletes exported files of specified export job")] + public async Task Job_Delete_Files() + { + // Your workspace ID. + int workspaceID = 1020245; + + // Job GUID + Guid jobId = Guid.Parse("00000000-0000-0000-0000-000000000000"); + + // Create job manager from service factory + using IExportJobManager jobManager = _serviceFactory.CreateProxy(); + + _logger.LogInformation("Job details before deleting files:"); + await PrintJobDetailsAsync(jobManager, workspaceID, jobId); + + // Delete files of the export job + OutputHelper.UpdateStatus("Deleting files of the export job"); + var result = await jobManager.DeleteAsync(workspaceID, jobId); + + _logger.LogInformation("Job details after deleting files:"); + await PrintJobDetailsAsync(jobManager, workspaceID, jobId); + + if (result.IsSuccess) + { + _logger.LogInformation("Files deleted successfully"); + } + else + { + string errorMessage = $"<{result.ErrorCode}> {result.ErrorMessage}"; + _logger.LogError($"Failed to delete files\n{errorMessage}"); + } + } + + private async Task PrintJobDetailsAsync(IExportJobManager jobManager, int workspaceID, Guid jobId) + { + OutputHelper.UpdateStatus("Fetching job details"); + var job = (await jobManager.GetAsync(workspaceID, jobId)).Value; + + string jobDataString = $"Job ID: {job.ID}\n" + + $"Application Name: {job.ApplicationName}\n" + + $"Job Status: [aquamarine1]{job.JobStatus}[/]\n" + + $"Output URL: [orange1]{job.ExportJobOutput.OutputUrl ?? ""}[/]\n" + + $"Is output deleted: [orange1]{job.IsOutputDeleted}[/]\n"; + + _logger.PrintExportJobResult(jobDataString, job); + + OutputHelper.ClearStatus(); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_GetSettings.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_GetSettings.cs index 7bb25fb..159df60 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_GetSettings.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_GetSettings.cs @@ -1,182 +1,183 @@ -using System.Collections.Concurrent; -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(19, nameof(Job_GetSettings), "Gets settings of a selected job")] - public async Task Job_GetSettings() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Guid of the job you want to fetch settings of - Guid jobID = Guid.NewGuid(); - - OutputHelper.UpdateStatus("Preparing job..."); - - // Create job manager from service factory - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - // Create a sample job to fetch settings from - await GetSettingsSample_CreateJobAsync(jobManager, workspaceID, jobID); - - // Get settings of the job - OutputHelper.UpdateStatus("Fetching job settings..."); - var settings = await jobManager.GetSettingsAsync(workspaceID, jobID); - - _logger.PrintJobJson(settings.Value, true); - } - - private async Task GetSettingsSample_CreateJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, Guid jobID) - { - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = "Sample-Job-0001"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithSubfolders() // include subfolders - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings - .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images - .WithTypeOfImage(ImageType.Pdf)) - .ExportFullText(settings => settings - .ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) - .ExportNative(settings => settings - .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files - .ExportPdf() // Export PDF files - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - // Optional overrides - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - prefixes.NativeSubdirectoryPrefix = "NATIVE_"; - prefixes.ImageSubdirectoryPrefix = "IMAGE_"; - prefixes.PdfSubdirectoryPrefix = "PDF_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - } +using System.Collections.Concurrent; +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(19, nameof(Job_GetSettings), "Gets settings of a selected job")] + public async Task Job_GetSettings() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Guid of the job you want to fetch settings of + Guid jobID = Guid.NewGuid(); + + OutputHelper.UpdateStatus("Preparing job..."); + + // Create job manager from service factory + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + // Create a sample job to fetch settings from + await GetSettingsSample_CreateJobAsync(jobManager, workspaceID, jobID); + + // Get settings of the job + OutputHelper.UpdateStatus("Fetching job settings..."); + var settings = await jobManager.GetSettingsAsync(workspaceID, jobID); + + _logger.PrintJobJson(settings.Value, true); + } + + private async Task GetSettingsSample_CreateJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, Guid jobID) + { + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = "Sample-Job-0001"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithSubfolders() // include subfolders + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings + .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images + .WithTypeOfImage(ImageType.Pdf)) + .ExportFullText(settings => settings + .ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) + .ExportNative(settings => settings + .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files + .ExportPdf() // Export PDF files + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + // Optional overrides + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + prefixes.NativeSubdirectoryPrefix = "NATIVE_"; + prefixes.ImageSubdirectoryPrefix = "IMAGE_"; + prefixes.PdfSubdirectoryPrefix = "PDF_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_List.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_List.cs index 128d31e..a0deeaf 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_List.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_List.cs @@ -1,208 +1,209 @@ -using System.Collections.Concurrent; -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public partial class BaseExportService -{ - [SampleMetadata(17, nameof(Job_ListExportJobs), "Lists export jobs")] - public async Task Job_ListExportJobs() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Switch to false if you don't want to create jobs for this sample - bool createJobs = false; - - // Create job manager from service factory - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - if (createJobs) - { - // Create example jobs - Task[] jobsCreationTasks = new Task[4]; - for (int i = 0; i < jobsCreationTasks.Length; i++) - { - OutputHelper.UpdateStatus("Creating new jobs"); - - int localScope = i; - jobsCreationTasks[localScope] = Task.Run(async () => - { - await ListSample_CreateJobAsync(jobManager, workspaceID, localScope); - }); - } - - // Await for all jobs to be created but not started - await Task.WhenAll(jobsCreationTasks); - } - - // Get list of the existing export jobs - OutputHelper.UpdateStatus("Fetching export jobs list"); - var result = await jobManager.ListAsync(workspaceID, 0, 10); - List exportJobs = result.Value.Jobs; - - _logger.LogInformation("Export jobs list:"); - foreach (var job in exportJobs) - { - string jobDataString = $"Job ID: {job.ID}\n" - + $"Application Name: {job.ApplicationName}\n" - + $"Job Status: [aquamarine1]{job.JobStatus}[/]\n" - + $"Output URL: [orange1]{job.ExportJobOutput.OutputUrl ?? ""}[/]\n" - + $"Is output deleted: [orange1]{job.IsOutputDeleted}[/]\n"; - - _logger.PrintExportJobResult(jobDataString, job); - } - } - - private async Task ListSample_CreateJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, int iteration) - { - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = "Sample-Job-0001"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithSubfolders() // include subfolders - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings - .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images - .WithTypeOfImage(ImageType.Pdf)) - .ExportFullText(settings => settings - .ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) - .ExportNative(settings => settings - .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files - .ExportPdf() // Export PDF files - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - // Optional overrides - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - prefixes.NativeSubdirectoryPrefix = "NATIVE_"; - prefixes.ImageSubdirectoryPrefix = "IMAGE_"; - prefixes.PdfSubdirectoryPrefix = "PDF_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - } +using System.Collections.Concurrent; +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public partial class BaseExportService +{ + [SampleMetadata(17, nameof(Job_ListExportJobs), "Lists export jobs")] + public async Task Job_ListExportJobs() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Switch to false if you don't want to create jobs for this sample + bool createJobs = false; + + // Create job manager from service factory + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + if (createJobs) + { + // Create example jobs + Task[] jobsCreationTasks = new Task[4]; + for (int i = 0; i < jobsCreationTasks.Length; i++) + { + OutputHelper.UpdateStatus("Creating new jobs"); + + int localScope = i; + jobsCreationTasks[localScope] = Task.Run(async () => + { + await ListSample_CreateJobAsync(jobManager, workspaceID, localScope); + }); + } + + // Await for all jobs to be created but not started + await Task.WhenAll(jobsCreationTasks); + } + + // Get list of the existing export jobs + OutputHelper.UpdateStatus("Fetching export jobs list"); + var result = await jobManager.ListAsync(workspaceID, 0, 10); + List exportJobs = result.Value.Jobs; + + _logger.LogInformation("Export jobs list:"); + foreach (var job in exportJobs) + { + string jobDataString = $"Job ID: {job.ID}\n" + + $"Application Name: {job.ApplicationName}\n" + + $"Job Status: [aquamarine1]{job.JobStatus}[/]\n" + + $"Output URL: [orange1]{job.ExportJobOutput.OutputUrl ?? ""}[/]\n" + + $"Is output deleted: [orange1]{job.IsOutputDeleted}[/]\n"; + + _logger.PrintExportJobResult(jobDataString, job); + } + } + + private async Task ListSample_CreateJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, int iteration) + { + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = "Sample-Job-0001"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithSubfolders() // include subfolders + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings + .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images + .WithTypeOfImage(ImageType.Pdf)) + .ExportFullText(settings => settings + .ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) + .ExportNative(settings => settings + .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files + .ExportPdf() // Export PDF files + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + // Optional overrides + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + prefixes.NativeSubdirectoryPrefix = "NATIVE_"; + prefixes.ImageSubdirectoryPrefix = "IMAGE_"; + prefixes.PdfSubdirectoryPrefix = "PDF_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + } } \ No newline at end of file diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_StartAllRunnableJobs.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_StartAllRunnableJobs.cs index 96573b2..6aeb07e 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_StartAllRunnableJobs.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_StartAllRunnableJobs.cs @@ -1,280 +1,281 @@ -using System.Collections.Concurrent; -using Relativity.Export.Samples.RelConsole.Helpers; -using Relativity.Export.V1.Builders.ExportSettings; -using Relativity.Export.V1.Model; -using Relativity.Export.V1.Model.ExportJobSettings; - -namespace Relativity.Export.Samples.RelConsole.SampleCollection; - -public record class RunnableJobResult(string ResultMessage, ExportStatus? ResultStatus); - -public partial class BaseExportService -{ - [SampleMetadata(18, nameof(Job_StartAllRunnableJobs), "Starts all runnable export jobs")] - public async Task Job_StartAllRunnableJobs() - { - // Your workspace ID. - // This is where we point to the workspace where we want to export from. - int workspaceID = 1020245; - - // Switch to false if you don't want to create jobs for this sample - bool createJobs = true; - - // Create job manager from service factory - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); - - if (createJobs) - { - // Create example jobs - Task[] jobsCreationTasks = new Task[4]; - for (int i = 0; i < jobsCreationTasks.Length; i++) - { - OutputHelper.UpdateStatus("Creating new jobs"); - - int localScope = i; - jobsCreationTasks[localScope] = Task.Run(async () => - { - await StartSample_CreateJobAsync(jobManager, workspaceID, localScope); - }); - } - - // Await for all jobs to be created but not started - await Task.WhenAll(jobsCreationTasks); - } - - // Get list of the existing export jobs - OutputHelper.UpdateStatus("Fetching export jobs list"); - var result = await jobManager.ListAsync(workspaceID, 0, 1000); - var runnableJobs = result.Value.Jobs.Where(job => job.JobStatus == ExportStatus.New).ToList(); - - _logger.LogInformation("Runnable jobs:"); - foreach (var job in runnableJobs) - { - string jobDataString = $"Job ID: {job.ID}\n" - + $"Application Name: {job.ApplicationName}\n" - + $"Job Status: [aquamarine1]{job.JobStatus}[/]"; - - _logger.LogInformation(jobDataString); - } - - // Run all jobs - var jobResults = await StartSample_StartMultipleJobsAsync(jobManager, runnableJobs, workspaceID); - - var finalMessage = string.Join("\n\n", jobResults.Select(jobResult => jobResult.ResultMessage)); - var jobsStatuses = jobResults.Select(jobResult => jobResult.ResultStatus).ToList(); - - _logger.PrintBulkExportJobResult(finalMessage, jobsStatuses); - } - - private async Task StartSample_CreateJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, int iteration) - { - // Your View ID. - // View will provide us with available data to export, requires folder to be visible there. - int viewID = 1042326; - - // Your Folder ID. - // Our targetted folder. If you want to export from the workspace root, - // the ID is different from the workspace ID. - int folderID = 1003697; - - // Job related data - Guid jobID = Guid.NewGuid(); - string? applicationName = "Export-Service-Sample-App"; - string? correlationID = "Sample-Job-0001"; - - _logger.PrintSampleData(new Dictionary - { - {"Workspace ID", workspaceID.ToString() }, - {"View ID", viewID.ToString() }, - {"Folder ID", folderID.ToString() }, - {"Artifact Type ID", "10" }, - {"Job ID", jobID.ToString() }, - {"Application Name", applicationName }, - {"Correlation ID", correlationID } - }); - - // Export source settings - var sourceSettings = ExportSourceSettingsBuilder.Create() - .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) - .WithSubfolders() // include subfolders - .WithCustomStartAtDocumentNumber(1) - .Build(); - - // Select and assign an order to long text fields that Relativity checks for text when performing an export. - // You must provide at least one long text field to use this functionality - // If there won't be a value for a field, the next field in the list will be used - // Example: - // 1003668 - Extracted Text - // 1003677 - Folder Name - // If there won't be any value for Extracted Text, Folder Name will be used - List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; - - // Artifact settings - var artifactSettings = ExportArtifactSettingsBuilder.Create() - .WithDefaultFileNamePattern() - .WithoutApplyingFileNamePatternToImages() - .ExportImages(settings => settings - .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images - .WithTypeOfImage(ImageType.Pdf)) - .ExportFullText(settings => settings - .ExportFullTextAsFile() - .WithTextFileEncoding("UTF-8") - .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) - .ExportNative(settings => settings - .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files - .ExportPdf() // Export PDF files - .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export - .WithoutExportingMultiChoicesAsNested() - .Build(); - - // Subdirectory settings - var subdirectorySettings = SubdirectorySettingsBuilder.Create() - .WithSubdirectoryStartNumber(1) - .WithMaxNumberOfFilesInDirectory(100) - .WithDefaultPrefixes() - .OverridePrefixDefaults(prefixes => - { - // Optional overrides - prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; - prefixes.NativeSubdirectoryPrefix = "NATIVE_"; - prefixes.ImageSubdirectoryPrefix = "IMAGE_"; - prefixes.PdfSubdirectoryPrefix = "PDF_"; - }) - .WithSubdirectoryDigitPadding(5) - .Build(); - - // Volume settings - var volumeSettings = VolumeSettingsBuilder.Create() - .WithVolumePrefix("VOL_FOLDER_") - .WithVolumeStartNumber(1) - .WithVolumeMaxSizeInMegabytes(100) - .WithVolumeDigitPadding(5) - .Build(); - - // Loadfile settings - var loadfileSettings = LoadFileSettingsBuilder.Create() - .WithoutExportingMsAccess() - .WithoutCustomCultureInfo() - .WithDefaultDateTimeFormat() - .WithLoadFileFormat(LoadFileFormat.CSV) - .WithEncoding("UTF-8") - .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) - .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) - .WithDelimiterSettings(delimiters => - delimiters.WithDefaultDelimiters()) - .Build(); - - // Output settings - var outputSettings = ExportOutputSettingsBuilder.Create() - .WithoutArchiveCreation() - .WithDefaultFolderStructure() - .WithoutTransferJobID() - .WithDefaultDestinationPath() - .WithSubdirectorySettings(subdirectorySettings) - .WithVolumeSettings(volumeSettings) - .WithLoadFileSettings(loadfileSettings) - .Build(); - - // Connect all settings in the Job builder - var jobSettings = ExportJobSettingsBuilder.Create() - .WithExportSourceSettings(sourceSettings) - .WithExportArtifactSettings(artifactSettings) - .WithExportOutputSettings(outputSettings) - .Build(); - - // Create export job - _logger.LogInformation("Creating job"); - var validationResult = await jobManager.CreateAsync( - workspaceID, - jobID, - jobSettings, - applicationName, - correlationID); - - if (validationResult is null) - { - _logger.LogError("Something went wrong with fetching response"); - return; - } - - // check validation result - if (!validationResult.IsSuccess) - { - _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); - - // iterate errors and print them - foreach (var validationError in validationResult.Value.ValidationErrors) - { - _logger.LogError($"{validationError.Key} - {validationError.Value}"); - } - - return; - } - - _logger.LogInformation("Job created successfully"); - } - - private async Task> StartSample_StartMultipleJobsAsync(Relativity.Export.V1.IExportJobManager jobManager, List runnableExportJobs, int workspaceID) - { - OutputHelper.UpdateStatus("Starting all runnable jobs"); - - // Start all runnable jobs - ConcurrentBag jobResults = new(); - Task[] runningJobsTasks = new Task[runnableExportJobs.Count()]; - - for (int i = 0; i < runningJobsTasks.Length; i++) - { - int localScope = i; - runningJobsTasks[localScope] = Task.Run(async () => - { - var jobResult = await StartSample_RunJobAsync(jobManager, workspaceID, runnableExportJobs[localScope].ID); - jobResults.Add(jobResult); - }); - } - - // Await for all jobs to be completed - OutputHelper.UpdateStatus("Awaiting for all jobs to be completed"); - await Task.WhenAll(runningJobsTasks); - - return jobResults.ToList(); - } - - private async Task StartSample_RunJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, Guid jobID) - { - // Start export job via job manager - _logger.LogInformation($"Stating job with <{jobID}> ID"); - var startResponse = await jobManager.StartAsync(workspaceID, jobID); - - // Check for errors that occured during job start - if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) - { - _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); - - return new RunnableJobResult($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}", null); - } - - // Get status of the job and await for the completed state - _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => - { - return await jobManager.GetAsync(workspaceID, jobID); - }, frequency: 4000); - - string resultData = - $"Export job ID: {jobResult.ExportJobID}\n" - + $"Correlation ID: {jobResult.Value.CorrelationID}\n" - + $"Job status: {jobResult.Value.JobStatus}\n" - + $"Job error count: {jobResult.Value.JobErrorsCount}\n" - + $"Total records: {jobResult.Value.TotalRecords}\n" - + $"Processed records: {jobResult.Value.ProcessedRecords}\n" - + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" - + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" - + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" - + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" - + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; - - _logger.LogInformation("Job Completed"); - - return new RunnableJobResult(resultData, jobResult.Value.JobStatus); - } +using System.Collections.Concurrent; +using Relativity.Export.Samples.RelConsole.Helpers; +using Relativity.Export.V1.Builders.ExportSettings; +using Relativity.Export.V1.Model; +using Relativity.Export.V1.Model.ExportJobSettings; + +namespace Relativity.Export.Samples.RelConsole.SampleCollection; + +public record class RunnableJobResult(string ResultMessage, ExportStatus? ResultStatus); + +public partial class BaseExportService +{ + [SampleMetadata(18, nameof(Job_StartAllRunnableJobs), "Starts all runnable export jobs")] + public async Task Job_StartAllRunnableJobs() + { + // Your workspace ID. + // This is where we point to the workspace where we want to export from. + int workspaceID = 1020245; + + // Switch to false if you don't want to create jobs for this sample + bool createJobs = true; + + // Create job manager from service factory + using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + + if (createJobs) + { + // Create example jobs + Task[] jobsCreationTasks = new Task[4]; + for (int i = 0; i < jobsCreationTasks.Length; i++) + { + OutputHelper.UpdateStatus("Creating new jobs"); + + int localScope = i; + jobsCreationTasks[localScope] = Task.Run(async () => + { + await StartSample_CreateJobAsync(jobManager, workspaceID, localScope); + }); + } + + // Await for all jobs to be created but not started + await Task.WhenAll(jobsCreationTasks); + } + + // Get list of the existing export jobs + OutputHelper.UpdateStatus("Fetching export jobs list"); + var result = await jobManager.ListAsync(workspaceID, 0, 1000); + var runnableJobs = result.Value.Jobs.Where(job => job.JobStatus == ExportStatus.New).ToList(); + + _logger.LogInformation("Runnable jobs:"); + foreach (var job in runnableJobs) + { + string jobDataString = $"Job ID: {job.ID}\n" + + $"Application Name: {job.ApplicationName}\n" + + $"Job Status: [aquamarine1]{job.JobStatus}[/]"; + + _logger.LogInformation(jobDataString); + } + + // Run all jobs + var jobResults = await StartSample_StartMultipleJobsAsync(jobManager, runnableJobs, workspaceID); + + var finalMessage = string.Join("\n\n", jobResults.Select(jobResult => jobResult.ResultMessage)); + var jobsStatuses = jobResults.Select(jobResult => jobResult.ResultStatus).ToList(); + + _logger.PrintBulkExportJobResult(finalMessage, jobsStatuses); + } + + private async Task StartSample_CreateJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, int iteration) + { + // Your View ID. + // View will provide us with available data to export, requires folder to be visible there. + int viewID = 1042326; + + // Your Folder ID. + // Our targetted folder. If you want to export from the workspace root, + // the ID is different from the workspace ID. + int folderID = 1003697; + + // Job related data + Guid jobID = Guid.NewGuid(); + string? applicationName = "Export-Service-Sample-App"; + string? correlationID = "Sample-Job-0001"; + + _logger.PrintSampleData(new Dictionary + { + {"Workspace ID", workspaceID.ToString() }, + {"View ID", viewID.ToString() }, + {"Folder ID", folderID.ToString() }, + {"Artifact Type ID", "10" }, + {"Job ID", jobID.ToString() }, + {"Application Name", applicationName }, + {"Correlation ID", correlationID } + }); + + // Export source settings + var sourceSettings = ExportSourceSettingsBuilder.Create() + .FromFolder(exportSourceArtifactID: folderID, viewID: viewID) + .WithSubfolders() // include subfolders + .WithCustomStartAtDocumentNumber(1) + .Build(); + + // Select and assign an order to long text fields that Relativity checks for text when performing an export. + // You must provide at least one long text field to use this functionality + // If there won't be a value for a field, the next field in the list will be used + // Example: + // 1003668 - Extracted Text + // 1003677 - Folder Name + // If there won't be any value for Extracted Text, Folder Name will be used + List fulltextPrecedenceFieldsArtifactIds = new() { 1003668, 1003677 }; + + // Artifact settings + var artifactSettings = ExportArtifactSettingsBuilder.Create() + .WithDefaultFileNamePattern() + .WithoutApplyingFileNamePatternToImages() + .ExportImages(settings => settings + .WithImagePrecedenceArtifactIDs(new List { -1 }) // Exports images + .WithTypeOfImage(ImageType.Pdf)) + .ExportFullText(settings => settings + .ExportFullTextAsFile() + .WithTextFileEncoding("UTF-8") + .WithPrecedenceFieldsArtifactIDs(fulltextPrecedenceFieldsArtifactIds)) + .ExportNative(settings => settings + .WithNativePrecedenceArtifactIDs(new List { -1 })) // Exports native files + .ExportPdf() // Export PDF files + .WithFieldArtifactIDs(new List { 1003676, 1003667 }) // Fields to export + .WithoutFieldAliases() + .WithoutExportingMultiChoicesAsNested() + .Build(); + + // Subdirectory settings + var subdirectorySettings = SubdirectorySettingsBuilder.Create() + .WithSubdirectoryStartNumber(1) + .WithMaxNumberOfFilesInDirectory(100) + .WithDefaultPrefixes() + .OverridePrefixDefaults(prefixes => + { + // Optional overrides + prefixes.FullTextSubdirectoryPrefix = "FULLTEXT_"; + prefixes.NativeSubdirectoryPrefix = "NATIVE_"; + prefixes.ImageSubdirectoryPrefix = "IMAGE_"; + prefixes.PdfSubdirectoryPrefix = "PDF_"; + }) + .WithSubdirectoryDigitPadding(5) + .Build(); + + // Volume settings + var volumeSettings = VolumeSettingsBuilder.Create() + .WithVolumePrefix("VOL_FOLDER_") + .WithVolumeStartNumber(1) + .WithVolumeMaxSizeInMegabytes(100) + .WithVolumeDigitPadding(5) + .Build(); + + // Loadfile settings + var loadfileSettings = LoadFileSettingsBuilder.Create() + .WithoutExportingMsAccess() + .WithoutCustomCultureInfo() + .WithDefaultDateTimeFormat() + .WithLoadFileFormat(LoadFileFormat.CSV) + .WithEncoding("UTF-8") + .WithImageLoadFileFormat(ImageLoadFileFormat.IPRO) + .WithPdfFileFormat(PdfLoadFileFormat.IPRO_FullText) + .WithDelimiterSettings(delimiters => + delimiters.WithDefaultDelimiters()) + .Build(); + + // Output settings + var outputSettings = ExportOutputSettingsBuilder.Create() + .WithoutArchiveCreation() + .WithDefaultFolderStructure() + .WithoutTransferJobID() + .WithDefaultDestinationPath() + .WithSubdirectorySettings(subdirectorySettings) + .WithVolumeSettings(volumeSettings) + .WithLoadFileSettings(loadfileSettings) + .Build(); + + // Connect all settings in the Job builder + var jobSettings = ExportJobSettingsBuilder.Create() + .WithExportSourceSettings(sourceSettings) + .WithExportArtifactSettings(artifactSettings) + .WithExportOutputSettings(outputSettings) + .Build(); + + // Create export job + _logger.LogInformation("Creating job"); + var validationResult = await jobManager.CreateAsync( + workspaceID, + jobID, + jobSettings, + applicationName, + correlationID); + + if (validationResult is null) + { + _logger.LogError("Something went wrong with fetching response"); + return; + } + + // check validation result + if (!validationResult.IsSuccess) + { + _logger.LogError($"<{validationResult.ErrorCode}> {validationResult.ErrorMessage}"); + + // iterate errors and print them + foreach (var validationError in validationResult.Value.ValidationErrors) + { + _logger.LogError($"{validationError.Key} - {validationError.Value}"); + } + + return; + } + + _logger.LogInformation("Job created successfully"); + } + + private async Task> StartSample_StartMultipleJobsAsync(Relativity.Export.V1.IExportJobManager jobManager, List runnableExportJobs, int workspaceID) + { + OutputHelper.UpdateStatus("Starting all runnable jobs"); + + // Start all runnable jobs + ConcurrentBag jobResults = new(); + Task[] runningJobsTasks = new Task[runnableExportJobs.Count()]; + + for (int i = 0; i < runningJobsTasks.Length; i++) + { + int localScope = i; + runningJobsTasks[localScope] = Task.Run(async () => + { + var jobResult = await StartSample_RunJobAsync(jobManager, workspaceID, runnableExportJobs[localScope].ID); + jobResults.Add(jobResult); + }); + } + + // Await for all jobs to be completed + OutputHelper.UpdateStatus("Awaiting for all jobs to be completed"); + await Task.WhenAll(runningJobsTasks); + + return jobResults.ToList(); + } + + private async Task StartSample_RunJobAsync(Relativity.Export.V1.IExportJobManager jobManager, int workspaceID, Guid jobID) + { + // Start export job via job manager + _logger.LogInformation($"Stating job with <{jobID}> ID"); + var startResponse = await jobManager.StartAsync(workspaceID, jobID); + + // Check for errors that occured during job start + if (!string.IsNullOrEmpty(startResponse.ErrorMessage)) + { + _logger.LogError($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}"); + + return new RunnableJobResult($"<{startResponse.ErrorCode}> {startResponse.ErrorMessage}", null); + } + + // Get status of the job and await for the completed state + _logger.LogInformation("Awaiting job status updates"); + var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + { + return await jobManager.GetAsync(workspaceID, jobID); + }, frequency: 4000); + + string resultData = + $"Export job ID: {jobResult.ExportJobID}\n" + + $"Correlation ID: {jobResult.Value.CorrelationID}\n" + + $"Job status: {jobResult.Value.JobStatus}\n" + + $"Job error count: {jobResult.Value.JobErrorsCount}\n" + + $"Total records: {jobResult.Value.TotalRecords}\n" + + $"Processed records: {jobResult.Value.ProcessedRecords}\n" + + $"Exported files count: {jobResult.Value.ExportedFilesCount}\n" + + $"Total size of exported files: {jobResult.Value.TotalSizeOfExportedFiles}\n" + + $"Records with warnings: {jobResult.Value.RecordsWithErrors}\n" + + $"Records with errors: {jobResult.Value.RecordsWithErrors}\n" + + $"Output URL: [orange1]{jobResult.Value.ExportJobOutput.OutputUrl}[/]"; + + _logger.LogInformation("Job Completed"); + + return new RunnableJobResult(resultData, jobResult.Value.JobStatus); + } } \ No newline at end of file