| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | |
|
| | 6 | | // Alias the ServiceVersion enum used by the service importing this shared |
| | 7 | | // source file |
| | 8 | | using ServiceVersion = |
| | 9 | | #if BlobSDK |
| | 10 | | Azure.Storage.Blobs.BlobClientOptions.ServiceVersion; |
| | 11 | | #elif QueueSDK |
| | 12 | | Azure.Storage.Queues.QueueClientOptions.ServiceVersion; |
| | 13 | | #elif FileSDK |
| | 14 | | Azure.Storage.Files.Shares.ShareClientOptions.ServiceVersion; |
| | 15 | | #elif DataLakeSDK |
| | 16 | | Azure.Storage.Files.DataLake.DataLakeClientOptions.ServiceVersion; |
| | 17 | | #else |
| | 18 | | // If you see this error, you've included this shared source file from a |
| | 19 | | // client library that it doesn't know how to help you with. Either add |
| | 20 | | // the appropriate XyzSDK flag to your .csproj or alias your service |
| | 21 | | // version above. |
| | 22 | | ERROR_STORAGE_SERVICE_NOT_DEFINED; |
| | 23 | | #endif |
| | 24 | |
|
| | 25 | | namespace Azure.Storage |
| | 26 | | { |
| | 27 | | /// <summary> |
| | 28 | | /// Helpers to manage Storage service versions. |
| | 29 | | /// </summary> |
| | 30 | | internal static class StorageVersionExtensions |
| | 31 | | { |
| | 32 | | /// <summary> |
| | 33 | | /// Gets the latest version of the service supported by this SDK. |
| | 34 | | /// </summary> |
| | 35 | | public const ServiceVersion LatestVersion = |
| | 36 | | #if BlobSDK || QueueSDK || FileSDK || DataLakeSDK |
| | 37 | | ServiceVersion.V2019_12_12; |
| | 38 | | #else |
| | 39 | | ERROR_STORAGE_SERVICE_NOT_DEFINED; |
| | 40 | | #endif |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Convert a Storage ServiceVersion enum to an x-ms-version string. |
| | 44 | | /// </summary> |
| | 45 | | /// <param name="version">The service version enum value.</param> |
| | 46 | | /// <returns>The x-ms-version string.</returns> |
| | 47 | | public static string ToVersionString(this ServiceVersion version) => |
| 762 | 48 | | version switch |
| 762 | 49 | | { |
| 762 | 50 | | #if BlobSDK || FileSDK || DataLakeSDK |
| 762 | 51 | | ServiceVersion.V2019_02_02 => "2019-02-02", |
| 762 | 52 | | ServiceVersion.V2019_07_07 => "2019-07-07", |
| 762 | 53 | | ServiceVersion.V2019_12_12 => "2019-12-12", |
| 762 | 54 | | #elif QueueSDK |
| 762 | 55 | | // Queues just bumped the version number without changing the swagger |
| 0 | 56 | | ServiceVersion.V2019_02_02 => "2018-11-09", |
| 0 | 57 | | ServiceVersion.V2019_07_07 => "2018-11-09", |
| 1524 | 58 | | ServiceVersion.V2019_12_12 => "2018-11-09", |
| 762 | 59 | | #endif |
| 0 | 60 | | _ => throw Errors.VersionNotSupported(nameof(version)) |
| 762 | 61 | | }; |
| | 62 | |
|
| | 63 | | #if DataLakeSDK |
| | 64 | | /// <summary> |
| | 65 | | /// Convert a DataLake ServiceVersion to a Blobs ServiceVersion. |
| | 66 | | /// </summary> |
| | 67 | | /// <param name="version">The DataLake service version.</param> |
| | 68 | | /// <returns>The Blobs service version.</returns> |
| | 69 | | public static Azure.Storage.Blobs.BlobClientOptions.ServiceVersion AsBlobsVersion(this Azure.Storage.Files.DataL |
| | 70 | | version switch |
| | 71 | | { |
| | 72 | | Azure.Storage.Files.DataLake.DataLakeClientOptions.ServiceVersion.V2019_02_02 => |
| | 73 | | Azure.Storage.Blobs.BlobClientOptions.ServiceVersion.V2019_02_02, |
| | 74 | | Azure.Storage.Files.DataLake.DataLakeClientOptions.ServiceVersion.V2019_07_07 => |
| | 75 | | Azure.Storage.Blobs.BlobClientOptions.ServiceVersion.V2019_07_07, |
| | 76 | | Azure.Storage.Files.DataLake.DataLakeClientOptions.ServiceVersion.V2019_12_12 => |
| | 77 | | Azure.Storage.Blobs.BlobClientOptions.ServiceVersion.V2019_12_12, |
| | 78 | | _ => throw Errors.VersionNotSupported(nameof(version)) |
| | 79 | | }; |
| | 80 | | #endif |
| | 81 | | } |
| | 82 | | } |