-
Notifications
You must be signed in to change notification settings - Fork 0
/
DownloadDirectory.cs
62 lines (54 loc) · 3 KB
/
DownloadDirectory.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
using System.Threading;
using System.Threading.Tasks;
using Relativity.Transfer.SDK.Interfaces.Paths;
using Relativity.Transfer.SDK.Samples.Core.Attributes;
using Relativity.Transfer.SDK.Samples.Core.Authentication;
using Relativity.Transfer.SDK.Samples.Core.Configuration;
using Relativity.Transfer.SDK.Samples.Core.Helpers;
using Relativity.Transfer.SDK.Samples.Core.ProgressHandler;
using Relativity.Transfer.SDK.Samples.Core.Runner;
namespace Relativity.Transfer.SDK.Samples.Repository.FullPathWorkflow;
[Sample(SampleOrder.DownloadDirectory, "Download a directory",
"The sample illustrates how to implement a directory download from a RelativityOne file share.",
typeof(DownloadDirectory),
TransferType.DownloadDirectory)]
internal class DownloadDirectory : ISample
{
private readonly IConsoleLogger _consoleLogger;
private readonly IPathExtension _pathExtension;
private readonly IRelativityAuthenticationProviderFactory _relativityAuthenticationProviderFactory;
private readonly IProgressHandlerFactory _progressHandlerFactory;
public DownloadDirectory(IConsoleLogger consoleLogger,
IPathExtension pathExtension,
IRelativityAuthenticationProviderFactory relativityAuthenticationProviderFactory,
IProgressHandlerFactory progressHandlerFactory)
{
_consoleLogger = consoleLogger;
_pathExtension = pathExtension;
_relativityAuthenticationProviderFactory = relativityAuthenticationProviderFactory;
_progressHandlerFactory = progressHandlerFactory;
}
public async Task ExecuteAsync(Configuration configuration, CancellationToken token)
{
var clientName = configuration.Common.ClientName;
var jobId = configuration.Common.JobId;
var source = string.IsNullOrWhiteSpace(configuration.DownloadDirectory.Source)
? _pathExtension.GetDefaultRemoteDirectoryPathForDownload(configuration.Common)
: new DirectoryPath(configuration.DownloadDirectory.Source);
var destination = _pathExtension.EnsureLocalDirectory(configuration.DownloadDirectory.Destination);
var authenticationProvider = _relativityAuthenticationProviderFactory.Create(configuration.Common);
var progressHandler = _progressHandlerFactory.Create();
// The builder follows the Fluent convention, and more options will be added in the future. The only required component (besides the client name)
// is the authentication provider - a provided one that utilizes an OAuth-based approach has been provided, but the custom implementation can be created.
var transferClient = TransferClientBuilder.FullPathWorkflow
.WithAuthentication(authenticationProvider)
.WithClientName(clientName)
.WithStagingExplorerContext()
.Build();
_consoleLogger.PrintCreatingTransfer(jobId, source, destination);
var result = await transferClient
.DownloadDirectoryAsync(jobId, source, destination, progressHandler, token)
.ConfigureAwait(false);
_consoleLogger.PrintTransferResult(result);
}
}