|
1 | 1 | using System; |
2 | | -using Microsoft.Azure.Storage.File; |
3 | | - |
| 2 | +using Azure.Storage.Files.Shares.Models; |
4 | 3 | using FluentStorage.Blobs; |
5 | 4 | using FluentStorage.Utils.Extensions; |
6 | 5 |
|
7 | 6 | namespace FluentStorage.Azure.Files { |
8 | 7 | static class AzConvert { |
9 | | - public static Blob ToBlob(CloudFileShare share) { |
| 8 | + public static Blob ToBlob(ShareItem share) { |
10 | 9 | var blob = new Blob(share.Name, BlobItemKind.Folder); |
11 | 10 | blob.TryAddProperties( |
12 | | - "IsSnapshot", share.IsSnapshot.ToString(), |
13 | | - "ETag", share.Properties.ETag, |
| 11 | + "ETag", share.Properties.ETag?.ToString(), |
14 | 12 | "LastModified", share.Properties.LastModified?.ToString(), |
15 | | - "Quota", share.Properties.Quota?.ToString(), |
16 | | - "SnapshotTime", share.SnapshotTime?.ToString(), |
| 13 | + "QuotaInGB", share.Properties.QuotaInGB?.ToString(), |
17 | 14 | "IsShare", "True"); |
18 | | - blob.Metadata.MergeRange(share.Metadata); |
19 | 15 | return blob; |
20 | 16 | } |
21 | 17 |
|
22 | | - public static Blob ToBlob(string path, IListFileItem item) { |
23 | | - if (item is CloudFile file) { |
24 | | - var blob = new Blob(path, file.Name, BlobItemKind.File) { |
25 | | - LastModificationTime = file.Properties.LastWriteTime, |
26 | | - Size = file.Properties.Length, |
27 | | - MD5 = file.Properties.ContentMD5 |
28 | | - }; |
29 | | - blob.TryAddProperties( |
30 | | - "CopyState", file.CopyState?.ToString(), |
31 | | - "ChangeTime", file.Properties.ChangeTime?.ToString(), |
32 | | - "ContentType", file.Properties.ContentType, |
33 | | - "CreationTime", file.Properties.CreationTime?.ToString(), |
34 | | - "ETag", file.Properties.ETag, |
35 | | - "IsServerEncrypted", file.Properties.IsServerEncrypted.ToString(), |
36 | | - "LastModified", file.Properties.LastModified?.ToString(), |
37 | | - "NtfsAttributes", file.Properties.NtfsAttributes?.ToString()); |
38 | | - blob.Metadata.MergeRange(file.Metadata); |
39 | | - return blob; |
40 | | - } |
41 | | - else if (item is CloudFileDirectory dir) { |
42 | | - var blob = new Blob(path, dir.Name, BlobItemKind.Folder) { |
43 | | - LastModificationTime = dir.Properties.LastWriteTime |
44 | | - }; |
| 18 | + public static Blob ToBlob(string path, ShareFileItem item) { |
| 19 | + if (item.IsDirectory) { |
| 20 | + var blob = new Blob(path, item.Name, BlobItemKind.Folder); |
45 | 21 | blob.TryAddProperties( |
46 | | - "ChangeTime", dir.Properties.ChangeTime?.ToString(), |
47 | | - "CreationTime", dir.Properties.CreationTime?.ToString(), |
48 | | - "ETag", dir.Properties.ETag, |
49 | | - "IsServerEncrypted", dir.Properties.IsServerEncrypted.ToString(), |
50 | | - "LastModified", dir.Properties.LastModified?.ToString(), |
51 | | - "NtfsAttributes", dir.Properties.NtfsAttributes?.ToString()); |
52 | | - blob.Metadata.MergeRange(dir.Metadata); |
| 22 | + "ETag", item.Properties.ETag?.ToString(), |
| 23 | + "LastModified", item.Properties.LastModified?.ToString()); |
53 | 24 | return blob; |
54 | 25 | } |
55 | | - else { |
56 | | - throw new NotSupportedException($"don't know '{item.GetType()}' object type"); |
57 | | - } |
| 26 | + |
| 27 | + return ToFileBlob(path, item); |
| 28 | + } |
| 29 | + |
| 30 | + public static Blob ToBlob(string path, string name, ShareFileProperties properties) { |
| 31 | + return ToBlob(path, name, properties, properties.Metadata); |
| 32 | + } |
| 33 | + |
| 34 | + private static Blob ToFileBlob(string path, ShareFileItem item) { |
| 35 | + ShareFileItemProperties properties = item.Properties; |
| 36 | + var blob = new Blob(path, item.Name, BlobItemKind.File) { |
| 37 | + LastModificationTime = properties.LastModified, |
| 38 | + Size = item.FileSize |
| 39 | + }; |
| 40 | + blob.TryAddProperties( |
| 41 | + "ETag", properties.ETag?.ToString(), |
| 42 | + "LastModified", properties.LastModified?.ToString()); |
| 43 | + return blob; |
| 44 | + } |
| 45 | + |
| 46 | + private static Blob ToBlob(string path, string name, ShareFileProperties properties, System.Collections.Generic.IDictionary<string, string> metadata) { |
| 47 | + var blob = new Blob(path, name, BlobItemKind.File) { |
| 48 | + LastModificationTime = properties.LastModified, |
| 49 | + Size = properties.ContentLength, |
| 50 | + MD5 = properties.ContentHash == null ? null : Convert.ToBase64String(properties.ContentHash) |
| 51 | + }; |
| 52 | + blob.TryAddProperties( |
| 53 | + "CopyStatus", properties.CopyStatus.ToString(), |
| 54 | + "ContentType", properties.ContentType, |
| 55 | + "ETag", properties.ETag.ToString(), |
| 56 | + "IsServerEncrypted", properties.IsServerEncrypted.ToString(), |
| 57 | + "LastModified", properties.LastModified.ToString()); |
| 58 | + blob.Metadata.MergeRange(metadata); |
| 59 | + return blob; |
58 | 60 | } |
59 | 61 | } |
60 | 62 | } |
0 commit comments