-
Notifications
You must be signed in to change notification settings - Fork 6
/
Sample07_DirectImportSettingsForDocuments.cs
174 lines (154 loc) · 6.42 KB
/
Sample07_DirectImportSettingsForDocuments.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// <copyright file="Sample07_DirectImportSettingsForDocuments.cs" company="Relativity ODA LLC">
// © Relativity All Rights Reserved.
// </copyright>
namespace Relativity.Import.Samples.DotNetFrameworkClient.SamplesCollection
{
using System;
using System.Threading.Tasks;
using Relativity.Import.Samples.DotNetFrameworkClient.ImportSampleHelpers;
using Relativity.Import.V1;
using Relativity.Import.V1.Models.Settings;
using Relativity.Import.V1.Models.Sources;
/// <summary>
/// Class containing examples of using import service SDK.
/// </summary>
public partial class ImportServiceSample
{
/// <summary>
/// Example of setting ImportDocumentSetting manually - without ImportDocumentSettingsBuilder.
/// Settings to be used to import images.
/// </summary>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
public async Task Sample07_DirectImportSettingsForDocuments()
{
Console.WriteLine($"Running {nameof(this.Sample07_DirectImportSettingsForDocuments)}");
// GUID identifiers for import job and data source.
Guid importId = Guid.NewGuid();
Guid sourceId = Guid.NewGuid();
// destination workspace and folder artifact Ids.
const int workspaceId = 1000000;
const int rootFolderId = 2000000;
// overlay keyField
const string keyField = "Control Number";
// set of columns indexes in load file used in import settings.
const int extractedTextFilePathColumnIndex = 12;
const int emailToColumnIndex = 11;
const int fileNameColumnIndex = 13;
const int fileSizeColumnIndex = 14;
const int filePathColumnIndex = 22;
// Configuration settings for document import. Example of set without using ImportDocumentSettingsBuilder.
ImportDocumentSettings importSettings = new ImportDocumentSettings()
{
Overlay = new OverlaySettings
{
Mode = OverlayMode.AppendOverlay,
KeyField = keyField,
MultiFieldOverlayBehaviour = MultiFieldOverlayBehaviour.UseRelativityDefaults,
},
Native = new NativeSettings
{
FileNameColumnIndex = fileNameColumnIndex,
FilePathColumnIndex = filePathColumnIndex,
},
Fields = new FieldsSettings
{
FieldMappings = new[]
{
new FieldMapping
{
Field = "Control Number",
ContainsID = false,
ColumnIndex = 0,
ContainsFilePath = false,
},
new FieldMapping
{
Field = "Custodian - Single Choice",
ContainsID = false,
ColumnIndex = 1,
ContainsFilePath = false,
},
new FieldMapping
{
Field = "Email To",
ContainsID = false,
ColumnIndex = emailToColumnIndex,
ContainsFilePath = false,
},
new FieldMapping
{
Field = "Extracted Text",
ContainsID = false,
ColumnIndex = extractedTextFilePathColumnIndex,
ContainsFilePath = true,
Encoding = "UTF-8",
FileSizeColumnIndex = fileSizeColumnIndex,
},
},
},
Folder = new FolderSettings
{
FolderPathColumnIndex = null,
RootFolderID = rootFolderId,
},
};
// Example of data source configuration created without using DataSourceSettingsBuilder.
DataSourceSettings dataSourceSettings = new DataSourceSettings
{
Type = DataSourceType.LoadFile,
Path = "\\files\\T001\\Files\\SampleDataSources\\load_file_04.dat",
NewLineDelimiter = '#',
ColumnDelimiter = '|',
QuoteDelimiter = '^',
MultiValueDelimiter = '$',
NestedValueDelimiter = '&',
Encoding = null,
CultureInfo = "en-us",
EndOfLine = DataSourceEndOfLine.Windows,
FirstLineContainsColumnNames = true,
StartLine = 0,
};
using (Relativity.Import.V1.Services.IDocumentConfigurationController documentConfiguration =
this.serviceFactory.CreateProxy<Relativity.Import.V1.Services.IDocumentConfigurationController>())
using (Relativity.Import.V1.Services.IImportJobController importJobController =
this.serviceFactory.CreateProxy<Relativity.Import.V1.Services.IImportJobController>())
using (Relativity.Import.V1.Services.IImportSourceController importSourceController =
this.serviceFactory.CreateProxy<Relativity.Import.V1.Services.IImportSourceController>())
{
// Create import job.
Response response = await importJobController.CreateAsync(
importJobID: importId,
workspaceID: workspaceId,
applicationName: "Import-service-sample-app",
correlationID: "Sample-job-0007");
ResponseHelper.EnsureSuccessResponse(response, "IImportJobController.CreateAsync");
// Add import document settings to existing import job.
response = await documentConfiguration.CreateAsync(workspaceId, importId, importSettings);
ResponseHelper.EnsureSuccessResponse(response, "IDocumentConfigurationController.CreateAsync");
// Add data source settings to existing import job.
response = await importSourceController.AddSourceAsync(workspaceId, importId, sourceId, dataSourceSettings);
ResponseHelper.EnsureSuccessResponse(response, "IImportSourceController.AddSourceAsync");
// Start import job.
response = await importJobController.BeginAsync(workspaceId, importId);
ResponseHelper.EnsureSuccessResponse(response, "IImportJobController.BeginAsync");
// End import job.
await importJobController.EndAsync(workspaceId, importId);
ResponseHelper.EnsureSuccessResponse(response, "IImportJobController.EndAsync");
// It may take some time for import job to be completed. Request data source details to monitor the current state.
var dataSourceState = await this.WaitImportDataSourceToBeCompleted(
funcAsync: () => importSourceController.GetDetailsAsync(workspaceId, importId, sourceId),
timeout: 10000);
// Get current import progress.
var importProgress = await importJobController.GetProgressAsync(workspaceId, importId);
if (importProgress.IsSuccess)
{
Console.WriteLine($"\nData source state: {dataSourceState}");
Console.WriteLine($"Import progress: Total records: {importProgress.Value.TotalRecords}, Imported records: {importProgress.Value.ImportedRecords}, Records with errors: {importProgress.Value.ErroredRecords}");
}
}
}
}
}
// Expected console output:
// Data source state: Completed
// Import progress: Total records: 2, Imported records: 2, Records with errors: 0