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
 /// <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;
 }
Exemplo n.º 2
0
        internal int? GetDiskSizeGbFromBlobUri(string sBlobUri)
        {
            var storageClient = new StorageManagementClient();
            var blobMatch = Regex.Match(sBlobUri, "https?://(\\S*?)\\..*?/(.*)");
            if (!blobMatch.Success)
            {
                WriteError("Blob URI of disk does not match known pattern {0}", sBlobUri);
                throw new ArgumentException("Blob URI of disk does not match known pattern");
            }
            var accountName = blobMatch.Groups[1].Value;

            BlobUri blobUri;
            if (BlobUri.TryParseUri(new Uri(sBlobUri), out blobUri))
            {
                try
                {
                    var account = this.GetStorageAccountFromCache(accountName);
                    var resGroupName = this.GetResourceGroupFromId(account.Id);
                    StorageCredentialsFactory storageCredentialsFactory = new StorageCredentialsFactory(resGroupName,
                        this._StorageClient, this._Subscription);
                    StorageCredentials sc = storageCredentialsFactory.Create(blobUri);
                    CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(sc, true);
                    CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
                    CloudBlobContainer blobContainer = blobClient.GetContainerReference(blobUri.BlobContainerName);
                    var cloudBlob = blobContainer.GetPageBlobReference(blobUri.BlobName);
                    var sasToken = cloudBlob.GetSharedAccessSignature(
                        new SharedAccessBlobPolicy()
                        {
                            SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24.0),
                            Permissions = SharedAccessBlobPermissions.Read
                        });
                    cloudBlob.FetchAttributes();

                    return (int?)(cloudBlob.Properties.Length / (1024 * 1024 * 1024));
                }
                catch (Exception)
                {
                    this.WriteWarning("Could not determine OS Disk size.");
                }
            }

            return null;
        }
Exemplo n.º 3
0
 public CloudPageBlob Create(BlobUri destination)
 {
     return(new CloudPageBlob(new Uri(destination.BlobPath), credentialsFactory.Create(destination)));
 }