| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.IO; |
| | 7 | | using System.Text; |
| | 8 | | using System.Text.Json; |
| | 9 | | using System.Threading; |
| | 10 | | using System.Threading.Tasks; |
| | 11 | | using Azure.Core; |
| | 12 | | using Azure.Core.Pipeline; |
| | 13 | | using Azure.Storage.Files.Shares.Models; |
| | 14 | | using Metadata = System.Collections.Generic.IDictionary<string, string>; |
| | 15 | |
|
| | 16 | | namespace Azure.Storage.Files.Shares |
| | 17 | | { |
| | 18 | | /// <summary> |
| | 19 | | /// The <see cref="ShareClient"/> allows you to manipulate Azure |
| | 20 | | /// Storage shares and their directories and files. |
| | 21 | | /// </summary> |
| | 22 | | public class ShareClient |
| | 23 | | { |
| | 24 | | /// <summary> |
| | 25 | | /// The share's primary <see cref="Uri"/> endpoint. |
| | 26 | | /// </summary> |
| | 27 | | private readonly Uri _uri; |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Gets the share's primary <see cref="Uri"/> endpoint. |
| | 31 | | /// </summary> |
| 1641 | 32 | | public virtual Uri Uri => _uri; |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// The <see cref="HttpPipeline"/> transport pipeline used to send |
| | 36 | | /// every request. |
| | 37 | | /// </summary> |
| | 38 | | private readonly HttpPipeline _pipeline; |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Gets the <see cref="HttpPipeline"/> transport pipeline used to send |
| | 42 | | /// every request. |
| | 43 | | /// </summary> |
| 2469 | 44 | | internal virtual HttpPipeline Pipeline => _pipeline; |
| | 45 | |
|
| | 46 | | /// <summary> |
| | 47 | | /// The version of the service to use when sending requests. |
| | 48 | | /// </summary> |
| | 49 | | private readonly ShareClientOptions.ServiceVersion _version; |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// The version of the service to use when sending requests. |
| | 53 | | /// </summary> |
| 1455 | 54 | | internal virtual ShareClientOptions.ServiceVersion Version => _version; |
| | 55 | |
|
| | 56 | | /// <summary> |
| | 57 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 58 | | /// every request. |
| | 59 | | /// </summary> |
| | 60 | | private readonly ClientDiagnostics _clientDiagnostics; |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// The <see cref="ClientDiagnostics"/> instance used to create diagnostic scopes |
| | 64 | | /// every request. |
| | 65 | | /// </summary> |
| 1455 | 66 | | internal virtual ClientDiagnostics ClientDiagnostics => _clientDiagnostics; |
| | 67 | |
|
| | 68 | | /// <summary> |
| | 69 | | /// The Storage account name corresponding to the share client. |
| | 70 | | /// </summary> |
| | 71 | | private string _accountName; |
| | 72 | |
|
| | 73 | | /// <summary> |
| | 74 | | /// Gets the Storage account name corresponding to the share client. |
| | 75 | | /// </summary> |
| | 76 | | public virtual string AccountName |
| | 77 | | { |
| | 78 | | get |
| | 79 | | { |
| 4 | 80 | | SetNameFieldsIfNull(); |
| 4 | 81 | | return _accountName; |
| | 82 | | } |
| | 83 | | } |
| | 84 | |
|
| | 85 | | /// <summary> |
| | 86 | | /// The name of the share. |
| | 87 | | /// </summary> |
| | 88 | | private string _name; |
| | 89 | |
|
| | 90 | | /// <summary> |
| | 91 | | /// Gets the name of the share. |
| | 92 | | /// </summary> |
| | 93 | | public virtual string Name |
| | 94 | | { |
| | 95 | | get |
| | 96 | | { |
| 185 | 97 | | SetNameFieldsIfNull(); |
| 185 | 98 | | return _name; |
| | 99 | | } |
| | 100 | | } |
| | 101 | |
|
| | 102 | | #region ctors |
| | 103 | | /// <summary> |
| | 104 | | /// Initializes a new instance of the <see cref="ShareClient"/> |
| | 105 | | /// class for mocking. |
| | 106 | | /// </summary> |
| 589 | 107 | | protected ShareClient() |
| | 108 | | { |
| 589 | 109 | | } |
| | 110 | |
|
| | 111 | | /// <summary> |
| | 112 | | /// Initializes a new instance of the <see cref="ShareClient"/> |
| | 113 | | /// class. |
| | 114 | | /// </summary> |
| | 115 | | /// <param name="connectionString"> |
| | 116 | | /// A connection string includes the authentication information |
| | 117 | | /// required for your application to access data in an Azure Storage |
| | 118 | | /// account at runtime. |
| | 119 | | /// |
| | 120 | | /// For more information, |
| | 121 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 122 | | /// Configure Azure Storage connection strings</see> |
| | 123 | | /// </param> |
| | 124 | | /// <param name="shareName"> |
| | 125 | | /// The name of the share in the storage account to reference. |
| | 126 | | /// </param> |
| | 127 | | public ShareClient(string connectionString, string shareName) |
| 0 | 128 | | : this(connectionString, shareName, null) |
| | 129 | | { |
| 0 | 130 | | } |
| | 131 | |
|
| | 132 | | /// <summary> |
| | 133 | | /// Initializes a new instance of the <see cref="ShareClient"/> |
| | 134 | | /// class. |
| | 135 | | /// </summary> |
| | 136 | | /// <param name="connectionString"> |
| | 137 | | /// A connection string includes the authentication information |
| | 138 | | /// required for your application to access data in an Azure Storage |
| | 139 | | /// account at runtime. |
| | 140 | | /// |
| | 141 | | /// For more information, |
| | 142 | | /// <see href="https://docs.microsoft.com/azure/storage/common/storage-configure-connection-string"> |
| | 143 | | /// Configure Azure Storage connection strings</see> |
| | 144 | | /// </param> |
| | 145 | | /// <param name="shareName"> |
| | 146 | | /// The name of the share in the storage account to reference. |
| | 147 | | /// </param> |
| | 148 | | /// <param name="options"> |
| | 149 | | /// Optional client options that define the transport pipeline |
| | 150 | | /// policies for authentication, retries, etc., that are applied to |
| | 151 | | /// every request. |
| | 152 | | /// </param> |
| 6 | 153 | | public ShareClient(string connectionString, string shareName, ShareClientOptions options) |
| | 154 | | { |
| 6 | 155 | | options ??= new ShareClientOptions(); |
| 6 | 156 | | var conn = StorageConnectionString.Parse(connectionString); |
| 6 | 157 | | var builder = new ShareUriBuilder(conn.FileEndpoint) { ShareName = shareName }; |
| 6 | 158 | | _uri = builder.ToUri(); |
| 6 | 159 | | _pipeline = options.Build(conn.Credentials); |
| 6 | 160 | | _version = options.Version; |
| 6 | 161 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 6 | 162 | | } |
| | 163 | |
|
| | 164 | | /// <summary> |
| | 165 | | /// Initializes a new instance of the <see cref="ShareClient"/> |
| | 166 | | /// class. |
| | 167 | | /// </summary> |
| | 168 | | /// <param name="shareUri"> |
| | 169 | | /// A <see cref="Uri"/> referencing the share that includes the |
| | 170 | | /// name of the account and the name of the share. |
| | 171 | | /// </param> |
| | 172 | | /// <param name="options"> |
| | 173 | | /// Optional client options that define the transport pipeline |
| | 174 | | /// policies for authentication, retries, etc., that are applied to |
| | 175 | | /// every request. |
| | 176 | | /// </param> |
| | 177 | | public ShareClient(Uri shareUri, ShareClientOptions options = default) |
| 22 | 178 | | : this(shareUri, (HttpPipelinePolicy)null, options) |
| | 179 | | { |
| 22 | 180 | | } |
| | 181 | |
|
| | 182 | | /// <summary> |
| | 183 | | /// Initializes a new instance of the <see cref="ShareClient"/> |
| | 184 | | /// class. |
| | 185 | | /// </summary> |
| | 186 | | /// <param name="shareUri"> |
| | 187 | | /// A <see cref="Uri"/> referencing the share that includes the |
| | 188 | | /// name of the account and the name of the share. |
| | 189 | | /// </param> |
| | 190 | | /// <param name="credential"> |
| | 191 | | /// The shared key credential used to sign requests. |
| | 192 | | /// </param> |
| | 193 | | /// <param name="options"> |
| | 194 | | /// Optional client options that define the transport pipeline |
| | 195 | | /// policies for authentication, retries, etc., that are applied to |
| | 196 | | /// every request. |
| | 197 | | /// </param> |
| | 198 | | public ShareClient(Uri shareUri, StorageSharedKeyCredential credential, ShareClientOptions options = default) |
| 0 | 199 | | : this(shareUri, credential.AsPolicy(), options) |
| | 200 | | { |
| 0 | 201 | | } |
| | 202 | |
|
| | 203 | | /// <summary> |
| | 204 | | /// Initializes a new instance of the <see cref="ShareClient"/> |
| | 205 | | /// class. |
| | 206 | | /// </summary> |
| | 207 | | /// <param name="shareUri"> |
| | 208 | | /// A <see cref="Uri"/> referencing the share that includes the |
| | 209 | | /// name of the account and the name of the share. |
| | 210 | | /// </param> |
| | 211 | | /// <param name="authentication"> |
| | 212 | | /// An optional authentication policy used to sign requests. |
| | 213 | | /// </param> |
| | 214 | | /// <param name="options"> |
| | 215 | | /// Optional client options that define the transport pipeline |
| | 216 | | /// policies for authentication, retries, etc., that are applied to |
| | 217 | | /// every request. |
| | 218 | | /// </param> |
| 22 | 219 | | internal ShareClient(Uri shareUri, HttpPipelinePolicy authentication, ShareClientOptions options) |
| | 220 | | { |
| 22 | 221 | | options ??= new ShareClientOptions(); |
| 22 | 222 | | _uri = shareUri; |
| 22 | 223 | | _pipeline = options.Build(authentication); |
| 22 | 224 | | _version = options.Version; |
| 22 | 225 | | _clientDiagnostics = new ClientDiagnostics(options); |
| 22 | 226 | | } |
| | 227 | |
|
| | 228 | | /// <summary> |
| | 229 | | /// Initializes a new instance of the <see cref="ShareClient"/> |
| | 230 | | /// class. |
| | 231 | | /// </summary> |
| | 232 | | /// <param name="shareUri"> |
| | 233 | | /// A <see cref="Uri"/> referencing the share that includes the |
| | 234 | | /// name of the account and the name of the share. |
| | 235 | | /// </param> |
| | 236 | | /// <param name="pipeline"> |
| | 237 | | /// The transport pipeline used to send every request. |
| | 238 | | /// </param> |
| | 239 | | /// <param name="version"> |
| | 240 | | /// The version of the service to use when sending requests. |
| | 241 | | /// </param> |
| | 242 | | /// <param name="clientDiagnostics"> |
| | 243 | | /// The <see cref="ClientDiagnostics"/> instance used to create |
| | 244 | | /// diagnostic scopes every request. |
| | 245 | | /// </param> |
| 577 | 246 | | internal ShareClient(Uri shareUri, HttpPipeline pipeline, ShareClientOptions.ServiceVersion version, ClientDiagn |
| | 247 | | { |
| 577 | 248 | | _uri = shareUri; |
| 577 | 249 | | _pipeline = pipeline; |
| 577 | 250 | | _version = version; |
| 577 | 251 | | _clientDiagnostics = clientDiagnostics; |
| 577 | 252 | | } |
| | 253 | | #endregion ctors |
| | 254 | |
|
| | 255 | | /// <summary> |
| | 256 | | /// Initializes a new instance of the <see cref="ShareClient"/> |
| | 257 | | /// class with an identical <see cref="Uri"/> source but the specified |
| | 258 | | /// <paramref name="snapshot"/> timestamp. |
| | 259 | | /// |
| | 260 | | /// For more information, see |
| | 261 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/snapshot-share"> |
| | 262 | | /// Snapshot Share</see>. |
| | 263 | | /// </summary> |
| | 264 | | /// <remarks> |
| | 265 | | /// Pass null or empty string to remove the snapshot returning a URL to the base share. |
| | 266 | | /// </remarks> |
| | 267 | | /// <param name="snapshot"> |
| | 268 | | /// The snapshot identifier. |
| | 269 | | /// </param> |
| | 270 | | /// <returns> |
| | 271 | | /// A new <see cref="ShareClient"/> instance. |
| | 272 | | /// </returns> |
| | 273 | | public virtual ShareClient WithSnapshot(string snapshot) |
| | 274 | | { |
| 20 | 275 | | var p = new ShareUriBuilder(Uri) { Snapshot = snapshot }; |
| 20 | 276 | | return new ShareClient(p.ToUri(), Pipeline, Version, ClientDiagnostics); |
| | 277 | | } |
| | 278 | |
|
| | 279 | | /// <summary> |
| | 280 | | /// Create a new <see cref="ShareDirectoryClient"/> object by appending |
| | 281 | | /// <paramref name="directoryName"/> to the end of <see cref="Uri"/>. The |
| | 282 | | /// new <see cref="ShareDirectoryClient"/> uses the same request policy |
| | 283 | | /// pipeline as the <see cref="ShareClient"/>. |
| | 284 | | /// </summary> |
| | 285 | | /// <param name="directoryName">The name of the directory.</param> |
| | 286 | | /// <returns>A new <see cref="ShareDirectoryClient"/> instance.</returns> |
| | 287 | | public virtual ShareDirectoryClient GetDirectoryClient(string directoryName) |
| | 288 | | { |
| 433 | 289 | | ShareUriBuilder shareUriBuilder = new ShareUriBuilder(Uri) |
| 433 | 290 | | { |
| 433 | 291 | | DirectoryOrFilePath = directoryName |
| 433 | 292 | | }; |
| 433 | 293 | | return new ShareDirectoryClient( |
| 433 | 294 | | shareUriBuilder.ToUri(), |
| 433 | 295 | | Pipeline, |
| 433 | 296 | | Version, |
| 433 | 297 | | ClientDiagnostics); |
| | 298 | | } |
| | 299 | |
|
| | 300 | |
|
| | 301 | | /// <summary> |
| | 302 | | /// Create a <see cref="ShareDirectoryClient"/> object for the root of the |
| | 303 | | /// share. The new <see cref="ShareDirectoryClient"/> uses the same request |
| | 304 | | /// policy pipeline as the <see cref="ShareClient"/>. |
| | 305 | | /// </summary> |
| | 306 | | /// <returns>A new <see cref="ShareDirectoryClient"/> instance.</returns> |
| | 307 | | public virtual ShareDirectoryClient GetRootDirectoryClient() |
| 66 | 308 | | => GetDirectoryClient(""); |
| | 309 | |
|
| | 310 | | /// <summary> |
| | 311 | | /// Sets the various name fields if they are currently null. |
| | 312 | | /// </summary> |
| | 313 | | private void SetNameFieldsIfNull() |
| | 314 | | { |
| 189 | 315 | | if (_name == null || _accountName == null) |
| | 316 | | { |
| 54 | 317 | | var builder = new ShareUriBuilder(Uri); |
| 54 | 318 | | _name = builder.ShareName; |
| 54 | 319 | | _accountName = builder.AccountName; |
| | 320 | | } |
| 189 | 321 | | } |
| | 322 | |
|
| | 323 | | #region Create |
| | 324 | | /// <summary> |
| | 325 | | /// The <see cref="Create"/> operation creates a new share |
| | 326 | | /// under the specified account. If a share with the same name |
| | 327 | | /// already exists, the operation fails. |
| | 328 | | /// |
| | 329 | | /// For more information, see |
| | 330 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-share"> |
| | 331 | | /// Create Share</see>. |
| | 332 | | /// </summary> |
| | 333 | | /// <param name="metadata"> |
| | 334 | | /// Optional custom metadata to set for this share. |
| | 335 | | /// </param> |
| | 336 | | /// <param name="quotaInGB"> |
| | 337 | | /// Optional. Maximum size of the share in bytes. If unspecified, use the service's default value. |
| | 338 | | /// </param> |
| | 339 | | /// <param name="cancellationToken"> |
| | 340 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 341 | | /// notifications that the operation should be cancelled. |
| | 342 | | /// </param> |
| | 343 | | /// <returns> |
| | 344 | | /// A <see cref="Response{ShareInfo}"/> describing the newly |
| | 345 | | /// created share. |
| | 346 | | /// </returns> |
| | 347 | | /// <remarks> |
| | 348 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 349 | | /// a failure occurs. |
| | 350 | | /// </remarks> |
| | 351 | | public virtual Response<ShareInfo> Create( |
| | 352 | | Metadata metadata = default, |
| | 353 | | int? quotaInGB = default, |
| | 354 | | CancellationToken cancellationToken = default) => |
| 218 | 355 | | CreateInternal( |
| 218 | 356 | | metadata, |
| 218 | 357 | | quotaInGB, |
| 218 | 358 | | false, // async |
| 218 | 359 | | cancellationToken) |
| 218 | 360 | | .EnsureCompleted(); |
| | 361 | |
|
| | 362 | | /// <summary> |
| | 363 | | /// The <see cref="CreateAsync"/> operation creates a new share |
| | 364 | | /// under the specified account. If a share with the same name |
| | 365 | | /// already exists, the operation fails. |
| | 366 | | /// |
| | 367 | | /// For more information, see |
| | 368 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-share"> |
| | 369 | | /// Create Share</see>. |
| | 370 | | /// </summary> |
| | 371 | | /// <param name="metadata"> |
| | 372 | | /// Optional custom metadata to set for this share. |
| | 373 | | /// </param> |
| | 374 | | /// <param name="quotaInGB"> |
| | 375 | | /// Optional. Maximum size of the share in bytes. If unspecified, use the service's default value. |
| | 376 | | /// </param> |
| | 377 | | /// <param name="cancellationToken"> |
| | 378 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 379 | | /// notifications that the operation should be cancelled. |
| | 380 | | /// </param> |
| | 381 | | /// <returns> |
| | 382 | | /// A <see cref="Response{ShareInfo}"/> describing the newly |
| | 383 | | /// created share. |
| | 384 | | /// </returns> |
| | 385 | | /// <remarks> |
| | 386 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 387 | | /// a failure occurs. |
| | 388 | | /// </remarks> |
| | 389 | | public virtual async Task<Response<ShareInfo>> CreateAsync( |
| | 390 | | Metadata metadata = default, |
| | 391 | | int? quotaInGB = default, |
| | 392 | | CancellationToken cancellationToken = default) => |
| 219 | 393 | | await CreateInternal( |
| 219 | 394 | | metadata, |
| 219 | 395 | | quotaInGB, |
| 219 | 396 | | true, // async |
| 219 | 397 | | cancellationToken) |
| 219 | 398 | | .ConfigureAwait(false); |
| | 399 | |
|
| | 400 | | /// <summary> |
| | 401 | | /// The <see cref="CreateInternal"/> operation creates a new share |
| | 402 | | /// under the specified account. If a share with the same name |
| | 403 | | /// already exists, the operation fails. |
| | 404 | | /// |
| | 405 | | /// For more information, see |
| | 406 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-share"> |
| | 407 | | /// Create Share</see>. |
| | 408 | | /// </summary> |
| | 409 | | /// <param name="metadata"> |
| | 410 | | /// Optional custom metadata to set for this share. |
| | 411 | | /// </param> |
| | 412 | | /// <param name="quotaInGB"> |
| | 413 | | /// Optional. Maximum size of the share in bytes. If unspecified, use the service's default value. |
| | 414 | | /// </param> |
| | 415 | | /// <param name="async"> |
| | 416 | | /// Whether to invoke the operation asynchronously. |
| | 417 | | /// </param> |
| | 418 | | /// <param name="cancellationToken"> |
| | 419 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 420 | | /// notifications that the operation should be cancelled. |
| | 421 | | /// </param> |
| | 422 | | /// <param name="operationName"> |
| | 423 | | /// Optional. To indicate if the name of the operation. |
| | 424 | | /// </param> |
| | 425 | | /// <returns> |
| | 426 | | /// A <see cref="Response{ShareInfo}"/> describing the newly |
| | 427 | | /// created share. |
| | 428 | | /// </returns> |
| | 429 | | /// <remarks> |
| | 430 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 431 | | /// a failure occurs. |
| | 432 | | /// </remarks> |
| | 433 | | internal async Task<Response<ShareInfo>> CreateInternal( |
| | 434 | | Metadata metadata, |
| | 435 | | int? quotaInGB, |
| | 436 | | bool async, |
| | 437 | | CancellationToken cancellationToken, |
| | 438 | | string operationName = default) |
| | 439 | | { |
| 447 | 440 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 441 | | { |
| | 442 | | Pipeline.LogMethodEnter( |
| | 443 | | nameof(ShareClient), |
| | 444 | | message: |
| | 445 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 446 | | $"{nameof(quotaInGB)}: {quotaInGB}"); |
| | 447 | | try |
| | 448 | | { |
| 447 | 449 | | return await FileRestClient.Share.CreateAsync( |
| 447 | 450 | | ClientDiagnostics, |
| 447 | 451 | | Pipeline, |
| 447 | 452 | | Uri, |
| 447 | 453 | | version: Version.ToVersionString(), |
| 447 | 454 | | metadata: metadata, |
| 447 | 455 | | quotaInGB: quotaInGB, |
| 447 | 456 | | async: async, |
| 447 | 457 | | operationName: operationName ?? $"{nameof(ShareClient)}.{nameof(Create)}", |
| 447 | 458 | | cancellationToken: cancellationToken) |
| 447 | 459 | | .ConfigureAwait(false); |
| | 460 | | } |
| 8 | 461 | | catch (Exception ex) |
| | 462 | | { |
| | 463 | | Pipeline.LogException(ex); |
| 8 | 464 | | throw; |
| | 465 | | } |
| | 466 | | finally |
| | 467 | | { |
| | 468 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 469 | | } |
| | 470 | | } |
| 439 | 471 | | } |
| | 472 | | #endregion Create |
| | 473 | |
|
| | 474 | | #region Create If Not Exists |
| | 475 | | /// <summary> |
| | 476 | | /// The <see cref="CreateIfNotExists"/> operation creates a new share |
| | 477 | | /// under the specified account. If a share with the same name |
| | 478 | | /// already exists, it is not changed. |
| | 479 | | /// |
| | 480 | | /// For more information, see |
| | 481 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-share"> |
| | 482 | | /// Create Share</see>. |
| | 483 | | /// </summary> |
| | 484 | | /// <param name="metadata"> |
| | 485 | | /// Optional custom metadata to set for this share. |
| | 486 | | /// </param> |
| | 487 | | /// <param name="quotaInGB"> |
| | 488 | | /// Optional. Maximum size of the share in bytes. If unspecified, use the service's default value. |
| | 489 | | /// </param> |
| | 490 | | /// <param name="cancellationToken"> |
| | 491 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 492 | | /// notifications that the operation should be cancelled. |
| | 493 | | /// </param> |
| | 494 | | /// <returns> |
| | 495 | | /// A <see cref="Response{ShareInfo}"/> describing the newly |
| | 496 | | /// created share. If the share already exists, <c>null</c>. |
| | 497 | | /// </returns> |
| | 498 | | /// <remarks> |
| | 499 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 500 | | /// a failure occurs. |
| | 501 | | /// </remarks> |
| | 502 | | public virtual Response<ShareInfo> CreateIfNotExists( |
| | 503 | | Metadata metadata = default, |
| | 504 | | int? quotaInGB = default, |
| | 505 | | CancellationToken cancellationToken = default) => |
| 3 | 506 | | CreateIfNotExistsInternal( |
| 3 | 507 | | metadata, |
| 3 | 508 | | quotaInGB, |
| 3 | 509 | | async: false, |
| 3 | 510 | | cancellationToken).EnsureCompleted(); |
| | 511 | |
|
| | 512 | | /// <summary> |
| | 513 | | /// The <see cref="CreateIfNotExistsAsync"/> operation creates a new share |
| | 514 | | /// under the specified account. If a share with the same name |
| | 515 | | /// already exists, it is not changed. |
| | 516 | | /// |
| | 517 | | /// For more information, see |
| | 518 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-share"> |
| | 519 | | /// Create Share</see>. |
| | 520 | | /// </summary> |
| | 521 | | /// <param name="metadata"> |
| | 522 | | /// Optional custom metadata to set for this share. |
| | 523 | | /// </param> |
| | 524 | | /// <param name="quotaInGB"> |
| | 525 | | /// Optional. Maximum size of the share in bytes. If unspecified, use the service's default value. |
| | 526 | | /// </param> |
| | 527 | | /// <param name="cancellationToken"> |
| | 528 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 529 | | /// notifications that the operation should be cancelled. |
| | 530 | | /// </param> |
| | 531 | | /// <returns> |
| | 532 | | /// A <see cref="Response{ShareInfo}"/> describing the newly |
| | 533 | | /// created share. If the share already exists, <c>null</c>. |
| | 534 | | /// </returns> |
| | 535 | | /// <remarks> |
| | 536 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 537 | | /// a failure occurs. |
| | 538 | | /// </remarks> |
| | 539 | | public virtual async Task<Response<ShareInfo>> CreateIfNotExistsAsync( |
| | 540 | | Metadata metadata = default, |
| | 541 | | int? quotaInGB = default, |
| | 542 | | CancellationToken cancellationToken = default) => |
| 3 | 543 | | await CreateIfNotExistsInternal( |
| 3 | 544 | | metadata, |
| 3 | 545 | | quotaInGB, |
| 3 | 546 | | async: true, |
| 3 | 547 | | cancellationToken).ConfigureAwait(false); |
| | 548 | |
|
| | 549 | | /// <summary> |
| | 550 | | /// The <see cref="CreateIfNotExistsInternal"/> operation creates a new share |
| | 551 | | /// under the specified account. If a share with the same name |
| | 552 | | /// already exists, it is not changed. |
| | 553 | | /// |
| | 554 | | /// For more information, see |
| | 555 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-share"> |
| | 556 | | /// Create Share</see>. |
| | 557 | | /// </summary> |
| | 558 | | /// <param name="metadata"> |
| | 559 | | /// Optional custom metadata to set for this share. |
| | 560 | | /// </param> |
| | 561 | | /// <param name="quotaInGB"> |
| | 562 | | /// Optional. Maximum size of the share in bytes. If unspecified, use the service's default value. |
| | 563 | | /// </param> |
| | 564 | | /// <param name="async"> |
| | 565 | | /// Whether to invoke the operation asynchronously. |
| | 566 | | /// </param> |
| | 567 | | /// <param name="cancellationToken"> |
| | 568 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 569 | | /// notifications that the operation should be cancelled. |
| | 570 | | /// </param> |
| | 571 | | /// <returns> |
| | 572 | | /// A <see cref="Response{ShareInfo}"/> describing the newly |
| | 573 | | /// created share. If the share already exists, <c>null</c>. |
| | 574 | | /// </returns> |
| | 575 | | /// <remarks> |
| | 576 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 577 | | /// a failure occurs. |
| | 578 | | /// </remarks> |
| | 579 | | private async Task<Response<ShareInfo>> CreateIfNotExistsInternal( |
| | 580 | | Metadata metadata, |
| | 581 | | int? quotaInGB, |
| | 582 | | bool async, |
| | 583 | | CancellationToken cancellationToken) |
| | 584 | | { |
| 6 | 585 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 586 | | { |
| | 587 | | Pipeline.LogMethodEnter( |
| | 588 | | nameof(ShareClient), |
| | 589 | | message: |
| | 590 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 591 | | $"{nameof(quotaInGB)}: {quotaInGB}"); |
| | 592 | | Response<ShareInfo> response; |
| | 593 | | try |
| | 594 | | { |
| 6 | 595 | | response = await CreateInternal( |
| 6 | 596 | | metadata, |
| 6 | 597 | | quotaInGB, |
| 6 | 598 | | async, |
| 6 | 599 | | cancellationToken, |
| 6 | 600 | | $"{nameof(ShareClient)}.{nameof(CreateIfNotExists)}") |
| 6 | 601 | | .ConfigureAwait(false); |
| 2 | 602 | | } |
| | 603 | | catch (RequestFailedException storageRequestFailedException) |
| 4 | 604 | | when (storageRequestFailedException.ErrorCode == ShareErrorCode.ShareAlreadyExists) |
| | 605 | | { |
| 2 | 606 | | response = default; |
| 2 | 607 | | } |
| 2 | 608 | | catch (Exception ex) |
| | 609 | | { |
| | 610 | | Pipeline.LogException(ex); |
| 2 | 611 | | throw; |
| | 612 | | } |
| | 613 | | finally |
| | 614 | | { |
| | 615 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 616 | | } |
| 4 | 617 | | return response; |
| | 618 | | } |
| 4 | 619 | | } |
| | 620 | | #endregion Create If Not Exists |
| | 621 | |
|
| | 622 | | #region Exists |
| | 623 | | /// <summary> |
| | 624 | | /// The <see cref="Exists"/> operation can be called on a |
| | 625 | | /// <see cref="ShareClient"/> to see if the associated share |
| | 626 | | /// exists on the storage account in the storage service. |
| | 627 | | /// </summary> |
| | 628 | | /// <param name="cancellationToken"> |
| | 629 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 630 | | /// notifications that the operation should be cancelled. |
| | 631 | | /// </param> |
| | 632 | | /// <returns> |
| | 633 | | /// Returns true if the share exists. |
| | 634 | | /// </returns> |
| | 635 | | /// <remarks> |
| | 636 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 637 | | /// a failure occurs. |
| | 638 | | /// </remarks> |
| | 639 | | public virtual Response<bool> Exists( |
| | 640 | | CancellationToken cancellationToken = default) => |
| 5 | 641 | | ExistsInternal( |
| 5 | 642 | | async: false, |
| 5 | 643 | | cancellationToken).EnsureCompleted(); |
| | 644 | |
|
| | 645 | | /// <summary> |
| | 646 | | /// The <see cref="ExistsAsync"/> operation can be called on a |
| | 647 | | /// <see cref="ShareClient"/> to see if the associated share |
| | 648 | | /// exists on the storage account in the storage service. |
| | 649 | | /// </summary> |
| | 650 | | /// <param name="cancellationToken"> |
| | 651 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 652 | | /// notifications that the operation should be cancelled. |
| | 653 | | /// </param> |
| | 654 | | /// <returns> |
| | 655 | | /// Returns true if the share exists. |
| | 656 | | /// </returns> |
| | 657 | | /// <remarks> |
| | 658 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 659 | | /// a failure occurs. |
| | 660 | | /// </remarks> |
| | 661 | | public virtual async Task<Response<bool>> ExistsAsync( |
| | 662 | | CancellationToken cancellationToken = default) => |
| 5 | 663 | | await ExistsInternal( |
| 5 | 664 | | async: true, |
| 5 | 665 | | cancellationToken).ConfigureAwait(false); |
| | 666 | |
|
| | 667 | | /// <summary> |
| | 668 | | /// The <see cref="ExistsInternal"/> operation can be called on a |
| | 669 | | /// <see cref="ShareClient"/> to see if the associated share |
| | 670 | | /// exists on the storage account in the storage service. |
| | 671 | | /// </summary> |
| | 672 | | /// <param name="async"> |
| | 673 | | /// Whether to invoke the operation asynchronously. |
| | 674 | | /// </param> |
| | 675 | | /// <param name="cancellationToken"> |
| | 676 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 677 | | /// notifications that the operation should be cancelled. |
| | 678 | | /// </param> |
| | 679 | | /// <returns> |
| | 680 | | /// Returns true if the share exists. |
| | 681 | | /// </returns> |
| | 682 | | /// <remarks> |
| | 683 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 684 | | /// a failure occurs. |
| | 685 | | /// </remarks> |
| | 686 | | private async Task<Response<bool>> ExistsInternal( |
| | 687 | | bool async, |
| | 688 | | CancellationToken cancellationToken) |
| | 689 | | { |
| 10 | 690 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 691 | | { |
| | 692 | | Pipeline.LogMethodEnter( |
| | 693 | | nameof(ShareClient), |
| | 694 | | message: |
| | 695 | | $"{nameof(Uri)}: {Uri}"); |
| | 696 | |
|
| | 697 | | try |
| | 698 | | { |
| 10 | 699 | | Response<ShareProperties> response = await FileRestClient.Share.GetPropertiesAsync( |
| 10 | 700 | | ClientDiagnostics, |
| 10 | 701 | | Pipeline, |
| 10 | 702 | | Uri, |
| 10 | 703 | | version: Version.ToVersionString(), |
| 10 | 704 | | async: async, |
| 10 | 705 | | operationName: $"{nameof(ShareClient)}.{nameof(Exists)}", |
| 10 | 706 | | cancellationToken: cancellationToken) |
| 10 | 707 | | .ConfigureAwait(false); |
| | 708 | |
|
| 4 | 709 | | return Response.FromValue(true, response.GetRawResponse()); |
| | 710 | | } |
| | 711 | | catch (RequestFailedException storageRequestFailedException) |
| 6 | 712 | | when (storageRequestFailedException.ErrorCode == ShareErrorCode.ShareNotFound) |
| | 713 | | { |
| 4 | 714 | | return Response.FromValue(false, default); |
| | 715 | | } |
| 2 | 716 | | catch (Exception ex) |
| | 717 | | { |
| | 718 | | Pipeline.LogException(ex); |
| 2 | 719 | | throw; |
| | 720 | | } |
| | 721 | | finally |
| | 722 | | { |
| | 723 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 724 | | } |
| | 725 | | } |
| 8 | 726 | | } |
| | 727 | | #endregion Exists |
| | 728 | |
|
| | 729 | | #region Delete If Exists |
| | 730 | | /// <summary> |
| | 731 | | /// Marks the specified share or share snapshot for deletion, if it exists. |
| | 732 | | /// |
| | 733 | | /// For more information, see |
| | 734 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-share"> |
| | 735 | | /// Delete Share</see>. |
| | 736 | | /// </summary> |
| | 737 | | /// <param name="includeSnapshots"> |
| | 738 | | /// A value indicating whether to delete a share's snapshots in addition |
| | 739 | | /// to the share itself. |
| | 740 | | /// </param> |
| | 741 | | /// <param name="cancellationToken"> |
| | 742 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 743 | | /// notifications that the operation should be cancelled. |
| | 744 | | /// </param> |
| | 745 | | /// <returns> |
| | 746 | | /// A <see cref="Response"/> on successfully deleting. |
| | 747 | | /// </returns> |
| | 748 | | /// <remarks> |
| | 749 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 750 | | /// a failure occurs. |
| | 751 | | /// </remarks> |
| | 752 | | public virtual Response<bool> DeleteIfExists( |
| | 753 | | bool includeSnapshots = true, |
| | 754 | | CancellationToken cancellationToken = default) => |
| 3 | 755 | | DeleteIfExistsInternal( |
| 3 | 756 | | includeSnapshots, |
| 3 | 757 | | async: false, |
| 3 | 758 | | cancellationToken).EnsureCompleted(); |
| | 759 | |
|
| | 760 | | /// <summary> |
| | 761 | | /// Marks the specified share or share snapshot for deletion, if it exists. |
| | 762 | | /// |
| | 763 | | /// For more information, see |
| | 764 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-share"> |
| | 765 | | /// Delete Share</see>. |
| | 766 | | /// </summary> |
| | 767 | | /// <param name="includeSnapshots"> |
| | 768 | | /// A value indicating whether to delete a share's snapshots in addition |
| | 769 | | /// to the share itself. |
| | 770 | | /// </param> |
| | 771 | | /// <param name="cancellationToken"> |
| | 772 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 773 | | /// notifications that the operation should be cancelled. |
| | 774 | | /// </param> |
| | 775 | | /// <returns> |
| | 776 | | /// A <see cref="Response"/> on successfully deleting. |
| | 777 | | /// </returns> |
| | 778 | | /// <remarks> |
| | 779 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 780 | | /// a failure occurs. |
| | 781 | | /// </remarks> |
| | 782 | | public virtual async Task<Response<bool>> DeleteIfExistsAsync( |
| | 783 | | bool includeSnapshots = true, |
| | 784 | | CancellationToken cancellationToken = default) => |
| 3 | 785 | | await DeleteIfExistsInternal( |
| 3 | 786 | | includeSnapshots, |
| 3 | 787 | | async: true, |
| 3 | 788 | | cancellationToken).ConfigureAwait(false); |
| | 789 | |
|
| | 790 | | /// <summary> |
| | 791 | | /// Marks the specified share or share snapshot for deletion, if it exists. |
| | 792 | | /// |
| | 793 | | /// For more information, see |
| | 794 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-share"> |
| | 795 | | /// Delete Share</see>. |
| | 796 | | /// </summary> |
| | 797 | | /// <param name="includeSnapshots"> |
| | 798 | | /// A value indicating whether to delete a share's snapshots in addition |
| | 799 | | /// to the share itself. |
| | 800 | | /// </param> |
| | 801 | | /// <param name="async"> |
| | 802 | | /// Whether to invoke the operation asynchronously. |
| | 803 | | /// </param> |
| | 804 | | /// <param name="cancellationToken"> |
| | 805 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 806 | | /// notifications that the operation should be cancelled. |
| | 807 | | /// </param> |
| | 808 | | /// <returns> |
| | 809 | | /// A <see cref="Response"/> on successfully deleting. |
| | 810 | | /// </returns> |
| | 811 | | /// <remarks> |
| | 812 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 813 | | /// a failure occurs. |
| | 814 | | /// </remarks> |
| | 815 | | private async Task<Response<bool>> DeleteIfExistsInternal( |
| | 816 | | bool includeSnapshots, |
| | 817 | | bool async, |
| | 818 | | CancellationToken cancellationToken) |
| | 819 | | { |
| 6 | 820 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 821 | | { |
| | 822 | | Pipeline.LogMethodEnter( |
| | 823 | | nameof(ShareClient), |
| | 824 | | message: |
| | 825 | | $"{nameof(Uri)}: {Uri}"); |
| | 826 | | try |
| | 827 | | { |
| 6 | 828 | | Response response = await DeleteInternal( |
| 6 | 829 | | includeSnapshots, |
| 6 | 830 | | async, |
| 6 | 831 | | cancellationToken, |
| 6 | 832 | | $"{nameof(ShareClient)}.{nameof(DeleteIfExists)}") |
| 6 | 833 | | .ConfigureAwait(false); |
| 2 | 834 | | return Response.FromValue(true, response); |
| | 835 | | } |
| | 836 | | catch (RequestFailedException storageRequestFailedException) |
| 4 | 837 | | when (storageRequestFailedException.ErrorCode == ShareErrorCode.ShareNotFound) |
| | 838 | | { |
| 2 | 839 | | return Response.FromValue(false, default); |
| | 840 | | } |
| 2 | 841 | | catch (Exception ex) |
| | 842 | | { |
| | 843 | | Pipeline.LogException(ex); |
| 2 | 844 | | throw; |
| | 845 | | } |
| | 846 | | finally |
| | 847 | | { |
| | 848 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 849 | | } |
| | 850 | | } |
| 4 | 851 | | } |
| | 852 | | #endregion Delete If Exists |
| | 853 | |
|
| | 854 | | #region CreateSnapshot |
| | 855 | | /// <summary> |
| | 856 | | /// Creates a read-only snapshot of a share. |
| | 857 | | /// |
| | 858 | | /// For more information, see |
| | 859 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/snapshot-share"> |
| | 860 | | /// Snapshot Share</see>. |
| | 861 | | /// </summary> |
| | 862 | | /// <param name="metadata"> |
| | 863 | | /// Optional custom metadata to set for this share. |
| | 864 | | /// </param> |
| | 865 | | /// <param name="cancellationToken"> |
| | 866 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 867 | | /// notifications that the operation should be cancelled. |
| | 868 | | /// </param> |
| | 869 | | /// <returns> |
| | 870 | | /// A <see cref="Response{ShareSnapshotInfo}"/> describing the newly |
| | 871 | | /// created snapshot. |
| | 872 | | /// </returns> |
| | 873 | | /// <remarks> |
| | 874 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 875 | | /// a failure occurs. |
| | 876 | | /// </remarks> |
| | 877 | | public virtual Response<ShareSnapshotInfo> CreateSnapshot( |
| | 878 | | Metadata metadata = default, |
| | 879 | | CancellationToken cancellationToken = default) => |
| 6 | 880 | | CreateSnapshotInternal( |
| 6 | 881 | | metadata, |
| 6 | 882 | | false, // async |
| 6 | 883 | | cancellationToken) |
| 6 | 884 | | .EnsureCompleted(); |
| | 885 | |
|
| | 886 | | /// <summary> |
| | 887 | | /// Creates a read-only snapshot of a share. |
| | 888 | | /// |
| | 889 | | /// For more information, see |
| | 890 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/snapshot-share"> |
| | 891 | | /// Snapshot Share</see>. |
| | 892 | | /// </summary> |
| | 893 | | /// <param name="metadata"> |
| | 894 | | /// Optional custom metadata to set for this share. |
| | 895 | | /// </param> |
| | 896 | | /// <param name="cancellationToken"> |
| | 897 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 898 | | /// notifications that the operation should be cancelled. |
| | 899 | | /// </param> |
| | 900 | | /// <returns> |
| | 901 | | /// A <see cref="Response{ShareSnapshotInfo}"/> describing the newly |
| | 902 | | /// created snapshot. |
| | 903 | | /// </returns> |
| | 904 | | /// <remarks> |
| | 905 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 906 | | /// a failure occurs. |
| | 907 | | /// </remarks> |
| | 908 | | public virtual async Task<Response<ShareSnapshotInfo>> CreateSnapshotAsync( |
| | 909 | | Metadata metadata = default, |
| | 910 | | CancellationToken cancellationToken = default) => |
| 6 | 911 | | await CreateSnapshotInternal( |
| 6 | 912 | | metadata, |
| 6 | 913 | | true, // async |
| 6 | 914 | | cancellationToken) |
| 6 | 915 | | .ConfigureAwait(false); |
| | 916 | |
|
| | 917 | | /// <summary> |
| | 918 | | /// Creates a read-only snapshot of a share. |
| | 919 | | /// |
| | 920 | | /// For more information, see |
| | 921 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/snapshot-share"> |
| | 922 | | /// Snapshot Share</see>. |
| | 923 | | /// </summary> |
| | 924 | | /// <param name="metadata"> |
| | 925 | | /// Optional custom metadata to set for this share. |
| | 926 | | /// </param> |
| | 927 | | /// <param name="async"> |
| | 928 | | /// Whether to invoke the operation asynchronously. |
| | 929 | | /// </param> |
| | 930 | | /// <param name="cancellationToken"> |
| | 931 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 932 | | /// notifications that the operation should be cancelled. |
| | 933 | | /// </param> |
| | 934 | | /// <returns> |
| | 935 | | /// A <see cref="Response{ShareSnapshotInfo}"/> describing the newly |
| | 936 | | /// created snapshot. |
| | 937 | | /// </returns> |
| | 938 | | /// <remarks> |
| | 939 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 940 | | /// a failure occurs. |
| | 941 | | /// </remarks> |
| | 942 | | private async Task<Response<ShareSnapshotInfo>> CreateSnapshotInternal( |
| | 943 | | Metadata metadata, |
| | 944 | | bool async, |
| | 945 | | CancellationToken cancellationToken) |
| | 946 | | { |
| 12 | 947 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 948 | | { |
| | 949 | | Pipeline.LogMethodEnter( |
| | 950 | | nameof(ShareClient), |
| | 951 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 952 | | try |
| | 953 | | { |
| 12 | 954 | | return await FileRestClient.Share.CreateSnapshotAsync( |
| 12 | 955 | | ClientDiagnostics, |
| 12 | 956 | | Pipeline, |
| 12 | 957 | | Uri, |
| 12 | 958 | | version: Version.ToVersionString(), |
| 12 | 959 | | metadata: metadata, |
| 12 | 960 | | async: async, |
| 12 | 961 | | operationName: $"{nameof(ShareClient)}.{nameof(CreateSnapshot)}", |
| 12 | 962 | | cancellationToken: cancellationToken) |
| 12 | 963 | | .ConfigureAwait(false); |
| | 964 | | } |
| 2 | 965 | | catch (Exception ex) |
| | 966 | | { |
| | 967 | | Pipeline.LogException(ex); |
| 2 | 968 | | throw; |
| | 969 | | } |
| | 970 | | finally |
| | 971 | | { |
| | 972 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 973 | | } |
| | 974 | | } |
| 10 | 975 | | } |
| | 976 | | #endregion CreateSnapshot |
| | 977 | |
|
| | 978 | | #region Delete |
| | 979 | | /// <summary> |
| | 980 | | /// Marks the specified share or share snapshot for deletion. |
| | 981 | | /// The share or share snapshot and any files contained within it are later deleted during garbage collection. |
| | 982 | | /// |
| | 983 | | /// For more information, see |
| | 984 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-share"> |
| | 985 | | /// Delete Share</see>. |
| | 986 | | /// </summary> |
| | 987 | | /// <param name="includeSnapshots"> |
| | 988 | | /// A value indicating whether to delete a share's snapshots in addition |
| | 989 | | /// to the share itself. |
| | 990 | | /// </param> |
| | 991 | | /// <param name="cancellationToken"> |
| | 992 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 993 | | /// notifications that the operation should be cancelled. |
| | 994 | | /// </param> |
| | 995 | | /// <returns> |
| | 996 | | /// A <see cref="Response"/> on successfully deleting. |
| | 997 | | /// </returns> |
| | 998 | | /// <remarks> |
| | 999 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1000 | | /// a failure occurs. |
| | 1001 | | /// </remarks> |
| | 1002 | | public virtual Response Delete( |
| | 1003 | | bool includeSnapshots = true, |
| | 1004 | | CancellationToken cancellationToken = default) => |
| 220 | 1005 | | DeleteInternal( |
| 220 | 1006 | | includeSnapshots, |
| 220 | 1007 | | false, // async |
| 220 | 1008 | | cancellationToken) |
| 220 | 1009 | | .EnsureCompleted(); |
| | 1010 | |
|
| | 1011 | | /// <summary> |
| | 1012 | | /// Marks the specified share or share snapshot for deletion. |
| | 1013 | | /// The share or share snapshot and any files contained within it are later deleted during garbage collection. |
| | 1014 | | /// |
| | 1015 | | /// For more information, see |
| | 1016 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-share"> |
| | 1017 | | /// Delete Share</see>. |
| | 1018 | | /// </summary> |
| | 1019 | | /// <param name="includeSnapshots"> |
| | 1020 | | /// A value indicating whether to delete a share's snapshots in addition |
| | 1021 | | /// to the share itself. |
| | 1022 | | /// </param> |
| | 1023 | | /// <param name="cancellationToken"> |
| | 1024 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1025 | | /// notifications that the operation should be cancelled. |
| | 1026 | | /// </param> |
| | 1027 | | /// <returns> |
| | 1028 | | /// A <see cref="Response"/> on successfully deleting. |
| | 1029 | | /// </returns> |
| | 1030 | | /// <remarks> |
| | 1031 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1032 | | /// a failure occurs. |
| | 1033 | | /// </remarks> |
| | 1034 | | public virtual async Task<Response> DeleteAsync( |
| | 1035 | | bool includeSnapshots = true, |
| | 1036 | | CancellationToken cancellationToken = default) => |
| 221 | 1037 | | await DeleteInternal( |
| 221 | 1038 | | includeSnapshots, |
| 221 | 1039 | | true, // async |
| 221 | 1040 | | cancellationToken) |
| 221 | 1041 | | .ConfigureAwait(false); |
| | 1042 | |
|
| | 1043 | | /// <summary> |
| | 1044 | | /// Marks the specified share or share snapshot for deletion. |
| | 1045 | | /// The share or share snapshot and any files contained within it are later deleted during garbage collection. |
| | 1046 | | /// |
| | 1047 | | /// For more information, see |
| | 1048 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-share"> |
| | 1049 | | /// Delete Share</see>. |
| | 1050 | | /// </summary> |
| | 1051 | | /// <param name="includeSnapshots"> |
| | 1052 | | /// A value indicating whether to delete a share's snapshots in addition |
| | 1053 | | /// to the share itself. |
| | 1054 | | /// </param> |
| | 1055 | | /// <param name="async"> |
| | 1056 | | /// Whether to invoke the operation asynchronously. |
| | 1057 | | /// </param> |
| | 1058 | | /// <param name="cancellationToken"> |
| | 1059 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1060 | | /// notifications that the operation should be cancelled. |
| | 1061 | | /// </param> |
| | 1062 | | /// <param name="operationName"> |
| | 1063 | | /// Optional. To indicate if the name of the operation. |
| | 1064 | | /// </param> |
| | 1065 | | /// <returns> |
| | 1066 | | /// A <see cref="Response"/> on successfully deleting. |
| | 1067 | | /// </returns> |
| | 1068 | | /// <remarks> |
| | 1069 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1070 | | /// a failure occurs. |
| | 1071 | | /// </remarks> |
| | 1072 | | internal async Task<Response> DeleteInternal( |
| | 1073 | | bool includeSnapshots, |
| | 1074 | | bool async, |
| | 1075 | | CancellationToken cancellationToken, |
| | 1076 | | string operationName = default) |
| | 1077 | | { |
| 451 | 1078 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 1079 | | { |
| | 1080 | | Pipeline.LogMethodEnter( |
| | 1081 | | nameof(ShareClient), |
| | 1082 | | message: |
| | 1083 | | $"{nameof(Uri)}: {Uri}"); |
| | 1084 | | try |
| | 1085 | | { |
| 451 | 1086 | | return await FileRestClient.Share.DeleteAsync( |
| 451 | 1087 | | ClientDiagnostics, |
| 451 | 1088 | | Pipeline, |
| 451 | 1089 | | Uri, |
| 451 | 1090 | | version: Version.ToVersionString(), |
| 451 | 1091 | | deleteSnapshots: includeSnapshots ? DeleteSnapshotsOptionType.Include : (DeleteSnapshotsOptionTy |
| 451 | 1092 | | async: async, |
| 451 | 1093 | | operationName: operationName ?? $"{nameof(ShareClient)}.{nameof(Delete)}", |
| 451 | 1094 | | cancellationToken: cancellationToken) |
| 451 | 1095 | | .ConfigureAwait(false); |
| | 1096 | | } |
| 10 | 1097 | | catch (Exception ex) |
| | 1098 | | { |
| | 1099 | | Pipeline.LogException(ex); |
| 10 | 1100 | | throw; |
| | 1101 | | } |
| | 1102 | | finally |
| | 1103 | | { |
| | 1104 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 1105 | | } |
| | 1106 | | } |
| 441 | 1107 | | } |
| | 1108 | | #endregion Delete |
| | 1109 | |
|
| | 1110 | | #region GetProperties |
| | 1111 | | /// <summary> |
| | 1112 | | /// The <see cref="GetProperties"/> operation returns all |
| | 1113 | | /// user-defined metadata, standard HTTP properties, and system |
| | 1114 | | /// properties for the share. |
| | 1115 | | /// |
| | 1116 | | /// For more information, see |
| | 1117 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-share-properties"> |
| | 1118 | | /// Get Share Properties</see>. |
| | 1119 | | /// </summary> |
| | 1120 | | /// <param name="cancellationToken"> |
| | 1121 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1122 | | /// notifications that the operation should be cancelled. |
| | 1123 | | /// </param> |
| | 1124 | | /// <returns> |
| | 1125 | | /// A <see cref="Response{ShareProperties}"/> describing the |
| | 1126 | | /// share's properties. |
| | 1127 | | /// </returns> |
| | 1128 | | /// <remarks> |
| | 1129 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1130 | | /// a failure occurs. |
| | 1131 | | /// </remarks> |
| | 1132 | | public virtual Response<ShareProperties> GetProperties( |
| | 1133 | | CancellationToken cancellationToken = default) => |
| 10 | 1134 | | GetPropertiesInternal( |
| 10 | 1135 | | false, // async |
| 10 | 1136 | | cancellationToken) |
| 10 | 1137 | | .EnsureCompleted(); |
| | 1138 | |
|
| | 1139 | | /// <summary> |
| | 1140 | | /// The <see cref="GetPropertiesAsync"/> operation returns all |
| | 1141 | | /// user-defined metadata, standard HTTP properties, and system |
| | 1142 | | /// properties for the share. |
| | 1143 | | /// |
| | 1144 | | /// For more information, see |
| | 1145 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-share-properties"> |
| | 1146 | | /// Get Share Properties</see>. |
| | 1147 | | /// </summary> |
| | 1148 | | /// <param name="cancellationToken"> |
| | 1149 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1150 | | /// notifications that the operation should be cancelled. |
| | 1151 | | /// </param> |
| | 1152 | | /// <returns> |
| | 1153 | | /// A <see cref="Response{ShareProperties}"/> describing the |
| | 1154 | | /// share's properties. |
| | 1155 | | /// </returns> |
| | 1156 | | /// <remarks> |
| | 1157 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1158 | | /// a failure occurs. |
| | 1159 | | /// </remarks> |
| | 1160 | | public virtual async Task<Response<ShareProperties>> GetPropertiesAsync( |
| | 1161 | | CancellationToken cancellationToken = default) => |
| 16 | 1162 | | await GetPropertiesInternal( |
| 16 | 1163 | | true, // async |
| 16 | 1164 | | cancellationToken) |
| 16 | 1165 | | .ConfigureAwait(false); |
| | 1166 | |
|
| | 1167 | | /// <summary> |
| | 1168 | | /// The <see cref="GetPropertiesInternal"/> operation returns all |
| | 1169 | | /// user-defined metadata, standard HTTP properties, and system |
| | 1170 | | /// properties for the share. |
| | 1171 | | /// |
| | 1172 | | /// For more information, see |
| | 1173 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-share-properties"> |
| | 1174 | | /// Get Share Properties</see>. |
| | 1175 | | /// </summary> |
| | 1176 | | /// <param name="async"> |
| | 1177 | | /// Whether to invoke the operation asynchronously. |
| | 1178 | | /// </param> |
| | 1179 | | /// <param name="cancellationToken"> |
| | 1180 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1181 | | /// notifications that the operation should be cancelled. |
| | 1182 | | /// </param> |
| | 1183 | | /// <returns> |
| | 1184 | | /// A <see cref="Response{ShareProperties}"/> describing the |
| | 1185 | | /// share's properties. |
| | 1186 | | /// </returns> |
| | 1187 | | /// <remarks> |
| | 1188 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1189 | | /// a failure occurs. |
| | 1190 | | /// </remarks> |
| | 1191 | | private async Task<Response<ShareProperties>> GetPropertiesInternal( |
| | 1192 | | bool async, |
| | 1193 | | CancellationToken cancellationToken) |
| | 1194 | | { |
| 26 | 1195 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 1196 | | { |
| | 1197 | | Pipeline.LogMethodEnter( |
| | 1198 | | nameof(ShareClient), |
| | 1199 | | message: |
| | 1200 | | $"{nameof(Uri)}: {Uri}"); |
| | 1201 | | try |
| | 1202 | | { |
| 26 | 1203 | | return await FileRestClient.Share.GetPropertiesAsync( |
| 26 | 1204 | | ClientDiagnostics, |
| 26 | 1205 | | Pipeline, |
| 26 | 1206 | | Uri, |
| 26 | 1207 | | version: Version.ToVersionString(), |
| 26 | 1208 | | async: async, |
| 26 | 1209 | | operationName: $"{nameof(ShareClient)}.{nameof(GetProperties)}", |
| 26 | 1210 | | cancellationToken: cancellationToken) |
| 26 | 1211 | | .ConfigureAwait(false); |
| | 1212 | | } |
| 8 | 1213 | | catch (Exception ex) |
| | 1214 | | { |
| | 1215 | | Pipeline.LogException(ex); |
| 8 | 1216 | | throw; |
| | 1217 | | } |
| | 1218 | | finally |
| | 1219 | | { |
| | 1220 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 1221 | | } |
| | 1222 | | } |
| 18 | 1223 | | } |
| | 1224 | | #endregion GetProperties |
| | 1225 | |
|
| | 1226 | | #region SetQuota |
| | 1227 | | /// <summary> |
| | 1228 | | /// Sets the maximum size of the share. |
| | 1229 | | /// |
| | 1230 | | /// For more information, see |
| | 1231 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-properties"> |
| | 1232 | | /// Set Share Properties</see>. |
| | 1233 | | /// </summary> |
| | 1234 | | /// <param name="quotaInGB"> |
| | 1235 | | /// Optional. The maximum size of the share. |
| | 1236 | | /// If unspecified, use the service's default value. |
| | 1237 | | /// </param> |
| | 1238 | | /// <param name="cancellationToken"> |
| | 1239 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1240 | | /// notifications that the operation should be cancelled. |
| | 1241 | | /// </param> |
| | 1242 | | /// <returns> |
| | 1243 | | /// A <see cref="Response{ShareInfo}"/> describing the updated |
| | 1244 | | /// share. |
| | 1245 | | /// </returns> |
| | 1246 | | /// <remarks> |
| | 1247 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1248 | | /// a failure occurs. |
| | 1249 | | /// </remarks> |
| | 1250 | | public virtual Response<ShareInfo> SetQuota( |
| | 1251 | | int quotaInGB = default, |
| | 1252 | | CancellationToken cancellationToken = default) => |
| 2 | 1253 | | SetQuotaInternal( |
| 2 | 1254 | | quotaInGB, |
| 2 | 1255 | | false, // async |
| 2 | 1256 | | cancellationToken) |
| 2 | 1257 | | .EnsureCompleted(); |
| | 1258 | |
|
| | 1259 | | /// <summary> |
| | 1260 | | /// Sets the maximum size of the share. |
| | 1261 | | /// |
| | 1262 | | /// For more information, see |
| | 1263 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-properties"> |
| | 1264 | | /// Set Share Properties</see>. |
| | 1265 | | /// </summary> |
| | 1266 | | /// <param name="quotaInGB"> |
| | 1267 | | /// Optional. The maximum size of the share. |
| | 1268 | | /// If unspecified, use the service's default value. |
| | 1269 | | /// </param> |
| | 1270 | | /// <param name="cancellationToken"> |
| | 1271 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1272 | | /// notifications that the operation should be cancelled. |
| | 1273 | | /// </param> |
| | 1274 | | /// <returns> |
| | 1275 | | /// A <see cref="Response{ShareInfo}"/> describing the updated |
| | 1276 | | /// share. |
| | 1277 | | /// </returns> |
| | 1278 | | /// <remarks> |
| | 1279 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1280 | | /// a failure occurs. |
| | 1281 | | /// </remarks> |
| | 1282 | | public virtual async Task<Response<ShareInfo>> SetQuotaAsync( |
| | 1283 | | int quotaInGB = default, |
| | 1284 | | CancellationToken cancellationToken = default) => |
| 2 | 1285 | | await SetQuotaInternal( |
| 2 | 1286 | | quotaInGB, |
| 2 | 1287 | | true, // async |
| 2 | 1288 | | cancellationToken) |
| 2 | 1289 | | .ConfigureAwait(false); |
| | 1290 | |
|
| | 1291 | | /// <summary> |
| | 1292 | | /// Sets the maximum size of the share. |
| | 1293 | | /// |
| | 1294 | | /// For more information, see |
| | 1295 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-properties"> |
| | 1296 | | /// Set Share Properties</see>. |
| | 1297 | | /// </summary> |
| | 1298 | | /// <param name="quotaInGB"> |
| | 1299 | | /// Optional. The maximum size of the share. |
| | 1300 | | /// If unspecified, use the service's default value. |
| | 1301 | | /// </param> |
| | 1302 | | /// <param name="async"> |
| | 1303 | | /// Whether to invoke the operation asynchronously. |
| | 1304 | | /// </param> |
| | 1305 | | /// <param name="cancellationToken"> |
| | 1306 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1307 | | /// notifications that the operation should be cancelled. |
| | 1308 | | /// </param> |
| | 1309 | | /// <returns> |
| | 1310 | | /// A <see cref="Response{ShareInfo}"/> describing the updated |
| | 1311 | | /// share. |
| | 1312 | | /// </returns> |
| | 1313 | | /// <remarks> |
| | 1314 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1315 | | /// a failure occurs. |
| | 1316 | | /// </remarks> |
| | 1317 | | internal virtual async Task<Response<ShareInfo>> SetQuotaInternal( |
| | 1318 | | int quotaInGB, |
| | 1319 | | bool async, |
| | 1320 | | CancellationToken cancellationToken) |
| | 1321 | | { |
| 4 | 1322 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 1323 | | { |
| | 1324 | | Pipeline.LogMethodEnter( |
| | 1325 | | nameof(ShareClient), |
| | 1326 | | message: |
| | 1327 | | $"{nameof(Uri)}: {Uri}\n" + |
| | 1328 | | $"{nameof(quotaInGB)}: {quotaInGB}"); |
| | 1329 | | try |
| | 1330 | | { |
| 4 | 1331 | | return await FileRestClient.Share.SetQuotaAsync( |
| 4 | 1332 | | ClientDiagnostics, |
| 4 | 1333 | | Pipeline, |
| 4 | 1334 | | Uri, |
| 4 | 1335 | | version: Version.ToVersionString(), |
| 4 | 1336 | | quotaInGB: quotaInGB, |
| 4 | 1337 | | async: async, |
| 4 | 1338 | | operationName: $"{nameof(ShareClient)}.{nameof(SetQuota)}", |
| 4 | 1339 | | cancellationToken: cancellationToken) |
| 4 | 1340 | | .ConfigureAwait(false); |
| | 1341 | | } |
| 2 | 1342 | | catch (Exception ex) |
| | 1343 | | { |
| | 1344 | | Pipeline.LogException(ex); |
| 2 | 1345 | | throw; |
| | 1346 | | } |
| | 1347 | | finally |
| | 1348 | | { |
| | 1349 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 1350 | | } |
| | 1351 | | } |
| 2 | 1352 | | } |
| | 1353 | | #endregion SetQuota |
| | 1354 | |
|
| | 1355 | | #region SetMetadata |
| | 1356 | | /// <summary> |
| | 1357 | | /// The <see cref="SetMetadata"/> operation sets user-defined |
| | 1358 | | /// metadata for the specified share as one or more name-value pairs. |
| | 1359 | | /// |
| | 1360 | | /// For more information, see |
| | 1361 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-metadata"> |
| | 1362 | | /// Set Share Metadata</see>. |
| | 1363 | | /// </summary> |
| | 1364 | | /// <param name="metadata"> |
| | 1365 | | /// Custom metadata to set for this share. |
| | 1366 | | /// </param> |
| | 1367 | | /// <param name="cancellationToken"> |
| | 1368 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1369 | | /// notifications that the operation should be cancelled. |
| | 1370 | | /// </param> |
| | 1371 | | /// <returns> |
| | 1372 | | /// A <see cref="Response{ShareInfo}"/> describing the updated |
| | 1373 | | /// share. |
| | 1374 | | /// </returns> |
| | 1375 | | /// <remarks> |
| | 1376 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1377 | | /// a failure occurs. |
| | 1378 | | /// </remarks> |
| | 1379 | | public virtual Response<ShareInfo> SetMetadata( |
| | 1380 | | Metadata metadata, |
| | 1381 | | CancellationToken cancellationToken = default) => |
| 2 | 1382 | | SetMetadataInternal( |
| 2 | 1383 | | metadata, |
| 2 | 1384 | | false, // async |
| 2 | 1385 | | cancellationToken) |
| 2 | 1386 | | .EnsureCompleted(); |
| | 1387 | |
|
| | 1388 | | /// <summary> |
| | 1389 | | /// The <see cref="SetMetadataAsync"/> operation sets user-defined |
| | 1390 | | /// metadata for the specified share as one or more name-value pairs. |
| | 1391 | | /// |
| | 1392 | | /// For more information, see |
| | 1393 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-metadata"> |
| | 1394 | | /// Set Share Metadata</see>. |
| | 1395 | | /// </summary> |
| | 1396 | | /// <param name="metadata"> |
| | 1397 | | /// Custom metadata to set for this share. |
| | 1398 | | /// </param> |
| | 1399 | | /// <param name="cancellationToken"> |
| | 1400 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1401 | | /// notifications that the operation should be cancelled. |
| | 1402 | | /// </param> |
| | 1403 | | /// <returns> |
| | 1404 | | /// A <see cref="Response{ShareInfo}"/> describing the updated |
| | 1405 | | /// share. |
| | 1406 | | /// </returns> |
| | 1407 | | /// <remarks> |
| | 1408 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1409 | | /// a failure occurs. |
| | 1410 | | /// </remarks> |
| | 1411 | | public virtual async Task<Response<ShareInfo>> SetMetadataAsync( |
| | 1412 | | Metadata metadata, |
| | 1413 | | CancellationToken cancellationToken = default) => |
| 2 | 1414 | | await SetMetadataInternal( |
| 2 | 1415 | | metadata, |
| 2 | 1416 | | true, // async |
| 2 | 1417 | | cancellationToken) |
| 2 | 1418 | | .ConfigureAwait(false); |
| | 1419 | |
|
| | 1420 | | /// <summary> |
| | 1421 | | /// The <see cref="SetMetadataInternal"/> operation sets user-defined |
| | 1422 | | /// metadata for the specified share as one or more name-value pairs. |
| | 1423 | | /// |
| | 1424 | | /// For more information, see |
| | 1425 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-metadata"> |
| | 1426 | | /// Set Share Metadata</see>. |
| | 1427 | | /// </summary> |
| | 1428 | | /// <param name="metadata"> |
| | 1429 | | /// Custom metadata to set for this share. |
| | 1430 | | /// </param> |
| | 1431 | | /// <param name="async"> |
| | 1432 | | /// Whether to invoke the operation asynchronously. |
| | 1433 | | /// </param> |
| | 1434 | | /// <param name="cancellationToken"> |
| | 1435 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1436 | | /// notifications that the operation should be cancelled. |
| | 1437 | | /// </param> |
| | 1438 | | /// <returns> |
| | 1439 | | /// A <see cref="Response{ShareInfo}"/> describing the updated |
| | 1440 | | /// share. |
| | 1441 | | /// </returns> |
| | 1442 | | /// <remarks> |
| | 1443 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1444 | | /// a failure occurs. |
| | 1445 | | /// </remarks> |
| | 1446 | | private async Task<Response<ShareInfo>> SetMetadataInternal( |
| | 1447 | | Metadata metadata, |
| | 1448 | | bool async, |
| | 1449 | | CancellationToken cancellationToken) |
| | 1450 | | { |
| 4 | 1451 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 1452 | | { |
| | 1453 | | Pipeline.LogMethodEnter( |
| | 1454 | | nameof(ShareClient), |
| | 1455 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 1456 | | try |
| | 1457 | | { |
| 4 | 1458 | | return await FileRestClient.Share.SetMetadataAsync( |
| 4 | 1459 | | ClientDiagnostics, |
| 4 | 1460 | | Pipeline, |
| 4 | 1461 | | Uri, |
| 4 | 1462 | | version: Version.ToVersionString(), |
| 4 | 1463 | | metadata: metadata, |
| 4 | 1464 | | async: async, |
| 4 | 1465 | | operationName: $"{nameof(ShareClient)}.{nameof(SetMetadata)}", |
| 4 | 1466 | | cancellationToken: cancellationToken) |
| 4 | 1467 | | .ConfigureAwait(false); |
| | 1468 | | } |
| 2 | 1469 | | catch (Exception ex) |
| | 1470 | | { |
| | 1471 | | Pipeline.LogException(ex); |
| 2 | 1472 | | throw; |
| | 1473 | | } |
| | 1474 | | finally |
| | 1475 | | { |
| | 1476 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 1477 | | } |
| | 1478 | | } |
| 2 | 1479 | | } |
| | 1480 | | #endregion SetMetadata |
| | 1481 | |
|
| | 1482 | | #region GetAccessPolicy |
| | 1483 | | /// <summary> |
| | 1484 | | /// The <see cref="GetAccessPolicy"/> operation gets the |
| | 1485 | | /// permissions for this share. The permissions indicate whether |
| | 1486 | | /// share data may be accessed publicly. |
| | 1487 | | /// |
| | 1488 | | /// For more information, see |
| | 1489 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-share-acl"> |
| | 1490 | | /// Get Share ACL</see>. |
| | 1491 | | /// </summary> |
| | 1492 | | /// <param name="cancellationToken"> |
| | 1493 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1494 | | /// notifications that the operation should be cancelled. |
| | 1495 | | /// </param> |
| | 1496 | | /// <returns> |
| | 1497 | | /// A <see cref="Response{T}"/> of <see cref="IEnumerable{SignedIdentifier}"/> |
| | 1498 | | /// describing the share's access policy. |
| | 1499 | | /// </returns> |
| | 1500 | | /// <remarks> |
| | 1501 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1502 | | /// a failure occurs. |
| | 1503 | | /// </remarks> |
| | 1504 | | public virtual Response<IEnumerable<ShareSignedIdentifier>> GetAccessPolicy( |
| | 1505 | | CancellationToken cancellationToken = default) => |
| 5 | 1506 | | GetAccessPolicyInternal( |
| 5 | 1507 | | false, // async |
| 5 | 1508 | | cancellationToken) |
| 5 | 1509 | | .EnsureCompleted(); |
| | 1510 | |
|
| | 1511 | | /// <summary> |
| | 1512 | | /// The <see cref="GetAccessPolicyAsync"/> operation gets the |
| | 1513 | | /// permissions for this share. The permissions indicate whether |
| | 1514 | | /// share data may be accessed publicly. |
| | 1515 | | /// |
| | 1516 | | /// For more information, see |
| | 1517 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-share-acl"> |
| | 1518 | | /// Get Share ACL</see>. |
| | 1519 | | /// </summary> |
| | 1520 | | /// <param name="cancellationToken"> |
| | 1521 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1522 | | /// notifications that the operation should be cancelled. |
| | 1523 | | /// </param> |
| | 1524 | | /// <returns> |
| | 1525 | | /// A <see cref="Response{T}"/> of <see cref="IEnumerable{FileSignedIdentifier}"/> |
| | 1526 | | /// describing the share's access policy. |
| | 1527 | | /// </returns> |
| | 1528 | | /// <remarks> |
| | 1529 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1530 | | /// a failure occurs. |
| | 1531 | | /// </remarks> |
| | 1532 | | public virtual async Task<Response<IEnumerable<ShareSignedIdentifier>>> GetAccessPolicyAsync( |
| | 1533 | | CancellationToken cancellationToken = default) => |
| 5 | 1534 | | await GetAccessPolicyInternal( |
| 5 | 1535 | | true, // async |
| 5 | 1536 | | cancellationToken) |
| 5 | 1537 | | .ConfigureAwait(false); |
| | 1538 | |
|
| | 1539 | | /// <summary> |
| | 1540 | | /// The <see cref="GetAccessPolicyInternal"/> operation gets the |
| | 1541 | | /// permissions for this share. The permissions indicate whether |
| | 1542 | | /// share data may be accessed publicly. |
| | 1543 | | /// |
| | 1544 | | /// For more information, see |
| | 1545 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-share-acl"> |
| | 1546 | | /// Get Share ACL</see>. |
| | 1547 | | /// </summary> |
| | 1548 | | /// <param name="async"> |
| | 1549 | | /// Whether to invoke the operation asynchronously. |
| | 1550 | | /// </param> |
| | 1551 | | /// <param name="cancellationToken"> |
| | 1552 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1553 | | /// notifications that the operation should be cancelled. |
| | 1554 | | /// </param> |
| | 1555 | | /// <returns> |
| | 1556 | | /// A <see cref="Response{T}"/> of <see cref="IEnumerable{FileSignedIdentifier}"/> |
| | 1557 | | /// describing the share's access policy. |
| | 1558 | | /// </returns> |
| | 1559 | | /// <remarks> |
| | 1560 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1561 | | /// a failure occurs. |
| | 1562 | | /// </remarks> |
| | 1563 | | private async Task<Response<IEnumerable<ShareSignedIdentifier>>> GetAccessPolicyInternal( |
| | 1564 | | bool async, |
| | 1565 | | CancellationToken cancellationToken) |
| | 1566 | | { |
| 10 | 1567 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 1568 | | { |
| | 1569 | | Pipeline.LogMethodEnter( |
| | 1570 | | nameof(ShareClient), |
| | 1571 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 1572 | | try |
| | 1573 | | { |
| 10 | 1574 | | return await FileRestClient.Share.GetAccessPolicyAsync( |
| 10 | 1575 | | ClientDiagnostics, |
| 10 | 1576 | | Pipeline, |
| 10 | 1577 | | Uri, |
| 10 | 1578 | | version: Version.ToVersionString(), |
| 10 | 1579 | | async: async, |
| 10 | 1580 | | operationName: $"{nameof(ShareClient)}.{nameof(GetAccessPolicy)}", |
| 10 | 1581 | | cancellationToken: cancellationToken) |
| 10 | 1582 | | .ConfigureAwait(false); |
| | 1583 | | } |
| 2 | 1584 | | catch (Exception ex) |
| | 1585 | | { |
| | 1586 | | Pipeline.LogException(ex); |
| 2 | 1587 | | throw; |
| | 1588 | | } |
| | 1589 | | finally |
| | 1590 | | { |
| | 1591 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 1592 | | } |
| | 1593 | | } |
| 8 | 1594 | | } |
| | 1595 | | #endregion GetAccessPolicy |
| | 1596 | |
|
| | 1597 | | #region SetAccessPolicy |
| | 1598 | | /// <summary> |
| | 1599 | | /// The <see cref="SetAccessPolicy"/> operation sets the |
| | 1600 | | /// permissions for the specified share. The permissions indicate |
| | 1601 | | /// whether share data may be accessed publicly. |
| | 1602 | | /// |
| | 1603 | | /// For more information, see |
| | 1604 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-acl"> |
| | 1605 | | /// Set Share ACL</see>. |
| | 1606 | | /// </summary> |
| | 1607 | | /// <param name="permissions"> |
| | 1608 | | /// Stored access policies that you can use to provide fine grained |
| | 1609 | | /// control over share permissions. |
| | 1610 | | /// </param> |
| | 1611 | | /// <param name="cancellationToken"> |
| | 1612 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1613 | | /// notifications that the operation should be cancelled. |
| | 1614 | | /// </param> |
| | 1615 | | /// <returns> |
| | 1616 | | /// A <see cref="Response{ShareInfo}"/> describing the |
| | 1617 | | /// updated share. |
| | 1618 | | /// </returns> |
| | 1619 | | /// <remarks> |
| | 1620 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1621 | | /// a failure occurs. |
| | 1622 | | /// </remarks> |
| | 1623 | | public virtual Response<ShareInfo> SetAccessPolicy( |
| | 1624 | | IEnumerable<ShareSignedIdentifier> permissions, |
| | 1625 | | CancellationToken cancellationToken = default) => |
| 7 | 1626 | | SetAccessPolicyInternal( |
| 7 | 1627 | | permissions, |
| 7 | 1628 | | false, // async |
| 7 | 1629 | | cancellationToken) |
| 7 | 1630 | | .EnsureCompleted(); |
| | 1631 | |
|
| | 1632 | | /// <summary> |
| | 1633 | | /// The <see cref="SetAccessPolicyAsync"/> operation sets the |
| | 1634 | | /// permissions for the specified share. The permissions indicate |
| | 1635 | | /// whether share data may be accessed publicly. |
| | 1636 | | /// |
| | 1637 | | /// For more information, see |
| | 1638 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-acl"> |
| | 1639 | | /// Set Share ACL</see>. |
| | 1640 | | /// </summary> |
| | 1641 | | /// <param name="permissions"> |
| | 1642 | | /// Stored access policies that you can use to provide fine grained |
| | 1643 | | /// control over share permissions. |
| | 1644 | | /// </param> |
| | 1645 | | /// <param name="cancellationToken"> |
| | 1646 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1647 | | /// notifications that the operation should be cancelled. |
| | 1648 | | /// </param> |
| | 1649 | | /// <returns> |
| | 1650 | | /// A <see cref="Response{ShareInfo}"/> describing the |
| | 1651 | | /// updated share. |
| | 1652 | | /// </returns> |
| | 1653 | | /// <remarks> |
| | 1654 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1655 | | /// a failure occurs. |
| | 1656 | | /// </remarks> |
| | 1657 | | public virtual async Task<Response<ShareInfo>> SetAccessPolicyAsync( |
| | 1658 | | IEnumerable<ShareSignedIdentifier> permissions, |
| | 1659 | | CancellationToken cancellationToken = default) => |
| 7 | 1660 | | await SetAccessPolicyInternal( |
| 7 | 1661 | | permissions, |
| 7 | 1662 | | true, // async |
| 7 | 1663 | | cancellationToken) |
| 7 | 1664 | | .ConfigureAwait(false); |
| | 1665 | |
|
| | 1666 | | /// <summary> |
| | 1667 | | /// The <see cref="SetAccessPolicyInternal"/> operation sets the |
| | 1668 | | /// permissions for the specified share. The permissions indicate |
| | 1669 | | /// whether share data may be accessed publicly. |
| | 1670 | | /// |
| | 1671 | | /// For more information, see |
| | 1672 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-acl"> |
| | 1673 | | /// Set Share ACL</see>. |
| | 1674 | | /// </summary> |
| | 1675 | | /// <param name="permissions"> |
| | 1676 | | /// Stored access policies that you can use to provide fine grained |
| | 1677 | | /// control over share permissions. |
| | 1678 | | /// </param> |
| | 1679 | | /// <param name="async"> |
| | 1680 | | /// Whether to invoke the operation asynchronously. |
| | 1681 | | /// </param> |
| | 1682 | | /// <param name="cancellationToken"> |
| | 1683 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1684 | | /// notifications that the operation should be cancelled. |
| | 1685 | | /// </param> |
| | 1686 | | /// <returns> |
| | 1687 | | /// A <see cref="Response{ShareInfo}"/> describing the |
| | 1688 | | /// updated share. |
| | 1689 | | /// </returns> |
| | 1690 | | /// <remarks> |
| | 1691 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1692 | | /// a failure occurs. |
| | 1693 | | /// </remarks> |
| | 1694 | | private async Task<Response<ShareInfo>> SetAccessPolicyInternal( |
| | 1695 | | IEnumerable<ShareSignedIdentifier> permissions, |
| | 1696 | | bool async, |
| | 1697 | | CancellationToken cancellationToken) |
| | 1698 | | { |
| 14 | 1699 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 1700 | | { |
| | 1701 | | Pipeline.LogMethodEnter( |
| | 1702 | | nameof(ShareClient), |
| | 1703 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 1704 | | try |
| | 1705 | | { |
| 14 | 1706 | | return await FileRestClient.Share.SetAccessPolicyAsync( |
| 14 | 1707 | | ClientDiagnostics, |
| 14 | 1708 | | Pipeline, |
| 14 | 1709 | | Uri, |
| 14 | 1710 | | version: Version.ToVersionString(), |
| 14 | 1711 | | permissions: permissions, |
| 14 | 1712 | | async: async, |
| 14 | 1713 | | operationName: $"{nameof(ShareClient)}.{nameof(SetAccessPolicy)}", |
| 14 | 1714 | | cancellationToken: cancellationToken) |
| 14 | 1715 | | .ConfigureAwait(false); |
| | 1716 | | } |
| 2 | 1717 | | catch (Exception ex) |
| | 1718 | | { |
| | 1719 | | Pipeline.LogException(ex); |
| 2 | 1720 | | throw; |
| | 1721 | | } |
| | 1722 | | finally |
| | 1723 | | { |
| | 1724 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 1725 | | } |
| | 1726 | | } |
| 12 | 1727 | | } |
| | 1728 | | #endregion SetAccessPolicy |
| | 1729 | |
|
| | 1730 | | #region GetStatistics |
| | 1731 | | /// <summary> |
| | 1732 | | /// Retrieves statistics related to the share. |
| | 1733 | | /// |
| | 1734 | | /// For more information, see |
| | 1735 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-share-stats"> |
| | 1736 | | /// Get Share Stats</see>. |
| | 1737 | | /// </summary> |
| | 1738 | | /// <param name="cancellationToken"> |
| | 1739 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1740 | | /// notifications that the operation should be cancelled. |
| | 1741 | | /// </param> |
| | 1742 | | /// <returns> |
| | 1743 | | /// A <see cref="Response{ShareStatistics}"/> describing the |
| | 1744 | | /// share statistics. |
| | 1745 | | /// </returns> |
| | 1746 | | /// <remarks> |
| | 1747 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1748 | | /// a failure occurs. |
| | 1749 | | /// </remarks> |
| | 1750 | | public virtual Response<ShareStatistics> GetStatistics( |
| | 1751 | | CancellationToken cancellationToken = default) => |
| 3 | 1752 | | GetStatisticsInternal( |
| 3 | 1753 | | false, // async |
| 3 | 1754 | | cancellationToken) |
| 3 | 1755 | | .EnsureCompleted(); |
| | 1756 | |
|
| | 1757 | | /// <summary> |
| | 1758 | | /// Retrieves statistics related to the share. |
| | 1759 | | /// |
| | 1760 | | /// For more information, see |
| | 1761 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-share-stats"> |
| | 1762 | | /// Get Share Stats</see>. |
| | 1763 | | /// </summary> |
| | 1764 | | /// <param name="cancellationToken"> |
| | 1765 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1766 | | /// notifications that the operation should be cancelled. |
| | 1767 | | /// </param> |
| | 1768 | | /// <returns> |
| | 1769 | | /// A <see cref="Response{ShareStatistics}"/> describing the |
| | 1770 | | /// share statistics. |
| | 1771 | | /// </returns> |
| | 1772 | | /// <remarks> |
| | 1773 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1774 | | /// a failure occurs. |
| | 1775 | | /// </remarks> |
| | 1776 | | public virtual async Task<Response<ShareStatistics>> GetStatisticsAsync( |
| | 1777 | | CancellationToken cancellationToken = default) => |
| 3 | 1778 | | await GetStatisticsInternal( |
| 3 | 1779 | | true, // async |
| 3 | 1780 | | cancellationToken) |
| 3 | 1781 | | .ConfigureAwait(false); |
| | 1782 | |
|
| | 1783 | | /// <summary> |
| | 1784 | | /// Retrieves statistics related to the share. |
| | 1785 | | /// |
| | 1786 | | /// For more information, see |
| | 1787 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/get-share-stats" |
| | 1788 | | /// >Get Share Stats</see>. |
| | 1789 | | /// </summary> |
| | 1790 | | /// <param name="async"> |
| | 1791 | | /// Whether to invoke the operation asynchronously. |
| | 1792 | | /// </param> |
| | 1793 | | /// <param name="cancellationToken"> |
| | 1794 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1795 | | /// notifications that the operation should be cancelled. |
| | 1796 | | /// </param> |
| | 1797 | | /// <returns> |
| | 1798 | | /// A <see cref="Response{ShareStatistics}"/> describing the |
| | 1799 | | /// share statistics. |
| | 1800 | | /// </returns> |
| | 1801 | | /// <remarks> |
| | 1802 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 1803 | | /// a failure occurs. |
| | 1804 | | /// </remarks> |
| | 1805 | | private async Task<Response<ShareStatistics>> GetStatisticsInternal( |
| | 1806 | | bool async, |
| | 1807 | | CancellationToken cancellationToken) |
| | 1808 | | { |
| 6 | 1809 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 1810 | | { |
| | 1811 | | Pipeline.LogMethodEnter( |
| | 1812 | | nameof(ShareClient), |
| | 1813 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 1814 | | try |
| | 1815 | | { |
| 6 | 1816 | | return await FileRestClient.Share.GetStatisticsAsync( |
| 6 | 1817 | | ClientDiagnostics, |
| 6 | 1818 | | Pipeline, |
| 6 | 1819 | | Uri, |
| 6 | 1820 | | version: Version.ToVersionString(), |
| 6 | 1821 | | async: async, |
| 6 | 1822 | | operationName: $"{nameof(ShareClient)}.{nameof(GetStatistics)}", |
| 6 | 1823 | | cancellationToken: cancellationToken) |
| 6 | 1824 | | .ConfigureAwait(false); |
| | 1825 | | } |
| 2 | 1826 | | catch (Exception ex) |
| | 1827 | | { |
| | 1828 | | Pipeline.LogException(ex); |
| 2 | 1829 | | throw; |
| | 1830 | | } |
| | 1831 | | finally |
| | 1832 | | { |
| | 1833 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 1834 | | } |
| | 1835 | | } |
| 4 | 1836 | | } |
| | 1837 | | #endregion GetStatistics |
| | 1838 | |
|
| | 1839 | | #region GetPermission |
| | 1840 | | /// <summary> |
| | 1841 | | /// Gets the file permission in Security Descriptor Definition Language (SDDL). |
| | 1842 | | /// </summary> |
| | 1843 | | /// <param name="filePermissionKey"> |
| | 1844 | | /// The file permission key. |
| | 1845 | | /// </param> |
| | 1846 | | /// <param name="cancellationToken"> |
| | 1847 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1848 | | /// notifications that the operation should be cancelled. |
| | 1849 | | /// </param> |
| | 1850 | | /// <returns> |
| | 1851 | | /// A <see cref="Response{String}"/> file permission. |
| | 1852 | | /// </returns> |
| | 1853 | | public virtual Response<string> GetPermission( |
| | 1854 | | string filePermissionKey = default, |
| | 1855 | | CancellationToken cancellationToken = default) => |
| 2 | 1856 | | GetPermissionInternal( |
| 2 | 1857 | | filePermissionKey, |
| 2 | 1858 | | false, // async |
| 2 | 1859 | | cancellationToken) |
| 2 | 1860 | | .EnsureCompleted(); |
| | 1861 | |
|
| | 1862 | | /// <summary> |
| | 1863 | | /// Gets the file permission in Security Descriptor Definition Language (SDDL). |
| | 1864 | | /// </summary> |
| | 1865 | | /// <param name="filePermissionKey"> |
| | 1866 | | /// The file permission key. |
| | 1867 | | /// </param> |
| | 1868 | | /// <param name="cancellationToken"> |
| | 1869 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1870 | | /// notifications that the operation should be cancelled. |
| | 1871 | | /// </param> |
| | 1872 | | /// <returns> |
| | 1873 | | /// A <see cref="Response{String}"/> file permission. |
| | 1874 | | /// </returns> |
| | 1875 | | public virtual async Task<Response<string>> GetPermissionAsync( |
| | 1876 | | string filePermissionKey = default, |
| | 1877 | | CancellationToken cancellationToken = default) => |
| 2 | 1878 | | await GetPermissionInternal( |
| 2 | 1879 | | filePermissionKey, |
| 2 | 1880 | | true, // async |
| 2 | 1881 | | cancellationToken) |
| 2 | 1882 | | .ConfigureAwait(false); |
| | 1883 | |
|
| | 1884 | | private async Task<Response<string>> GetPermissionInternal( |
| | 1885 | | string filePermissionKey, |
| | 1886 | | bool async, |
| | 1887 | | CancellationToken cancellationToken) |
| | 1888 | | { |
| 4 | 1889 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 1890 | | { |
| | 1891 | | Pipeline.LogMethodEnter( |
| | 1892 | | nameof(ShareClient), |
| | 1893 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 1894 | | try |
| | 1895 | | { |
| | 1896 | | // Get the permission as a JSON object |
| 4 | 1897 | | Response<string> jsonResponse = |
| 4 | 1898 | | await FileRestClient.Share.GetPermissionAsync( |
| 4 | 1899 | | ClientDiagnostics, |
| 4 | 1900 | | Pipeline, |
| 4 | 1901 | | Uri, |
| 4 | 1902 | | filePermissionKey: filePermissionKey, |
| 4 | 1903 | | version: Version.ToVersionString(), |
| 4 | 1904 | | async: async, |
| 4 | 1905 | | operationName: $"{nameof(ShareClient)}.{nameof(GetPermission)}", |
| 4 | 1906 | | cancellationToken: cancellationToken) |
| 4 | 1907 | | .ConfigureAwait(false); |
| | 1908 | |
|
| | 1909 | | // Return an exploding Response on 304 |
| 2 | 1910 | | if (jsonResponse.IsUnavailable()) |
| | 1911 | | { |
| 0 | 1912 | | return jsonResponse; |
| | 1913 | | } |
| | 1914 | |
|
| | 1915 | | // Parse the JSON object |
| 2 | 1916 | | using var doc = JsonDocument.Parse(jsonResponse.Value); |
| 2 | 1917 | | if (doc.RootElement.ValueKind != JsonValueKind.Object || |
| 2 | 1918 | | !doc.RootElement.TryGetProperty("permission", out JsonElement permissionProperty) || |
| 2 | 1919 | | permissionProperty.ValueKind != JsonValueKind.String) |
| | 1920 | | { |
| 0 | 1921 | | throw ShareErrors.InvalidPermissionJson(jsonResponse.Value); |
| | 1922 | | } |
| 2 | 1923 | | var permission = permissionProperty.GetString(); |
| | 1924 | |
|
| | 1925 | | // Return the Permission string |
| 2 | 1926 | | return Response.FromValue(permission, jsonResponse.GetRawResponse()); |
| | 1927 | | } |
| 2 | 1928 | | catch (Exception ex) |
| | 1929 | | { |
| | 1930 | | Pipeline.LogException(ex); |
| 2 | 1931 | | throw; |
| | 1932 | | } |
| | 1933 | | finally |
| | 1934 | | { |
| | 1935 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 1936 | | } |
| | 1937 | | } |
| 2 | 1938 | | } |
| | 1939 | | #endregion GetPermission |
| | 1940 | |
|
| | 1941 | | #region CreatePermission |
| | 1942 | | /// <summary> |
| | 1943 | | /// Creates a permission (a security descriptor) at the share level. The created security descriptor |
| | 1944 | | /// can be used for the files/directories in the share. |
| | 1945 | | /// </summary> |
| | 1946 | | /// <param name="permission"> |
| | 1947 | | /// File permission in the Security Descriptor Definition Language (SDDL). SDDL must have an owner, group, |
| | 1948 | | /// and discretionary access control list (DACL). The provided SDDL string format of the security descriptor |
| | 1949 | | /// should not have domain relative identifier (like 'DU', 'DA', 'DD' etc) in it. |
| | 1950 | | /// </param> |
| | 1951 | | /// <param name="cancellationToken"> |
| | 1952 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1953 | | /// notifications that the operation should be cancelled. |
| | 1954 | | /// </param> |
| | 1955 | | /// <returns> |
| | 1956 | | /// A <see cref="Response{PermissionInfo}"/> with ID of the newly created file permission. |
| | 1957 | | /// </returns> |
| | 1958 | | public virtual Response<PermissionInfo> CreatePermission( |
| | 1959 | | string permission, |
| | 1960 | | CancellationToken cancellationToken = default) => |
| 7 | 1961 | | CreatePermissionInternal( |
| 7 | 1962 | | permission, |
| 7 | 1963 | | false, // async |
| 7 | 1964 | | cancellationToken) |
| 7 | 1965 | | .EnsureCompleted(); |
| | 1966 | |
|
| | 1967 | | /// <summary> |
| | 1968 | | /// Creates a permission (a security descriptor) at the share level. The created security descriptor |
| | 1969 | | /// can be used for the files/directories in the share. |
| | 1970 | | /// </summary> |
| | 1971 | | /// <param name="permission"> |
| | 1972 | | /// File permission in the Security Descriptor Definition Language (SDDL). SDDL must have an owner, group, |
| | 1973 | | /// and discretionary access control list (DACL). The provided SDDL string format of the security descriptor |
| | 1974 | | /// should not have domain relative identifier (like 'DU', 'DA', 'DD' etc) in it. |
| | 1975 | | /// </param> |
| | 1976 | | /// <param name="cancellationToken"> |
| | 1977 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 1978 | | /// notifications that the operation should be cancelled. |
| | 1979 | | /// </param> |
| | 1980 | | /// <returns> |
| | 1981 | | /// A <see cref="Response{PermissionInfo}"/> with ID of the newly created file permission. |
| | 1982 | | /// </returns> |
| | 1983 | | public virtual async Task<Response<PermissionInfo>> CreatePermissionAsync( |
| | 1984 | | string permission, |
| | 1985 | | CancellationToken cancellationToken = default) => |
| 7 | 1986 | | await CreatePermissionInternal( |
| 7 | 1987 | | permission, |
| 7 | 1988 | | true, // async |
| 7 | 1989 | | cancellationToken) |
| 7 | 1990 | | .ConfigureAwait(false); |
| | 1991 | |
|
| | 1992 | | private async Task<Response<PermissionInfo>> CreatePermissionInternal( |
| | 1993 | | string permission, |
| | 1994 | | bool async, |
| | 1995 | | CancellationToken cancellationToken) |
| | 1996 | | { |
| 14 | 1997 | | using (Pipeline.BeginLoggingScope(nameof(ShareClient))) |
| | 1998 | | { |
| | 1999 | | Pipeline.LogMethodEnter( |
| | 2000 | | nameof(ShareClient), |
| | 2001 | | message: $"{nameof(Uri)}: {Uri}"); |
| | 2002 | | try |
| | 2003 | | { |
| | 2004 | | // Serialize the permission as a JSON object |
| 14 | 2005 | | using var stream = new MemoryStream(); |
| 14 | 2006 | | using var writer = new Utf8JsonWriter(stream); |
| 14 | 2007 | | writer.WriteStartObject(); |
| 14 | 2008 | | writer.WriteString("permission", permission); |
| 14 | 2009 | | writer.WriteEndObject(); |
| 14 | 2010 | | if (async) |
| | 2011 | | { |
| 7 | 2012 | | await writer.FlushAsync().ConfigureAwait(false); |
| | 2013 | | } |
| | 2014 | | else |
| | 2015 | | { |
| 7 | 2016 | | writer.Flush(); |
| | 2017 | | } |
| 14 | 2018 | | var json = Encoding.UTF8.GetString(stream.ToArray()); |
| | 2019 | |
|
| 14 | 2020 | | return await FileRestClient.Share.CreatePermissionAsync( |
| 14 | 2021 | | ClientDiagnostics, |
| 14 | 2022 | | Pipeline, |
| 14 | 2023 | | Uri, |
| 14 | 2024 | | version: Version.ToVersionString(), |
| 14 | 2025 | | sharePermissionJson: json, |
| 14 | 2026 | | async: async, |
| 14 | 2027 | | operationName: $"{nameof(ShareClient)}.{nameof(CreatePermission)}", |
| 14 | 2028 | | cancellationToken: cancellationToken) |
| 14 | 2029 | | .ConfigureAwait(false); |
| | 2030 | | } |
| 2 | 2031 | | catch (Exception ex) |
| | 2032 | | { |
| | 2033 | | Pipeline.LogException(ex); |
| 2 | 2034 | | throw; |
| | 2035 | | } |
| | 2036 | | finally |
| | 2037 | | { |
| | 2038 | | Pipeline.LogMethodExit(nameof(ShareClient)); |
| | 2039 | | } |
| | 2040 | | } |
| 12 | 2041 | | } |
| | 2042 | | #endregion CreatePermission |
| | 2043 | |
|
| | 2044 | | #region CreateDirectory |
| | 2045 | | /// <summary> |
| | 2046 | | /// The <see cref="CreateDirectory"/> operation creates a new |
| | 2047 | | /// directory in this share. |
| | 2048 | | /// |
| | 2049 | | /// For more information, see |
| | 2050 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-directory"> |
| | 2051 | | /// Create Directory</see>. |
| | 2052 | | /// </summary> |
| | 2053 | | /// <param name="directoryName">T |
| | 2054 | | /// The name of the directory to create. |
| | 2055 | | /// </param> |
| | 2056 | | /// <param name="metadata"> |
| | 2057 | | /// Optional custom metadata to set for the directory. |
| | 2058 | | /// </param> |
| | 2059 | | /// <param name="smbProperties"> |
| | 2060 | | /// Optional SMB properties to set for the directory. |
| | 2061 | | /// </param> |
| | 2062 | | /// <param name="filePermission"> |
| | 2063 | | /// Optional file permission to set on the directory. |
| | 2064 | | /// </param> |
| | 2065 | | /// <param name="cancellationToken"> |
| | 2066 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2067 | | /// notifications that the operation should be cancelled. |
| | 2068 | | /// </param> |
| | 2069 | | /// <returns> |
| | 2070 | | /// A <see cref="Response{DirectoryClient}"/> referencing the |
| | 2071 | | /// newly created directory. |
| | 2072 | | /// </returns> |
| | 2073 | | /// <remarks> |
| | 2074 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2075 | | /// a failure occurs. |
| | 2076 | | /// </remarks> |
| | 2077 | | public virtual Response<ShareDirectoryClient> CreateDirectory( |
| | 2078 | | string directoryName, |
| | 2079 | | IDictionary<string, string> metadata = default, |
| | 2080 | | FileSmbProperties smbProperties = default, |
| | 2081 | | string filePermission = default, |
| | 2082 | | CancellationToken cancellationToken = default) |
| | 2083 | | { |
| 3 | 2084 | | ShareDirectoryClient directory = GetDirectoryClient(directoryName); |
| 3 | 2085 | | Response<ShareDirectoryInfo> response = directory.CreateInternal( |
| 3 | 2086 | | metadata, |
| 3 | 2087 | | smbProperties, |
| 3 | 2088 | | filePermission, |
| 3 | 2089 | | async: false, |
| 3 | 2090 | | cancellationToken, |
| 3 | 2091 | | operationName: $"{nameof(ShareClient)}.{nameof(CreateDirectory)}") |
| 3 | 2092 | | .EnsureCompleted(); |
| 3 | 2093 | | return Response.FromValue(directory, response.GetRawResponse()); |
| | 2094 | | } |
| | 2095 | |
|
| | 2096 | | /// <summary> |
| | 2097 | | /// The <see cref="CreateDirectoryAsync"/> operation creates a new |
| | 2098 | | /// directory in this share. |
| | 2099 | | /// |
| | 2100 | | /// For more information, see |
| | 2101 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-directory"> |
| | 2102 | | /// Create Directory</see>. |
| | 2103 | | /// </summary> |
| | 2104 | | /// <param name="directoryName">T |
| | 2105 | | /// The name of the directory to create. |
| | 2106 | | /// </param> |
| | 2107 | | /// <param name="metadata"> |
| | 2108 | | /// Optional custom metadata to set for the directory. |
| | 2109 | | /// </param> |
| | 2110 | | /// <param name="smbProperties"> |
| | 2111 | | /// Optional SMB properties to set for the directory. |
| | 2112 | | /// </param> |
| | 2113 | | /// <param name="filePermission"> |
| | 2114 | | /// Optional file permission to set on the directory. |
| | 2115 | | /// </param> |
| | 2116 | | /// <param name="cancellationToken"> |
| | 2117 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2118 | | /// notifications that the operation should be cancelled. |
| | 2119 | | /// </param> |
| | 2120 | | /// <returns> |
| | 2121 | | /// A <see cref="Response{DirectoryClient}"/> referencing the |
| | 2122 | | /// newly created directory. |
| | 2123 | | /// </returns> |
| | 2124 | | /// <remarks> |
| | 2125 | | /// A <see cref="RequestFailedException"/> will be thrown if |
| | 2126 | | /// a failure occurs. |
| | 2127 | | /// </remarks> |
| | 2128 | | public virtual async Task<Response<ShareDirectoryClient>> CreateDirectoryAsync( |
| | 2129 | | string directoryName, |
| | 2130 | | IDictionary<string, string> metadata = default, |
| | 2131 | | FileSmbProperties smbProperties = default, |
| | 2132 | | string filePermission = default, |
| | 2133 | | CancellationToken cancellationToken = default) |
| | 2134 | | { |
| 3 | 2135 | | ShareDirectoryClient directory = GetDirectoryClient(directoryName); |
| 3 | 2136 | | Response<ShareDirectoryInfo> response = await directory.CreateInternal( |
| 3 | 2137 | | metadata, |
| 3 | 2138 | | smbProperties, |
| 3 | 2139 | | filePermission, |
| 3 | 2140 | | async: true, |
| 3 | 2141 | | cancellationToken, |
| 3 | 2142 | | operationName: $"{nameof(ShareClient)}.{nameof(CreateDirectory)}") |
| 3 | 2143 | | .ConfigureAwait(false); |
| 3 | 2144 | | return Response.FromValue(directory, response.GetRawResponse()); |
| 3 | 2145 | | } |
| | 2146 | | #endregion CreateDirectory |
| | 2147 | |
|
| | 2148 | | #region DeleteDirectory |
| | 2149 | | /// <summary> |
| | 2150 | | /// The <see cref="DeleteDirectory"/> operation removes the specified empty |
| | 2151 | | /// directory. |
| | 2152 | | /// |
| | 2153 | | /// For more information, see |
| | 2154 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-directory"> |
| | 2155 | | /// Delete Directory</see>. |
| | 2156 | | /// </summary> |
| | 2157 | | /// <param name="directoryName">T |
| | 2158 | | /// The name of the directory to delete. |
| | 2159 | | /// </param> |
| | 2160 | | /// <param name="cancellationToken"> |
| | 2161 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2162 | | /// notifications that the operation should be cancelled. |
| | 2163 | | /// </param> |
| | 2164 | | /// <returns> |
| | 2165 | | /// A <see cref="Response"/> if successful. |
| | 2166 | | /// </returns> |
| | 2167 | | /// <remarks> |
| | 2168 | | /// Note that the directory must be empty before it can be deleted. |
| | 2169 | | /// </remarks> |
| | 2170 | | public virtual Response DeleteDirectory( |
| | 2171 | | string directoryName, |
| | 2172 | | CancellationToken cancellationToken = default) => |
| 1 | 2173 | | GetDirectoryClient(directoryName).DeleteInternal( |
| 1 | 2174 | | async: false, |
| 1 | 2175 | | cancellationToken, |
| 1 | 2176 | | operationName: $"{nameof(ShareClient)}.{nameof(DeleteDirectory)}") |
| 1 | 2177 | | .EnsureCompleted(); |
| | 2178 | |
|
| | 2179 | | /// <summary> |
| | 2180 | | /// The <see cref="DeleteDirectoryAsync"/> operation removes the specified empty |
| | 2181 | | /// directory. |
| | 2182 | | /// |
| | 2183 | | /// For more information, see |
| | 2184 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/delete-directory"> |
| | 2185 | | /// Delete Directory</see>. |
| | 2186 | | /// </summary> |
| | 2187 | | /// <param name="directoryName">T |
| | 2188 | | /// The name of the directory to delete. |
| | 2189 | | /// </param> |
| | 2190 | | /// <param name="cancellationToken"> |
| | 2191 | | /// Optional <see cref="CancellationToken"/> to propagate |
| | 2192 | | /// notifications that the operation should be cancelled. |
| | 2193 | | /// </param> |
| | 2194 | | /// <returns> |
| | 2195 | | /// A <see cref="Response"/> if successful. |
| | 2196 | | /// </returns> |
| | 2197 | | /// <remarks> |
| | 2198 | | /// Note that the directory must be empty before it can be deleted. |
| | 2199 | | /// </remarks> |
| | 2200 | | public virtual async Task<Response> DeleteDirectoryAsync( |
| | 2201 | | string directoryName, |
| | 2202 | | CancellationToken cancellationToken = default) => |
| 1 | 2203 | | await GetDirectoryClient(directoryName) |
| 1 | 2204 | | .DeleteInternal( |
| 1 | 2205 | | async: true, |
| 1 | 2206 | | cancellationToken, |
| 1 | 2207 | | operationName: $"{nameof(ShareClient)}.{nameof(DeleteDirectory)}") |
| 1 | 2208 | | .ConfigureAwait(false); |
| | 2209 | | #endregion DeleteDirectory |
| | 2210 | | } |
| | 2211 | | } |