From 5098a92222b53f3c3f3bd2773ff0131df6d60ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Bo=C5=82uchowski?= Date: Tue, 18 Feb 2025 14:38:40 +0100 Subject: [PATCH 1/7] REL-1018089 Added dictionary logger && fixed selection ID for sample picker --- .../Helpers/Logger.cs | 69 +++++++++++-------- .../Helpers/OutputHelper.cs | 2 +- .../SampleCollection/BaseExportService.cs | 12 ++-- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/Relativity.Export.Samples.RelConsole/Helpers/Logger.cs b/Relativity.Export.Samples.RelConsole/Helpers/Logger.cs index 2a1d45e..7d4dcaf 100644 --- a/Relativity.Export.Samples.RelConsole/Helpers/Logger.cs +++ b/Relativity.Export.Samples.RelConsole/Helpers/Logger.cs @@ -23,31 +23,6 @@ public Logger(string[] args) _args = args; } - public void PrintJobJson(ExportJobSettings settings, bool print = false) - { - if (!_args.Contains("-json")) - { - if (!print) - return; - } - - // create JSON for preview - var serializerOptions = new JsonSerializerOptions() - { - WriteIndented = true, - }; - - var json = JsonSerializer.Serialize(settings, serializerOptions); - - var panel = new Panel(new JsonText(json)) - .RoundedBorder() - .BorderColor(Color.Orange1) - .Header("[aquamarine1]Job JSON[/]", Justify.Center); - - AnsiConsole.Write(panel); - } - - public void LogWarning(string message, bool hideTimeStamp = false) { Log(new SampleLog(LogLevel.Warning, $"[orange1]{message}[/]", hideTimeStamp)); @@ -95,7 +70,41 @@ public void Log(SampleLog log) AnsiConsole.Write(table); } + public void PrintJobJson(ExportJobSettings settings, bool print = false) + { + if (!_args.Contains("-json")) + { + if (!print) + return; + } + + // create JSON for preview + var serializerOptions = new JsonSerializerOptions() + { + WriteIndented = true, + }; + + var json = JsonSerializer.Serialize(settings, serializerOptions); + + var panel = new Panel(new JsonText(json)) + .RoundedBorder() + .BorderColor(Color.Orange1) + .Header("[aquamarine1]Job JSON[/]", Justify.Center); + + AnsiConsole.Write(panel); + } + + public void PrintAliases(Dictionary data) + { + PrintDictionaryData(data, "Field Aliases"); + } + public void PrintSampleData(Dictionary data) + { + PrintDictionaryData(data, "Sample Data"); + } + + public void PrintDictionaryData(Dictionary data, string header) where K : notnull { var dataGrid = new Grid() .AddColumn(new GridColumn().NoWrap()) @@ -103,17 +112,17 @@ public void PrintSampleData(Dictionary data) foreach (var record in data) { - dataGrid.AddRow(new Markup[] - { + dataGrid.AddRow( + [ new Markup($"[orange1]{record.Key}[/]"), - new Markup(record.Value) - }); + new Markup(record.Value?.ToString() ?? "#null") + ]); } var sampleData = new Panel(dataGrid) .RoundedBorder() .BorderColor(Color.Orange1) - .Header("[aquamarine1]Sample Data[/]", Justify.Center); + .Header($"[aquamarine1]{header}[/]", Justify.Center); AnsiConsole.Write(sampleData); } diff --git a/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs b/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs index 37fa397..aeda1b2 100644 --- a/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs +++ b/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs @@ -45,7 +45,7 @@ public static async Task StartAsync(string[] args, string relativityUrl, string { BaseExportService instance = new(relativityUrl, relativityUsername, relativityPassword, args); - var runnableSample = _sampleRunner[selectedSampleId]; + var runnableSample = _sampleRunner[selectedSampleId - 1]; await AnsiConsole.Status() .StartAsync("Thinking...", async ctx => diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/BaseExportService.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/BaseExportService.cs index f806529..6337591 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/BaseExportService.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/BaseExportService.cs @@ -16,19 +16,19 @@ public partial class BaseExportService public BaseExportService(string host, string username, string password, string[] args = default!) { - this._host = host; - this._username = username; - this._password = password; + _host = host; + _username = username; + _password = password; - this._serviceFactory = this.GetServiceFactory(); + _serviceFactory = 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); + Uri relativityRestUri = new Uri($"{_host}relativity.rest/api"); + Credentials credentials = new UsernamePasswordCredentials(_username, _password); ServiceFactorySettings settings = new ServiceFactorySettings(relativityRestUri, credentials); From 9d7ad545dd4b4f827a17615ec4740a1cc5bb4938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Bo=C5=82uchowski?= Date: Tue, 18 Feb 2025 14:39:32 +0100 Subject: [PATCH 2/7] REL-1018089 Nuget bump && Cleaning --- .../Relativity.Export.Samples.RelConsole.csproj | 8 ++++---- .../SampleCollection/Export_Folder_All.cs | 4 ++-- .../Export_Folder_All_With_DataSource_Name_In_Loadfile.cs | 4 ++-- .../SampleCollection/Export_Folder_FullText.cs | 4 ++-- .../SampleCollection/Export_Folder_Images.cs | 4 ++-- .../SampleCollection/Export_Folder_NativeFiles.cs | 4 ++-- .../SampleCollection/Export_Folder_PDF.cs | 4 ++-- .../SampleCollection/Export_Production_All.cs | 4 ++-- .../SampleCollection/Export_Production_FullText.cs | 4 ++-- .../SampleCollection/Export_Production_Images.cs | 4 ++-- .../SampleCollection/Export_Production_NativeFiles.cs | 4 ++-- .../SampleCollection/Export_Production_PDF.cs | 4 ++-- .../SampleCollection/Export_RDO.cs | 4 ++-- .../SampleCollection/Export_SavedSearch_All.cs | 4 ++-- .../SampleCollection/Export_SavedSearch_FullText.cs | 4 ++-- .../SampleCollection/Export_SavedSearch_Images.cs | 4 ++-- .../SampleCollection/Export_SavedSearch_NativeFiles.cs | 4 ++-- .../SampleCollection/Export_SavedSearch_PDF.cs | 4 ++-- .../SampleCollection/Job_Cancel.cs | 2 +- .../SampleCollection/Job_GetSettings.cs | 2 +- .../SampleCollection/Job_List.cs | 2 +- .../SampleCollection/Job_StartAllRunnableJobs.cs | 4 ++-- 22 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Relativity.Export.Samples.RelConsole/Relativity.Export.Samples.RelConsole.csproj b/Relativity.Export.Samples.RelConsole/Relativity.Export.Samples.RelConsole.csproj index a33d5fd..93ffc8f 100644 --- a/Relativity.Export.Samples.RelConsole/Relativity.Export.Samples.RelConsole.csproj +++ b/Relativity.Export.Samples.RelConsole/Relativity.Export.Samples.RelConsole.csproj @@ -1,4 +1,4 @@ - + Exe @@ -11,11 +11,11 @@ - - + + - + diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All.cs index d748463..fb36a0c 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All.cs @@ -130,7 +130,7 @@ public async Task Export_FromFolder_All() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -179,7 +179,7 @@ public async Task Export_FromFolder_All() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); 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 73c38e1..8c81b8c 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 @@ -131,7 +131,7 @@ public async Task Export_FromFolder_All_With_DataSource_Name_In_Loadfile() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -180,7 +180,7 @@ public async Task Export_FromFolder_All_With_DataSource_Name_In_Loadfile() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_FullText.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_FullText.cs index b1407a9..1a6c46b 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_FullText.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_FullText.cs @@ -120,7 +120,7 @@ public async Task Export_FromFolder_FullText() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -169,7 +169,7 @@ public async Task Export_FromFolder_FullText() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_Images.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_Images.cs index 6e93599..585fef8 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_Images.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_Images.cs @@ -114,7 +114,7 @@ public async Task Export_FromFolder_Images() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -163,7 +163,7 @@ public async Task Export_FromFolder_Images() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_NativeFiles.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_NativeFiles.cs index a3da40f..86f16ed 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_NativeFiles.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_NativeFiles.cs @@ -109,7 +109,7 @@ public async Task Export_FromFolder_NativeFiles() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -158,7 +158,7 @@ public async Task Export_FromFolder_NativeFiles() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_PDF.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_PDF.cs index 0e20952..38302d0 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_PDF.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_PDF.cs @@ -108,7 +108,7 @@ public async Task Export_FromFolder_PDF() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -157,7 +157,7 @@ public async Task Export_FromFolder_PDF() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_All.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_All.cs index ae0e51f..d65f255 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_All.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_All.cs @@ -134,7 +134,7 @@ public async Task Export_FromProduction_All() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -183,7 +183,7 @@ public async Task Export_FromProduction_All() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_FullText.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_FullText.cs index 2b2ebb8..5aaed44 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_FullText.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_FullText.cs @@ -114,7 +114,7 @@ public async Task Export_FromProduction_Fulltext() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -163,7 +163,7 @@ public async Task Export_FromProduction_Fulltext() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_Images.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_Images.cs index 9656bc1..e0c97a4 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_Images.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_Images.cs @@ -104,7 +104,7 @@ public async Task Export_FromProduction_Images() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -153,7 +153,7 @@ public async Task Export_FromProduction_Images() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_NativeFiles.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_NativeFiles.cs index ce7041c..bc87c6e 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_NativeFiles.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_NativeFiles.cs @@ -102,7 +102,7 @@ public async Task Export_FromProduction_NativeFiles() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -151,7 +151,7 @@ public async Task Export_FromProduction_NativeFiles() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_PDF.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_PDF.cs index 6df1947..5b93151 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_PDF.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Production_PDF.cs @@ -101,7 +101,7 @@ public async Task Export_FromProduction_PDF() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -150,7 +150,7 @@ public async Task Export_FromProduction_PDF() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_RDO.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_RDO.cs index 31c74e2..4f1a5bd 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_RDO.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_RDO.cs @@ -126,7 +126,7 @@ public async Task Export_RDO() var jobSettings = settingsBuilder.Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -175,7 +175,7 @@ public async Task Export_RDO() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_All.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_All.cs index 9b18d3e..17a93c7 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_All.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_All.cs @@ -100,7 +100,7 @@ public async Task Export_FromSavedSearch_All() var jobSettings = settingsBuilder.Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -149,7 +149,7 @@ public async Task Export_FromSavedSearch_All() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_FullText.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_FullText.cs index af856d2..347230e 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_FullText.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_FullText.cs @@ -118,7 +118,7 @@ public async Task Export_FromSavedSearch_FullText() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -167,7 +167,7 @@ public async Task Export_FromSavedSearch_FullText() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_Images.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_Images.cs index 32f323d..560ec53 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_Images.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_Images.cs @@ -84,7 +84,7 @@ public async Task Export_FromSavedSearch_Images() var jobSettings = settingsBuilder.Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -133,7 +133,7 @@ public async Task Export_FromSavedSearch_Images() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_NativeFiles.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_NativeFiles.cs index 3ed96d8..402a021 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_NativeFiles.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_NativeFiles.cs @@ -107,7 +107,7 @@ public async Task Export_FromSavedSearch_NativeFiles() .Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -156,7 +156,7 @@ public async Task Export_FromSavedSearch_NativeFiles() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_PDF.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_PDF.cs index 3014c0c..62abaae 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_PDF.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_SavedSearch_PDF.cs @@ -83,7 +83,7 @@ public async Task Export_FromSavedSearch_PDF() var jobSettings = settingsBuilder.Build(); // Create proxy to use IExportJobManager - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); _logger.PrintJobJson(jobSettings); @@ -132,7 +132,7 @@ public async Task Export_FromSavedSearch_PDF() // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Cancel.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Cancel.cs index 2c2e21c..81243b6 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Cancel.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_Cancel.cs @@ -19,7 +19,7 @@ public async Task Job_Cancel() Guid jobID = Guid.NewGuid(); // Create job manager from service factory - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); // Create and run the job to cancel await ListSample_CreateJobAsync(jobManager, workspaceID, jobID); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_GetSettings.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_GetSettings.cs index de14175..d40014b 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_GetSettings.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_GetSettings.cs @@ -19,7 +19,7 @@ public async Task Job_GetSettings() OutputHelper.UpdateStatus("Preparing job..."); // Create job manager from service factory - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); // Create a sample job to fetch settings from await GetSettingsSample_CreateJobAsync(jobManager, workspaceID, jobID); diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_List.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_List.cs index 5e129b1..c5dc4f2 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_List.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_List.cs @@ -18,7 +18,7 @@ public async Task Job_ListExportJobs() bool createJobs = false; // Create job manager from service factory - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); if (createJobs) { diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_StartAllRunnableJobs.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_StartAllRunnableJobs.cs index 97b8c98..93c45e5 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Job_StartAllRunnableJobs.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Job_StartAllRunnableJobs.cs @@ -21,7 +21,7 @@ public async Task Job_StartAllRunnableJobs() bool createJobs = true; // Create job manager from service factory - using Relativity.Export.V1.IExportJobManager jobManager = this._serviceFactory.CreateProxy(); + using Relativity.Export.V1.IExportJobManager jobManager = _serviceFactory.CreateProxy(); if (createJobs) { @@ -256,7 +256,7 @@ private async Task StartSample_RunJobAsync(Relativity.Export. // Get status of the job and await for the completed state _logger.LogInformation("Awaiting job status updates"); - var jobResult = await this.WaitForJobToBeCompletedAsync(async () => + var jobResult = await WaitForJobToBeCompletedAsync(async () => { return await jobManager.GetAsync(workspaceID, jobID); }, frequency: 4000); From cb81a7334bcc6674d3a98aaf15373ba08a6c7192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Bo=C5=82uchowski?= Date: Tue, 18 Feb 2025 14:40:03 +0100 Subject: [PATCH 3/7] REL-1018089 Added sample that uses aliases --- .../Export_Folder_All_WithAliases.cs | 213 ++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_WithAliases.cs diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_WithAliases.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_WithAliases.cs new file mode 100644 index 0000000..7f17eba --- /dev/null +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_WithAliases.cs @@ -0,0 +1,213 @@ +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(nameof(Export_FromFolder_All_WithAliases), "Exports native, fulltext, images and PDF files from folder and uses field aliases")] + public async Task Export_FromFolder_All_WithAliases() + { + // 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 }; + + // Aliases can use only artifact IDs that are in the fieldArtifactIDs list + // Key is the artifact ID of the field, value is the alias + List fieldArtifactIDs = new() { 1003676, 1003667 }; + Dictionary fieldAliases = new() + { + { 1003676, "Field1" }, + { 1003667, "Field2" } + }; + + // 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(fieldArtifactIDs) // Fields to export + .WithFieldAliases(fieldAliases) + .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(); + + _logger.PrintAliases(fieldAliases); + + // Create proxy to use IExportJobManager + using Relativity.Export.V1.IExportJobManager jobManager = _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 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 From 7073d6cc72cada8b7f548f1ea6db90890ae5d10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Bo=C5=82uchowski?= Date: Tue, 18 Feb 2025 14:44:03 +0100 Subject: [PATCH 4/7] REL-1018089 Added aliases sample for PS --- .../export-folder-all-with-aliases.ps1 | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 Relativity.Export.Samples.Powershell/SamplesCollection/export-folder-all-with-aliases.ps1 diff --git a/Relativity.Export.Samples.Powershell/SamplesCollection/export-folder-all-with-aliases.ps1 b/Relativity.Export.Samples.Powershell/SamplesCollection/export-folder-all-with-aliases.ps1 new file mode 100644 index 0000000..203286e --- /dev/null +++ b/Relativity.Export.Samples.Powershell/SamplesCollection/export-folder-all-with-aliases.ps1 @@ -0,0 +1,127 @@ +. "$global:rootDir\Helpers\EndpointsClass.ps1" +. "$global:rootDir\Helpers\WriteInformationClass.ps1" +. "$global:rootDir\Helpers\BaseExportService.ps1" + +# Your workspace ID: this is where we point to the workspace where we want to export from +[int]$workspaceId = 1022188 + +# Export settings parameters +# Your view ID: view will provide us with available data to export, requires folder to be visible there. +# Your folder ID: our targetted folder. If you want to export from the workspace root, the ID is different from the workspace ID. +# ExportSourceType: ExportFolder or ExportFolderWithSubfolders +[int]$viewId = 1003684 +[int]$folderID = 1003697 +[bool]$withSubfolders = $true + +# ArtifactIds: Example: 1003668 - Extracted Text, 1003677 - Folder Name, 1003676 - Artifact ID, 1003667 - Control Number +$fulltextPrecedenceFieldsArtifactIds = '[1003668,1003677]' + +# Aliases can use only artifact IDs that are in the fieldArtifactIDs list +# Key is the artifact ID of the field, value is the alias +$fieldArtifactIds = '[1003676,1003667]' +$aliases = '{ + "1003676": "Artifact ID - Field1", + "1003667": "Control Number - Field2" +}' + +# Job related data +$jobId = New-Guid +[string]$applicationName = "Export-Service-Sample-Powershell" +[string]$applicationId = "Sample-Job-" + $MyInvocation.MyCommand.Name.Replace(".ps1", "") +[int]$exportSourceType = if ($withSubfolders) { 3 } else { 2 } + +# Export job settings +[string]$exportJobSettings = +'{ + "settings": { + "ExportSourceSettings": { + "ArtifactTypeID":10, + "ExportSourceType":' + $exportSourceType + ', + "ExportSourceArtifactID":' + $folderID + ', + "ViewID":' + $viewId + ', + "StartAtDocumentNumber":1 + }, + "ExportArtifactSettings": { + "FileNamePattern":"{identifier}", + "ExportNative":true, + "ExportPdf":true, + "ExportImages":true, + "ExportFullText":true, + "ExportMultiChoicesAsNested":false, + "ImageExportSettings": { + "ImagePrecedenceArtifactIDs":[-1], + "TypeOfImage":2, + }, + "FullTextExportSettings": { + "ExportFullTextAsFile":true, + "TextFileEncoding":"utf-8", + "PrecedenceFieldsArtifactIDs":' + $fulltextPrecedenceFieldsArtifactIds + ' + }, + "NativeFilesExportSettings": { + "NativePrecedenceArtifactIDs":[-1] + }, + "FieldArtifactIDs":' + $fieldArtifactIds + ', + "FieldAliases":' + $aliases + ', + "ApplyFileNamePatternToImages":false + }, + "ExportOutputSettings": { + "LoadFileSettings": { + "LoadFileFormat":"CSV", + "ImageLoadFileFormat":"IPRO", + "PdfLoadFileFormat":"IPRO", + "Encoding":"utf-8", + "DelimitersSettings": { + "NestedValueDelimiter":"B", + "RecordDelimiter":"E", + "QuoteDelimiter":"D", + "NewlineDelimiter":"C", + "MultiRecordDelimiter":"A" + }, + "ExportMsAccess": false + }, + "VolumeSettings": { + "VolumePrefix":"VOL_FOLDER", + "VolumeStartNumber":"1", + "VolumeMaxSizeInMegabytes":100, + "VolumeDigitPadding":5 + }, + "SubdirectorySettings": { + "SubdirectoryStartNumber":1, + "MaxNumberOfFilesInDirectory":100, + "ImageSubdirectoryPrefix":"IMAGE_", + "NativeSubdirectoryPrefix":"NATIVE_", + "FullTextSubdirectoryPrefix":"FULLTEXT_", + "PdfSubdirectoryPrefix":"PDFS_", + "SubdirectoryDigitPadding":5 + }, + "CreateArchive":false, + "FolderStructure":0 + } + }, + "applicationName":"' + $applicationName + '", + "correlationID":"' + $applicationId + '" +}' + +# Create, run export job and display export job result +$global:Endpoints = [Endpoints]::new($workspaceId) +$global:WriteInformation = [WriteInformation]::new() +$global:BaseExportService = [BaseExportService]::new() + +Context "Exports native, fulltext, images and PDF files from folder" { + Describe "Create export job" { + $global:BaseExportService.createExportJob($jobId, $exportJobSettings) + } + + Describe "Start export job" { + $global:BaseExportService.startExportJob($jobId) + } + + Describe "Wait for export job to be completed" { + $global:BaseExportService.waitForExportJobToBeCompleted($jobId) + } + + Describe "Export job summary" { + $global:BaseExportService.exportJobResult($jobId) + } +} + From 00e07f5ee3b8d40e275a537cac9d2ddeb02dd7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Bo=C5=82uchowski?= Date: Tue, 18 Feb 2025 14:50:58 +0100 Subject: [PATCH 5/7] REL-1018089 Moved part of the logger to extensions for code clarity --- .../Helpers/Logger.cs | 42 ---------------- .../Helpers/LoggerExtensions.cs | 49 +++++++++++++++++++ 2 files changed, 49 insertions(+), 42 deletions(-) create mode 100644 Relativity.Export.Samples.RelConsole/Helpers/LoggerExtensions.cs diff --git a/Relativity.Export.Samples.RelConsole/Helpers/Logger.cs b/Relativity.Export.Samples.RelConsole/Helpers/Logger.cs index 7d4dcaf..cb0a0ba 100644 --- a/Relativity.Export.Samples.RelConsole/Helpers/Logger.cs +++ b/Relativity.Export.Samples.RelConsole/Helpers/Logger.cs @@ -94,16 +94,6 @@ public void PrintJobJson(ExportJobSettings settings, bool print = false) AnsiConsole.Write(panel); } - public void PrintAliases(Dictionary data) - { - PrintDictionaryData(data, "Field Aliases"); - } - - public void PrintSampleData(Dictionary data) - { - PrintDictionaryData(data, "Sample Data"); - } - public void PrintDictionaryData(Dictionary data, string header) where K : notnull { var dataGrid = new Grid() @@ -127,38 +117,6 @@ public void PrintDictionaryData(Dictionary data, string header) wher AnsiConsole.Write(sampleData); } - public void PrintExportJobResult(string finalMessage, ExportJob exportJob) - { - int processed = exportJob.ProcessedRecords - exportJob.RecordsWithErrors - exportJob.RecordsWithWarnings ?? 0; - - LogInformation(finalMessage, hideTimeStamp: true); - AnsiConsole.WriteLine(); - AnsiConsole.Write(new BreakdownChart() - .Width(60) - .AddItem("Processed", processed, Color.Green) - .AddItem("Records with errors", exportJob.RecordsWithErrors ?? 0, Color.Red) - .AddItem("Records with warnings", exportJob.RecordsWithWarnings ?? 0, Color.Yellow)); - AnsiConsole.WriteLine(); - } - - public void PrintBulkExportJobResult(string finalMessage, List exportStatuses) - { - int successJobs = exportStatuses.Count(s => s == ExportStatus.Completed); - int failedJobs = exportStatuses.Count(s => s == ExportStatus.Failed); - int cancelledJobs = exportStatuses.Count(s => s == ExportStatus.Cancelled); - int completedWithErrorsJobs = exportStatuses.Count(s => s == ExportStatus.CompletedWithErrors); - - LogInformation(string.IsNullOrEmpty(finalMessage) ? "Bulk export completed" : finalMessage, hideTimeStamp: true); - AnsiConsole.WriteLine(); - AnsiConsole.Write(new BreakdownChart() - .Width(60) - .AddItem("Success", successJobs, Color.Green) - .AddItem("Completed With Errors", completedWithErrorsJobs, Color.OrangeRed1) - .AddItem("Failed", failedJobs, Color.Red) - .AddItem("Cancelled", cancelledJobs, Color.Yellow)); - AnsiConsole.WriteLine(); - } - private string LevelToMessage(LogLevel logLevel) => logLevel switch { LogLevel.Information => "[bold][aquamarine1][/][/]", diff --git a/Relativity.Export.Samples.RelConsole/Helpers/LoggerExtensions.cs b/Relativity.Export.Samples.RelConsole/Helpers/LoggerExtensions.cs new file mode 100644 index 0000000..81e6de3 --- /dev/null +++ b/Relativity.Export.Samples.RelConsole/Helpers/LoggerExtensions.cs @@ -0,0 +1,49 @@ +using Relativity.Export.V1.Model; +using Spectre.Console; + +namespace Relativity.Export.Samples.RelConsole.Helpers; + +public static class LoggerExtensions +{ + public static void PrintAliases(this Logger logger, Dictionary data) + { + logger.PrintDictionaryData(data, "Field Aliases"); + } + + public static void PrintSampleData(this Logger logger, Dictionary data) + { + logger.PrintDictionaryData(data, "Sample Data"); + } + + public static void PrintExportJobResult(this Logger logger, string finalMessage, ExportJob exportJob) + { + int processed = exportJob.ProcessedRecords - exportJob.RecordsWithErrors - exportJob.RecordsWithWarnings ?? 0; + + logger.LogInformation(finalMessage, hideTimeStamp: true); + AnsiConsole.WriteLine(); + AnsiConsole.Write(new BreakdownChart() + .Width(60) + .AddItem("Processed", processed, Color.Green) + .AddItem("Records with errors", exportJob.RecordsWithErrors ?? 0, Color.Red) + .AddItem("Records with warnings", exportJob.RecordsWithWarnings ?? 0, Color.Yellow)); + AnsiConsole.WriteLine(); + } + + public static void PrintBulkExportJobResult(this Logger logger, string finalMessage, List exportStatuses) + { + int successJobs = exportStatuses.Count(s => s == ExportStatus.Completed); + int failedJobs = exportStatuses.Count(s => s == ExportStatus.Failed); + int cancelledJobs = exportStatuses.Count(s => s == ExportStatus.Cancelled); + int completedWithErrorsJobs = exportStatuses.Count(s => s == ExportStatus.CompletedWithErrors); + + logger.LogInformation(string.IsNullOrEmpty(finalMessage) ? "Bulk export completed" : finalMessage, hideTimeStamp: true); + AnsiConsole.WriteLine(); + AnsiConsole.Write(new BreakdownChart() + .Width(60) + .AddItem("Success", successJobs, Color.Green) + .AddItem("Completed With Errors", completedWithErrorsJobs, Color.OrangeRed1) + .AddItem("Failed", failedJobs, Color.Red) + .AddItem("Cancelled", cancelledJobs, Color.Yellow)); + AnsiConsole.WriteLine(); + } +} \ No newline at end of file From cf0db5d0012d86aa9926ec9032ee0e3854f7600e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Bo=C5=82uchowski?= Date: Tue, 18 Feb 2025 15:56:22 +0100 Subject: [PATCH 6/7] REL-1018089 Changed new sample name to be more consistent && Adjusted ID for sample picker --- .../Helpers/OutputHelper.cs | 30 +++++++++---------- ...s.cs => Export_Folder_All_With_Aliases.cs} | 4 +-- 2 files changed, 16 insertions(+), 18 deletions(-) rename Relativity.Export.Samples.RelConsole/SampleCollection/{Export_Folder_All_WithAliases.cs => Export_Folder_All_With_Aliases.cs} (97%) diff --git a/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs b/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs index aeda1b2..cb9ebf1 100644 --- a/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs +++ b/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs @@ -11,6 +11,7 @@ public static class OutputHelper { private static string[] _args = default!; private static Dictionary _sampleRunner = new(); + private static List _samples = new(); private static StatusContext _statusContext = default!; private static object _statusLock = new(); @@ -23,13 +24,12 @@ public static async Task StartAsync(string[] args, string relativityUrl, string int selectedSampleId = -1; bool isSampleValid = args.Length > 0 && Int32.TryParse(args[0], out selectedSampleId); - samples = GetSamples(isSampleValid ? selectedSampleId : -1); + GetSamples(isSampleValid ? selectedSampleId : -1); if (!args.Contains("-noui")) { - - var samplesPanel = GetSamplesPanel(samples); - var metadataPanel = GetSampleMetadataPanel(samples.FirstOrDefault(s => s.ID == selectedSampleId)); + var samplesPanel = GetSamplesPanel(); + var metadataPanel = GetSampleMetadataPanel(_samples.FirstOrDefault(s => s.ID == selectedSampleId)); Columns[] dataColumns = [ @@ -45,7 +45,7 @@ public static async Task StartAsync(string[] args, string relativityUrl, string { BaseExportService instance = new(relativityUrl, relativityUsername, relativityPassword, args); - var runnableSample = _sampleRunner[selectedSampleId - 1]; + var runnableSample = _sampleRunner[selectedSampleId]; await AnsiConsole.Status() .StartAsync("Thinking...", async ctx => @@ -126,9 +126,9 @@ public static void ClearStatus() } } - private static List GetSamples(int selectedSampleId) + private static void GetSamples(int selectedSampleId) { - List samples = new(); + _samples = new(); var sampleMethods = Assembly.GetExecutingAssembly() .GetTypes() .SelectMany(type => type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) @@ -155,11 +155,9 @@ private static List GetSamples(int selectedSampleId) !string.IsNullOrEmpty(data.Description) ? data.Description : "No description", sampleID == selectedSampleId); // is sample currently selected - samples.Add(sampleMetadata); - _sampleRunner.Add(i + 1, sampleMethods[i]); + _samples.Add(sampleMetadata); + _sampleRunner.Add(sampleID, sampleMethods[i]); } - - return samples; } private static Panel GetSampleMetadataPanel(SampleMetadata? sample) @@ -201,20 +199,20 @@ private static Panel GetSampleMetadataPanel(SampleMetadata? sample) return metadataPanel; } - private static Panel GetSamplesPanel(List samplesMetadata) + private static Panel GetSamplesPanel() { var samplesTable = new Table() .Expand(); samplesTable.AddColumns("ID", "Name"); - foreach (var sample in samplesMetadata.OrderBy(s => s.ID)) + foreach (var sample in _samples) { - IRenderable[] rows = new IRenderable[] - { + IRenderable[] rows = + [ new Markup(sample.ID.ToString(), new Style(sample.IsSelected ? Color.Aquamarine1 : Color.Orange1)), new Markup(sample.Name, new Style(sample.IsSelected ? Color.Aquamarine1 : Color.Orange1)) - }; + ]; samplesTable.AddRow(rows); } diff --git a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_WithAliases.cs b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_With_Aliases.cs similarity index 97% rename from Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_WithAliases.cs rename to Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_With_Aliases.cs index 7f17eba..568165b 100644 --- a/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_WithAliases.cs +++ b/Relativity.Export.Samples.RelConsole/SampleCollection/Export_Folder_All_With_Aliases.cs @@ -6,8 +6,8 @@ namespace Relativity.Export.Samples.RelConsole.SampleCollection; public partial class BaseExportService { - [SampleMetadata(nameof(Export_FromFolder_All_WithAliases), "Exports native, fulltext, images and PDF files from folder and uses field aliases")] - public async Task Export_FromFolder_All_WithAliases() + [SampleMetadata(nameof(Export_FromFolder_All_With_Aliases), "Exports native, fulltext, images and PDF files from folder and uses field aliases")] + public async Task Export_FromFolder_All_With_Aliases() { // Your workspace ID. // This is where we point to the workspace where we want to export from. From 050210d328434a17ebde396cbdc5f71e77e9fd9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Bo=C5=82uchowski?= Date: Tue, 18 Feb 2025 16:03:43 +0100 Subject: [PATCH 7/7] REL-1018089 Cleaning --- Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs b/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs index cb9ebf1..88aab60 100644 --- a/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs +++ b/Relativity.Export.Samples.RelConsole/Helpers/OutputHelper.cs @@ -20,7 +20,6 @@ public static async Task StartAsync(string[] args, string relativityUrl, string try { _args = args; - List samples; int selectedSampleId = -1; bool isSampleValid = args.Length > 0 && Int32.TryParse(args[0], out selectedSampleId);