-
Notifications
You must be signed in to change notification settings - Fork 6
/
Sample01_ImportNativeFiles.cs
135 lines (114 loc) · 5.77 KB
/
Sample01_ImportNativeFiles.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
// <copyright file="Sample01_ImportNativeFiles.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.Builders.DataSource;
using Relativity.Import.V1.Builders.Documents;
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 simple import native files.
/// </summary>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
public async Task Sample01_ImportNativeFiles()
{
Console.WriteLine($"Running {nameof(this.Sample01_ImportNativeFiles)}");
// GUID identifiers for import job and data source.
Guid importId = Guid.NewGuid();
Guid sourceId = Guid.NewGuid();
// destination workspace artifact Id.
const int workspaceId = 1000000;
// set of columns indexes in load file used in import settings.
const int controlNumberColumnIndex = 0;
const int custodianColumnIndex = 1;
const int dateSentColumnIndex = 5;
const int emailToColumnIndex = 11;
const int fileNameColumnIndex = 13;
const int filePathColumnIndex = 22;
// Path to the load file used in data source settings.
const string loadFile01Path = "\\\\files\\T001\\StructuredData\\Import\\SampleDataSources\\load_file_01.dat";
// Configuration settings for document import. Builder is used to create settings.
ImportDocumentSettings importSettings = ImportDocumentSettingsBuilder.Create()
.WithAppendMode()
.WithNatives(x => x
.WithFilePathDefinedInColumn(filePathColumnIndex)
.WithFileNameDefinedInColumn(fileNameColumnIndex))
.WithoutImages()
.WithFieldsMapped(x => x
.WithField(controlNumberColumnIndex, "Control Number")
.WithField(custodianColumnIndex, "Custodian - Single Choice")
.WithField(emailToColumnIndex, "Email To")
.WithField(dateSentColumnIndex, "Date Sent"))
.WithoutFolders();
// Configuration settings for data source. Builder is used to create settings.
DataSourceSettings dataSourceSettings = DataSourceSettingsBuilder.Create()
.ForLoadFile(loadFile01Path)
.WithDelimiters(d => d
.WithColumnDelimiters('|')
.WithQuoteDelimiter('^')
.WithNewLineDelimiter('#')
.WithNestedValueDelimiter('&')
.WithMultiValueDelimiter('$'))
.WithFirstLineContainingHeaders()
.WithEndOfLineForWindows()
.WithStartFromBeginning()
.WithDefaultEncoding()
.WithDefaultCultureInfo();
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-0001");
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.
// NOTE: You can also request job details to verify if job is finished - see appropriate sample (sample_19).
var dataSourceState = await this.WaitImportDataSourceToBeCompleted(
funcAsync: () => importSourceController.GetDetailsAsync(workspaceId, importId, sourceId),
timeout: 10000);
// Get current import progress for specific data source.
var importProgress = await importSourceController.GetProgressAsync(workspaceId, importId, sourceId);
if (importProgress.IsSuccess)
{
Console.WriteLine("\n");
Console.WriteLine($"Data source state: {dataSourceState}");
Console.WriteLine($"Import data source progress: Total records: {importProgress.Value.TotalRecords}, Imported records: {importProgress.Value.ImportedRecords}, Records with errors: {importProgress.Value.ErroredRecords}");
}
Console.WriteLine("\n");
}
}
}
}
/* Expected console result:
Data source state: Completed
Import data source progress: Total records: 4, Imported records: 4, Records with errors: 0
*/