Microsoft.Azure.Commands.Compute.StorageServices.StorageCredentialsFactory.Create C# (CSharp) Method

Create() public method

public Create ( BlobUri destination ) : Microsoft.WindowsAzure.Storage.Auth.StorageCredentials
destination Microsoft.WindowsAzure.Commands.Sync.Download.BlobUri
return Microsoft.WindowsAzure.Storage.Auth.StorageCredentials
        public StorageCredentials Create(BlobUri destination)
        {
            if (IsChannelRequired(destination.Uri))
            {
                if (currentSubscription == null)
                {
                    throw new ArgumentException(Rsrc.StorageCredentialsFactoryCurrentSubscriptionNotSet, "SubscriptionId");
                }
                var storageKeys = this.client.StorageAccounts.ListKeys(this.resourceGroupName, destination.StorageAccountName);
                return new StorageCredentials(destination.StorageAccountName, storageKeys.Key1);
            }

            return new StorageCredentials(destination.Uri.Query);
        }
    }

Usage Example

 /// <summary>
 /// find the snapshot with the tags
 /// </summary>
 /// <param name="blobUris"></param>
 /// <param name="snapshotTag"></param>
 /// <param name="taskId"></param>
 /// <param name="storageCredentialsFactory"></param>
 /// <returns></returns>
 public List<CloudPageBlob> FindSnapshot(List<string> blobUris, Dictionary<string, string> snapshotQuery, StorageCredentialsFactory storageCredentialsFactory)
 {
     List<CloudPageBlob> snapshots = new List<CloudPageBlob>();
     for (int i = 0; i < blobUris.Count; i++)
     {
         BlobUri blobUri = null;
         if (BlobUri.TryParseUri(new Uri(blobUris[i]), out blobUri))
         {
             StorageCredentials sc = storageCredentialsFactory.Create(blobUri);
             CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(sc, true);
             CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
             CloudBlobContainer blobContainer = blobClient.GetContainerReference(blobUri.BlobContainerName);
             IEnumerable<IListBlobItem> blobs = blobContainer.ListBlobs(null, true, BlobListingDetails.All);
             foreach (var blob in blobs)
             {
                 if (blob is CloudPageBlob)
                 {
                     CloudPageBlob pageBlob = blob as CloudPageBlob;
                     if (pageBlob.IsSnapshot && pageBlob.Name == blobUri.BlobName)
                     {
                         bool allMatch = true;
                         foreach (string keyToQuey in snapshotQuery.Keys)
                         {
                             if (!pageBlob.Metadata.Keys.Contains(keyToQuey))
                             {
                                 allMatch = false;
                             }
                             else if (!string.Equals(pageBlob.Metadata[keyToQuey], snapshotQuery[keyToQuey]))
                             {
                                 allMatch = false;
                             }
                         }
                         if (allMatch)
                         {
                             snapshots.Add(pageBlob);
                         }
                     }
                 }
             }
         }
     }
     return snapshots;
 }
All Usage Examples Of Microsoft.Azure.Commands.Compute.StorageServices.StorageCredentialsFactory::Create