-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
LocalFilesStorageResourceProvider.cs
71 lines (63 loc) · 2.52 KB
/
LocalFilesStorageResourceProvider.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core;
namespace Azure.Storage.DataMovement
{
/// <summary>
/// Provider for a <see cref="StorageResource"/> configured for the local filesystem.
/// </summary>
public class LocalFilesStorageResourceProvider : StorageResourceProvider
{
/// <inheritdoc/>
protected internal override string ProviderId => "local";
/// <summary>
/// Default constructor.
/// </summary>
public LocalFilesStorageResourceProvider()
{
}
/// <inheritdoc/>
protected internal override Task<StorageResource> FromSourceAsync(DataTransferProperties properties, CancellationToken cancellationToken)
=> Task.FromResult(FromTransferProperties(properties, getSource: true));
/// <inheritdoc/>
protected internal override Task<StorageResource> FromDestinationAsync(DataTransferProperties properties, CancellationToken cancellationToken)
=> Task.FromResult(FromTransferProperties(properties, getSource: false));
private StorageResource FromTransferProperties(DataTransferProperties properties, bool getSource)
{
Argument.AssertNotNull(properties, nameof(properties));
Uri storedUri = getSource ? properties.SourceUri : properties.DestinationUri;
return properties.IsContainer
? new LocalDirectoryStorageResourceContainer(storedUri)
: new LocalFileStorageResource(storedUri);
}
/// <summary>
/// Creates a storage resource to the file at the given path.
/// </summary>
/// <param name="filePath">
/// Path to the file.
/// </param>
/// <returns>
/// Storage resource to this file.
/// </returns>
public StorageResourceItem FromFile(string filePath)
{
return new LocalFileStorageResource(filePath);
}
/// <summary>
/// Creates a storage resource to the directory at the given path.
/// </summary>
/// <param name="directoryPath">
/// Path to the directory.
/// </param>
/// <returns>
/// Storage resource to this directory.
/// </returns>
public StorageResourceContainer FromDirectory(string directoryPath)
{
return new LocalDirectoryStorageResourceContainer(directoryPath);
}
}
}