Пример #1
0
        /// <summary>
        /// Creates a BlobContainerClient.  Called when one does not exist yet.
        /// </summary>
        /// <param name="uri">The target Uri.</param>
        /// <param name="context">The context.</param>
        /// <returns>
        /// A BlobContainerClient object.
        /// </returns>
        internal StorageContainerClientSleeve CreateBlobContainerClientForUri(
            Uri uri,
            StorageClientProviderContext context)
        {
            // set up a copy of the Context...
            var ctxCopy = new StorageClientProviderContext(context);

            BlobContainerClient blobContainerClient;
            BlobUriBuilder      containerUriBuilder;
            BlobClientOptions   clientOptions;

            try
            {
                containerUriBuilder = new BlobUriBuilder(uri);
                clientOptions       = new BlobClientOptions();
                var clientRequestIdPolicy = new BlobClientPipelinePolicy(ctxCopy);
                var uriC = StorageHelpers.BuildBlobStorageUri(containerUriBuilder.AccountName, containerUriBuilder.BlobContainerName);
                blobContainerClient = new BlobContainerClient(uriC, _identity, clientOptions);
            }
            catch (Exception fe) when(fe is ArgumentNullException || fe is UriFormatException)
            {
                var aex = new ArgumentException(LogEventIds.BlobContainerClientProviderUriMissingAccountName.Name, fe);

                _log.LogExceptionObject(LogEventIds.BlobContainerClientProviderUriMissingAccountName, aex, uri);
                throw aex;
            }
            catch (Exception e)
            {
                _log.LogExceptionObject(LogEventIds.BlobContainerClientProviderFailedToCreateBlobContainerClient, e, uri);
                throw;
            }


            try
            {
                var accountUri = StorageHelpers.BuildStorageAccountUri(containerUriBuilder.AccountName, buildForBlobService: true);
                var sleeve     = new StorageContainerClientSleeve(blobContainerClient,
                                                                  new BlobServiceClient(accountUri, _identity, clientOptions),
                                                                  ctxCopy);
                return(sleeve);
            }
            catch (ArgumentException aex)
            {
                _log.LogExceptionObject(LogEventIds.BlobContainerClientProviderUriMissingAccountName, aex, uri);
                throw;
            }
        }
Пример #2
0
 /// <summary>Reset this instance to reflect new context information.</summary>
 /// <param name="bcs">The sleeve to have context reset</param>
 /// <param name="ctx">The new context from which to update the sleeve's context.
 /// Note that the context state is copied to the sleeve, not used in place from ctx.</param>
 /// <returns>A reference to the input bcs parameter, updated to reflect the new context.</returns>
 internal static StorageContainerClientSleeve ResetSleeve(StorageContainerClientSleeve bcs, StorageClientProviderContext ctx)
 {
     // important to update the existing context in-place as policy references a particular instance
     bcs.Context.ResetTo(ctx);
     return(bcs);
 }