-
Notifications
You must be signed in to change notification settings - Fork 1
/
Export_SavedSearch_Images.cs
156 lines (135 loc) · 5.73 KB
/
Export_SavedSearch_Images.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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(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<string, string>
{
{"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<int> { -1 }) // exports only images
.WithTypeOfImage(ImageType.Pdf))
.WithoutExportingFullText()
.WithoutExportingNative()
.WithoutExportingPdf()
.WithFieldArtifactIDs(new List<int> { 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<Relativity.Export.V1.IExportJobManager>();
_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.OutputUrl}[/]";
_logger.LogInformation("Job Completed");
_logger.PrintExportJobResult(resultData, jobResult);
}
}