-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathImportClientPluginFactory.cs
More file actions
99 lines (89 loc) · 2.86 KB
/
ImportClientPluginFactory.cs
File metadata and controls
99 lines (89 loc) · 2.86 KB
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
namespace Relativity.Server.DataExchange.Wrapper
{
using System;
/// <summary>
/// Represents a factory to create <see cref="IImportClient"/> instances.
/// Implements the <see cref="System.IDisposable" />
/// </summary>
/// <seealso cref="System.IDisposable" />
/// <remarks>
/// The construction of each <see cref="IImportClient"/> should be wrapped with this object to guarantee assembly isolation.
/// </remarks>
public sealed class ImportClientPluginFactory : IDisposable
{
private readonly PluginConfiguration configuration;
private ImportClientPluginSearch pluginSearch;
private bool disposed;
/// <summary>
/// Initializes a new instance of the <see cref="ImportClientPluginFactory"/> class.
/// </summary>
/// <param name="configuration">
/// The plugin configuration.
/// </param>
public ImportClientPluginFactory(PluginConfiguration configuration)
{
this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
this.pluginSearch = null;
this.disposed = false;
}
/// <summary>
/// Creates an import client that's compatible with the Relativity instance defined by <paramref name="connectionInfo"/>.
/// </summary>
/// <param name="relativityVersion">
/// The Relativity version that was retrieved by REST API.
/// </param>
/// <param name="connectionInfo">
/// The import connection information.
/// </param>
/// <param name="context">
/// The import context.
/// </param>
/// <returns>
/// The <see cref="IImportClient"/> instance.
/// </returns>
/// <remarks>
/// The async/await pattern cannot be used because none of the constructs are marked with <see cref="SerializableAttribute"/>.
/// </remarks>
/// <exception cref="NotSupportedException">Thrown when there is an attempt to create an unsupported client</exception>
public IImportClient CreateImportClient(
Version relativityVersion,
ImportConnectionInfo connectionInfo,
ImportContext context)
{
this.Initialize();
// We can add a flag here to state we'll only allow construction of one or the other, but never both
return this.pluginSearch.CreateImportClient(relativityVersion, connectionInfo, context);
}
public void Dispose()
{
Dispose(true);
}
/// <summary>
/// Ensure the plugin search object is properly initialized.
/// </summary>
private void Initialize()
{
if (this.pluginSearch != null)
{
return;
}
this.pluginSearch = new ImportClientPluginSearch();
this.pluginSearch.Initialize(configuration);
}
private void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
if (this.pluginSearch != null)
{
this.pluginSearch.Dispose();
this.pluginSearch = null;
}
}
this.disposed = true;
}
}
}
}