< Summary

Class:Azure.Storage.Files.Shares.ShareClient
Assembly:Azure.Storage.Files.Shares
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.Shares\src\ShareClient.cs
Covered lines:427
Uncovered lines:6
Coverable lines:433
Total lines:2211
Line coverage:98.6% (427 of 433)
Covered branches:18
Total branches:24
Branch coverage:75% (18 of 24)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Uri()-100%100%
get_Pipeline()-100%100%
get_Version()-100%100%
get_ClientDiagnostics()-100%100%
get_AccountName()-100%100%
get_Name()-100%100%
.ctor()-100%100%
.ctor(...)-0%100%
.ctor(...)-100%50%
.ctor(...)-100%100%
.ctor(...)-0%100%
.ctor(...)-100%50%
.ctor(...)-100%100%
WithSnapshot(...)-100%100%
GetDirectoryClient(...)-100%100%
GetRootDirectoryClient()-100%100%
SetNameFieldsIfNull()-100%100%
Create(...)-100%100%
CreateAsync()-100%100%
CreateInternal()-100%100%
CreateIfNotExists(...)-100%100%
CreateIfNotExistsAsync()-100%100%
CreateIfNotExistsInternal()-100%100%
Exists(...)-100%100%
ExistsAsync()-100%100%
ExistsInternal()-100%100%
DeleteIfExists(...)-100%100%
DeleteIfExistsAsync()-100%100%
DeleteIfExistsInternal()-100%100%
CreateSnapshot(...)-100%100%
CreateSnapshotAsync()-100%100%
CreateSnapshotInternal()-100%100%
Delete(...)-100%100%
DeleteAsync()-100%100%
DeleteInternal()-100%100%
GetProperties(...)-100%100%
GetPropertiesAsync()-100%100%
GetPropertiesInternal()-100%100%
SetQuota(...)-100%100%
SetQuotaAsync()-100%100%
SetQuotaInternal()-100%100%
SetMetadata(...)-100%100%
SetMetadataAsync()-100%100%
SetMetadataInternal()-100%100%
GetAccessPolicy(...)-100%100%
GetAccessPolicyAsync()-100%100%
GetAccessPolicyInternal()-100%100%
SetAccessPolicy(...)-100%100%
SetAccessPolicyAsync()-100%100%
SetAccessPolicyInternal()-100%100%
GetStatistics(...)-100%100%
GetStatisticsAsync()-100%100%
GetStatisticsInternal()-100%100%
GetPermission(...)-100%100%
GetPermissionAsync()-100%100%
GetPermissionInternal()-91.67%50%
CreatePermission(...)-100%100%
CreatePermissionAsync()-100%100%
CreatePermissionInternal()-100%100%
CreateDirectory(...)-100%100%
CreateDirectoryAsync()-100%100%
DeleteDirectory(...)-100%100%
DeleteDirectoryAsync()-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.Shares\src\ShareClient.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.IO;
 7using System.Text;
 8using System.Text.Json;
 9using System.Threading;
 10using System.Threading.Tasks;
 11using Azure.Core;
 12using Azure.Core.Pipeline;
 13using Azure.Storage.Files.Shares.Models;
 14using Metadata = System.Collections.Generic.IDictionary<string, string>;
 15
 16namespace 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>
 164132        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>
 246944        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>
 145554        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>
 145566        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            {
 480                SetNameFieldsIfNull();
 481                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            {
 18597                SetNameFieldsIfNull();
 18598                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>
 589107        protected ShareClient()
 108        {
 589109        }
 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)
 0128            : this(connectionString, shareName, null)
 129        {
 0130        }
 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>
 6153        public ShareClient(string connectionString, string shareName, ShareClientOptions options)
 154        {
 6155            options ??= new ShareClientOptions();
 6156            var conn = StorageConnectionString.Parse(connectionString);
 6157            var builder = new ShareUriBuilder(conn.FileEndpoint) { ShareName = shareName };
 6158            _uri = builder.ToUri();
 6159            _pipeline = options.Build(conn.Credentials);
 6160            _version = options.Version;
 6161            _clientDiagnostics = new ClientDiagnostics(options);
 6162        }
 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)
 22178            : this(shareUri, (HttpPipelinePolicy)null, options)
 179        {
 22180        }
 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)
 0199            : this(shareUri, credential.AsPolicy(), options)
 200        {
 0201        }
 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>
 22219        internal ShareClient(Uri shareUri, HttpPipelinePolicy authentication, ShareClientOptions options)
 220        {
 22221            options ??= new ShareClientOptions();
 22222            _uri = shareUri;
 22223            _pipeline = options.Build(authentication);
 22224            _version = options.Version;
 22225            _clientDiagnostics = new ClientDiagnostics(options);
 22226        }
 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>
 577246        internal ShareClient(Uri shareUri, HttpPipeline pipeline, ShareClientOptions.ServiceVersion version, ClientDiagn
 247        {
 577248            _uri = shareUri;
 577249            _pipeline = pipeline;
 577250            _version = version;
 577251            _clientDiagnostics = clientDiagnostics;
 577252        }
 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        {
 20275            var p = new ShareUriBuilder(Uri) { Snapshot = snapshot };
 20276            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        {
 433289            ShareUriBuilder shareUriBuilder = new ShareUriBuilder(Uri)
 433290            {
 433291                DirectoryOrFilePath = directoryName
 433292            };
 433293            return new ShareDirectoryClient(
 433294                shareUriBuilder.ToUri(),
 433295                Pipeline,
 433296                Version,
 433297                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()
 66308            => GetDirectoryClient("");
 309
 310        /// <summary>
 311        /// Sets the various name fields if they are currently null.
 312        /// </summary>
 313        private void SetNameFieldsIfNull()
 314        {
 189315            if (_name == null || _accountName == null)
 316            {
 54317                var builder = new ShareUriBuilder(Uri);
 54318                _name = builder.ShareName;
 54319                _accountName = builder.AccountName;
 320            }
 189321        }
 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) =>
 218355            CreateInternal(
 218356                metadata,
 218357                quotaInGB,
 218358                false, // async
 218359                cancellationToken)
 218360                .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) =>
 219393            await CreateInternal(
 219394                metadata,
 219395                quotaInGB,
 219396                true, // async
 219397                cancellationToken)
 219398                .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        {
 447440            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                {
 447449                    return await FileRestClient.Share.CreateAsync(
 447450                        ClientDiagnostics,
 447451                        Pipeline,
 447452                        Uri,
 447453                        version: Version.ToVersionString(),
 447454                        metadata: metadata,
 447455                        quotaInGB: quotaInGB,
 447456                        async: async,
 447457                        operationName: operationName ?? $"{nameof(ShareClient)}.{nameof(Create)}",
 447458                        cancellationToken: cancellationToken)
 447459                        .ConfigureAwait(false);
 460                }
 8461                catch (Exception ex)
 462                {
 463                    Pipeline.LogException(ex);
 8464                    throw;
 465                }
 466                finally
 467                {
 468                    Pipeline.LogMethodExit(nameof(ShareClient));
 469                }
 470            }
 439471        }
 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) =>
 3506            CreateIfNotExistsInternal(
 3507                metadata,
 3508                quotaInGB,
 3509                async: false,
 3510                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) =>
 3543            await CreateIfNotExistsInternal(
 3544                metadata,
 3545                quotaInGB,
 3546                async: true,
 3547                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        {
 6585            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                {
 6595                    response = await CreateInternal(
 6596                        metadata,
 6597                        quotaInGB,
 6598                        async,
 6599                        cancellationToken,
 6600                        $"{nameof(ShareClient)}.{nameof(CreateIfNotExists)}")
 6601                        .ConfigureAwait(false);
 2602                }
 603                catch (RequestFailedException storageRequestFailedException)
 4604                when (storageRequestFailedException.ErrorCode == ShareErrorCode.ShareAlreadyExists)
 605                {
 2606                    response = default;
 2607                }
 2608                catch (Exception ex)
 609                {
 610                    Pipeline.LogException(ex);
 2611                    throw;
 612                }
 613                finally
 614                {
 615                    Pipeline.LogMethodExit(nameof(ShareClient));
 616                }
 4617                return response;
 618            }
 4619        }
 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) =>
 5641            ExistsInternal(
 5642                async: false,
 5643                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) =>
 5663            await ExistsInternal(
 5664                async: true,
 5665                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        {
 10690            using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
 691            {
 692                Pipeline.LogMethodEnter(
 693                    nameof(ShareClient),
 694                    message:
 695                    $"{nameof(Uri)}: {Uri}");
 696
 697                try
 698                {
 10699                    Response<ShareProperties> response = await FileRestClient.Share.GetPropertiesAsync(
 10700                        ClientDiagnostics,
 10701                        Pipeline,
 10702                        Uri,
 10703                        version: Version.ToVersionString(),
 10704                        async: async,
 10705                        operationName: $"{nameof(ShareClient)}.{nameof(Exists)}",
 10706                        cancellationToken: cancellationToken)
 10707                        .ConfigureAwait(false);
 708
 4709                    return Response.FromValue(true, response.GetRawResponse());
 710                }
 711                catch (RequestFailedException storageRequestFailedException)
 6712                when (storageRequestFailedException.ErrorCode == ShareErrorCode.ShareNotFound)
 713                {
 4714                    return Response.FromValue(false, default);
 715                }
 2716                catch (Exception ex)
 717                {
 718                    Pipeline.LogException(ex);
 2719                    throw;
 720                }
 721                finally
 722                {
 723                    Pipeline.LogMethodExit(nameof(ShareClient));
 724                }
 725            }
 8726        }
 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) =>
 3755            DeleteIfExistsInternal(
 3756                includeSnapshots,
 3757                async: false,
 3758                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) =>
 3785            await DeleteIfExistsInternal(
 3786                includeSnapshots,
 3787                async: true,
 3788                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        {
 6820            using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
 821            {
 822                Pipeline.LogMethodEnter(
 823                    nameof(ShareClient),
 824                    message:
 825                    $"{nameof(Uri)}: {Uri}");
 826                try
 827                {
 6828                    Response response = await DeleteInternal(
 6829                        includeSnapshots,
 6830                        async,
 6831                        cancellationToken,
 6832                        $"{nameof(ShareClient)}.{nameof(DeleteIfExists)}")
 6833                        .ConfigureAwait(false);
 2834                    return Response.FromValue(true, response);
 835                }
 836                catch (RequestFailedException storageRequestFailedException)
 4837                when (storageRequestFailedException.ErrorCode == ShareErrorCode.ShareNotFound)
 838                {
 2839                    return Response.FromValue(false, default);
 840                }
 2841                catch (Exception ex)
 842                {
 843                    Pipeline.LogException(ex);
 2844                    throw;
 845                }
 846                finally
 847                {
 848                    Pipeline.LogMethodExit(nameof(ShareClient));
 849                }
 850            }
 4851        }
 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) =>
 6880            CreateSnapshotInternal(
 6881                metadata,
 6882                false, // async
 6883                cancellationToken)
 6884                .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) =>
 6911            await CreateSnapshotInternal(
 6912                metadata,
 6913                true, // async
 6914                cancellationToken)
 6915                .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        {
 12947            using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
 948            {
 949                Pipeline.LogMethodEnter(
 950                    nameof(ShareClient),
 951                    message: $"{nameof(Uri)}: {Uri}");
 952                try
 953                {
 12954                    return await FileRestClient.Share.CreateSnapshotAsync(
 12955                        ClientDiagnostics,
 12956                        Pipeline,
 12957                        Uri,
 12958                        version: Version.ToVersionString(),
 12959                        metadata: metadata,
 12960                        async: async,
 12961                        operationName: $"{nameof(ShareClient)}.{nameof(CreateSnapshot)}",
 12962                        cancellationToken: cancellationToken)
 12963                        .ConfigureAwait(false);
 964                }
 2965                catch (Exception ex)
 966                {
 967                    Pipeline.LogException(ex);
 2968                    throw;
 969                }
 970                finally
 971                {
 972                    Pipeline.LogMethodExit(nameof(ShareClient));
 973                }
 974            }
 10975        }
 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) =>
 2201005            DeleteInternal(
 2201006                includeSnapshots,
 2201007                false, // async
 2201008                cancellationToken)
 2201009                .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) =>
 2211037            await DeleteInternal(
 2211038                includeSnapshots,
 2211039                true, // async
 2211040                cancellationToken)
 2211041                .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        {
 4511078            using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
 1079            {
 1080                Pipeline.LogMethodEnter(
 1081                    nameof(ShareClient),
 1082                    message:
 1083                    $"{nameof(Uri)}: {Uri}");
 1084                try
 1085                {
 4511086                    return await FileRestClient.Share.DeleteAsync(
 4511087                        ClientDiagnostics,
 4511088                        Pipeline,
 4511089                        Uri,
 4511090                        version: Version.ToVersionString(),
 4511091                        deleteSnapshots: includeSnapshots ? DeleteSnapshotsOptionType.Include : (DeleteSnapshotsOptionTy
 4511092                        async: async,
 4511093                        operationName: operationName ?? $"{nameof(ShareClient)}.{nameof(Delete)}",
 4511094                        cancellationToken: cancellationToken)
 4511095                        .ConfigureAwait(false);
 1096                }
 101097                catch (Exception ex)
 1098                {
 1099                    Pipeline.LogException(ex);
 101100                    throw;
 1101                }
 1102                finally
 1103                {
 1104                    Pipeline.LogMethodExit(nameof(ShareClient));
 1105                }
 1106            }
 4411107        }
 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) =>
 101134            GetPropertiesInternal(
 101135                false, // async
 101136                cancellationToken)
 101137                .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) =>
 161162            await GetPropertiesInternal(
 161163                true, // async
 161164                cancellationToken)
 161165                .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        {
 261195            using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
 1196            {
 1197                Pipeline.LogMethodEnter(
 1198                    nameof(ShareClient),
 1199                    message:
 1200                    $"{nameof(Uri)}: {Uri}");
 1201                try
 1202                {
 261203                    return await FileRestClient.Share.GetPropertiesAsync(
 261204                        ClientDiagnostics,
 261205                        Pipeline,
 261206                        Uri,
 261207                        version: Version.ToVersionString(),
 261208                        async: async,
 261209                        operationName: $"{nameof(ShareClient)}.{nameof(GetProperties)}",
 261210                        cancellationToken: cancellationToken)
 261211                        .ConfigureAwait(false);
 1212                }
 81213                catch (Exception ex)
 1214                {
 1215                    Pipeline.LogException(ex);
 81216                    throw;
 1217                }
 1218                finally
 1219                {
 1220                    Pipeline.LogMethodExit(nameof(ShareClient));
 1221                }
 1222            }
 181223        }
 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) =>
 21253            SetQuotaInternal(
 21254                quotaInGB,
 21255                false, // async
 21256                cancellationToken)
 21257                .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) =>
 21285            await SetQuotaInternal(
 21286                quotaInGB,
 21287                true, // async
 21288                cancellationToken)
 21289                .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        {
 41322            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                {
 41331                    return await FileRestClient.Share.SetQuotaAsync(
 41332                        ClientDiagnostics,
 41333                        Pipeline,
 41334                        Uri,
 41335                        version: Version.ToVersionString(),
 41336                        quotaInGB: quotaInGB,
 41337                        async: async,
 41338                        operationName: $"{nameof(ShareClient)}.{nameof(SetQuota)}",
 41339                        cancellationToken: cancellationToken)
 41340                        .ConfigureAwait(false);
 1341                }
 21342                catch (Exception ex)
 1343                {
 1344                    Pipeline.LogException(ex);
 21345                    throw;
 1346                }
 1347                finally
 1348                {
 1349                    Pipeline.LogMethodExit(nameof(ShareClient));
 1350                }
 1351            }
 21352        }
 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) =>
 21382            SetMetadataInternal(
 21383                metadata,
 21384                false, // async
 21385                cancellationToken)
 21386                .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) =>
 21414            await SetMetadataInternal(
 21415                metadata,
 21416                true, // async
 21417                cancellationToken)
 21418                .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        {
 41451            using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
 1452            {
 1453                Pipeline.LogMethodEnter(
 1454                    nameof(ShareClient),
 1455                    message: $"{nameof(Uri)}: {Uri}");
 1456                try
 1457                {
 41458                    return await FileRestClient.Share.SetMetadataAsync(
 41459                        ClientDiagnostics,
 41460                        Pipeline,
 41461                        Uri,
 41462                        version: Version.ToVersionString(),
 41463                        metadata: metadata,
 41464                        async: async,
 41465                        operationName: $"{nameof(ShareClient)}.{nameof(SetMetadata)}",
 41466                        cancellationToken: cancellationToken)
 41467                        .ConfigureAwait(false);
 1468                }
 21469                catch (Exception ex)
 1470                {
 1471                    Pipeline.LogException(ex);
 21472                    throw;
 1473                }
 1474                finally
 1475                {
 1476                    Pipeline.LogMethodExit(nameof(ShareClient));
 1477                }
 1478            }
 21479        }
 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) =>
 51506            GetAccessPolicyInternal(
 51507                false, // async
 51508                cancellationToken)
 51509                .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) =>
 51534            await GetAccessPolicyInternal(
 51535                true, // async
 51536                cancellationToken)
 51537                .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        {
 101567            using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
 1568            {
 1569                Pipeline.LogMethodEnter(
 1570                    nameof(ShareClient),
 1571                    message: $"{nameof(Uri)}: {Uri}");
 1572                try
 1573                {
 101574                    return await FileRestClient.Share.GetAccessPolicyAsync(
 101575                        ClientDiagnostics,
 101576                        Pipeline,
 101577                        Uri,
 101578                        version: Version.ToVersionString(),
 101579                        async: async,
 101580                        operationName: $"{nameof(ShareClient)}.{nameof(GetAccessPolicy)}",
 101581                        cancellationToken: cancellationToken)
 101582                        .ConfigureAwait(false);
 1583                }
 21584                catch (Exception ex)
 1585                {
 1586                    Pipeline.LogException(ex);
 21587                    throw;
 1588                }
 1589                finally
 1590                {
 1591                    Pipeline.LogMethodExit(nameof(ShareClient));
 1592                }
 1593            }
 81594        }
 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) =>
 71626            SetAccessPolicyInternal(
 71627                permissions,
 71628                false, // async
 71629                cancellationToken)
 71630                .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) =>
 71660            await SetAccessPolicyInternal(
 71661                permissions,
 71662                true, // async
 71663                cancellationToken)
 71664                .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        {
 141699            using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
 1700            {
 1701                Pipeline.LogMethodEnter(
 1702                    nameof(ShareClient),
 1703                    message: $"{nameof(Uri)}: {Uri}");
 1704                try
 1705                {
 141706                    return await FileRestClient.Share.SetAccessPolicyAsync(
 141707                        ClientDiagnostics,
 141708                        Pipeline,
 141709                        Uri,
 141710                        version: Version.ToVersionString(),
 141711                        permissions: permissions,
 141712                        async: async,
 141713                        operationName: $"{nameof(ShareClient)}.{nameof(SetAccessPolicy)}",
 141714                        cancellationToken: cancellationToken)
 141715                        .ConfigureAwait(false);
 1716                }
 21717                catch (Exception ex)
 1718                {
 1719                    Pipeline.LogException(ex);
 21720                    throw;
 1721                }
 1722                finally
 1723                {
 1724                    Pipeline.LogMethodExit(nameof(ShareClient));
 1725                }
 1726            }
 121727        }
 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) =>
 31752            GetStatisticsInternal(
 31753                false, // async
 31754                cancellationToken)
 31755                .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) =>
 31778            await GetStatisticsInternal(
 31779                true, // async
 31780                cancellationToken)
 31781                .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        {
 61809            using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
 1810            {
 1811                Pipeline.LogMethodEnter(
 1812                    nameof(ShareClient),
 1813                    message: $"{nameof(Uri)}: {Uri}");
 1814                try
 1815                {
 61816                    return await FileRestClient.Share.GetStatisticsAsync(
 61817                        ClientDiagnostics,
 61818                        Pipeline,
 61819                        Uri,
 61820                        version: Version.ToVersionString(),
 61821                        async: async,
 61822                        operationName: $"{nameof(ShareClient)}.{nameof(GetStatistics)}",
 61823                        cancellationToken: cancellationToken)
 61824                        .ConfigureAwait(false);
 1825                }
 21826                catch (Exception ex)
 1827                {
 1828                    Pipeline.LogException(ex);
 21829                    throw;
 1830                }
 1831                finally
 1832                {
 1833                    Pipeline.LogMethodExit(nameof(ShareClient));
 1834                }
 1835            }
 41836        }
 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) =>
 21856            GetPermissionInternal(
 21857                filePermissionKey,
 21858                false, // async
 21859                cancellationToken)
 21860                .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) =>
 21878            await GetPermissionInternal(
 21879                filePermissionKey,
 21880                true, // async
 21881                cancellationToken)
 21882                .ConfigureAwait(false);
 1883
 1884        private async Task<Response<string>> GetPermissionInternal(
 1885            string filePermissionKey,
 1886            bool async,
 1887            CancellationToken cancellationToken)
 1888        {
 41889            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
 41897                    Response<string> jsonResponse =
 41898                        await FileRestClient.Share.GetPermissionAsync(
 41899                            ClientDiagnostics,
 41900                            Pipeline,
 41901                            Uri,
 41902                            filePermissionKey: filePermissionKey,
 41903                            version: Version.ToVersionString(),
 41904                            async: async,
 41905                            operationName: $"{nameof(ShareClient)}.{nameof(GetPermission)}",
 41906                            cancellationToken: cancellationToken)
 41907                            .ConfigureAwait(false);
 1908
 1909                    // Return an exploding Response on 304
 21910                    if (jsonResponse.IsUnavailable())
 1911                    {
 01912                        return jsonResponse;
 1913                    }
 1914
 1915                    // Parse the JSON object
 21916                    using var doc = JsonDocument.Parse(jsonResponse.Value);
 21917                    if (doc.RootElement.ValueKind != JsonValueKind.Object ||
 21918                        !doc.RootElement.TryGetProperty("permission", out JsonElement permissionProperty) ||
 21919                        permissionProperty.ValueKind != JsonValueKind.String)
 1920                    {
 01921                        throw ShareErrors.InvalidPermissionJson(jsonResponse.Value);
 1922                    }
 21923                    var permission = permissionProperty.GetString();
 1924
 1925                    // Return the Permission string
 21926                    return Response.FromValue(permission, jsonResponse.GetRawResponse());
 1927                }
 21928                catch (Exception ex)
 1929                {
 1930                    Pipeline.LogException(ex);
 21931                    throw;
 1932                }
 1933                finally
 1934                {
 1935                    Pipeline.LogMethodExit(nameof(ShareClient));
 1936                }
 1937            }
 21938        }
 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) =>
 71961            CreatePermissionInternal(
 71962                permission,
 71963                false, // async
 71964                cancellationToken)
 71965                .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) =>
 71986            await CreatePermissionInternal(
 71987                permission,
 71988                true, // async
 71989                cancellationToken)
 71990                .ConfigureAwait(false);
 1991
 1992        private async Task<Response<PermissionInfo>> CreatePermissionInternal(
 1993            string permission,
 1994            bool async,
 1995            CancellationToken cancellationToken)
 1996        {
 141997            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
 142005                    using var stream = new MemoryStream();
 142006                    using var writer = new Utf8JsonWriter(stream);
 142007                    writer.WriteStartObject();
 142008                    writer.WriteString("permission", permission);
 142009                    writer.WriteEndObject();
 142010                    if (async)
 2011                    {
 72012                        await writer.FlushAsync().ConfigureAwait(false);
 2013                    }
 2014                    else
 2015                    {
 72016                        writer.Flush();
 2017                    }
 142018                    var json = Encoding.UTF8.GetString(stream.ToArray());
 2019
 142020                    return await FileRestClient.Share.CreatePermissionAsync(
 142021                        ClientDiagnostics,
 142022                        Pipeline,
 142023                        Uri,
 142024                        version: Version.ToVersionString(),
 142025                        sharePermissionJson: json,
 142026                        async: async,
 142027                        operationName: $"{nameof(ShareClient)}.{nameof(CreatePermission)}",
 142028                        cancellationToken: cancellationToken)
 142029                        .ConfigureAwait(false);
 2030                }
 22031                catch (Exception ex)
 2032                {
 2033                    Pipeline.LogException(ex);
 22034                    throw;
 2035                }
 2036                finally
 2037                {
 2038                    Pipeline.LogMethodExit(nameof(ShareClient));
 2039                }
 2040            }
 122041        }
 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        {
 32084            ShareDirectoryClient directory = GetDirectoryClient(directoryName);
 32085            Response<ShareDirectoryInfo> response = directory.CreateInternal(
 32086                metadata,
 32087                smbProperties,
 32088                filePermission,
 32089                async: false,
 32090                cancellationToken,
 32091                operationName: $"{nameof(ShareClient)}.{nameof(CreateDirectory)}")
 32092                .EnsureCompleted();
 32093            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        {
 32135            ShareDirectoryClient directory = GetDirectoryClient(directoryName);
 32136            Response<ShareDirectoryInfo> response = await directory.CreateInternal(
 32137                metadata,
 32138                smbProperties,
 32139                filePermission,
 32140                async: true,
 32141                cancellationToken,
 32142                operationName: $"{nameof(ShareClient)}.{nameof(CreateDirectory)}")
 32143                .ConfigureAwait(false);
 32144            return Response.FromValue(directory, response.GetRawResponse());
 32145        }
 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) =>
 12173            GetDirectoryClient(directoryName).DeleteInternal(
 12174                async: false,
 12175                cancellationToken,
 12176                operationName: $"{nameof(ShareClient)}.{nameof(DeleteDirectory)}")
 12177                .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) =>
 12203            await GetDirectoryClient(directoryName)
 12204                .DeleteInternal(
 12205                async: true,
 12206                cancellationToken,
 12207                operationName: $"{nameof(ShareClient)}.{nameof(DeleteDirectory)}")
 12208                .ConfigureAwait(false);
 2209        #endregion DeleteDirectory
 2210    }
 2211}