當前位置: 首頁>>代碼示例>>C#>>正文


C# CloudBlobClient.BeginGetBlobReferenceFromServer方法代碼示例

本文整理匯總了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.BeginGetBlobReferenceFromServer方法的典型用法代碼示例。如果您正苦於以下問題:C# CloudBlobClient.BeginGetBlobReferenceFromServer方法的具體用法?C# CloudBlobClient.BeginGetBlobReferenceFromServer怎麽用?C# CloudBlobClient.BeginGetBlobReferenceFromServer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient的用法示例。


在下文中一共展示了CloudBlobClient.BeginGetBlobReferenceFromServer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CloudBlobContainerGetBlobReferenceFromServerAPM

        public void CloudBlobContainerGetBlobReferenceFromServerAPM()
        {
            CloudBlobContainer container = GetRandomContainerReference();
            try
            {
                container.Create();

                SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy()
                {
                    Permissions = SharedAccessBlobPermissions.Read,
                    SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                    SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30),
                };

                CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb");
                blockBlob.PutBlockList(new string[] { });

                CloudPageBlob pageBlob = container.GetPageBlobReference("pb");
                pageBlob.Create(0);

                using (AutoResetEvent waitHandle = new AutoResetEvent(false))
                {
                    IAsyncResult result = container.BeginGetBlobReferenceFromServer("bb",
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    ICloudBlob blob1 = container.EndGetBlobReferenceFromServer(result);
                    Assert.IsInstanceOfType(blob1, typeof(CloudBlockBlob));

                    result = ((CloudBlockBlob)blob1).BeginCreateSnapshot(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    CloudBlockBlob blob1Snapshot = ((CloudBlockBlob)blob1).EndCreateSnapshot(result);
                    result = blob1.BeginSetProperties(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    blob1.EndSetProperties(result);
                    Uri blob1SnapshotUri = new Uri(blob1Snapshot.Uri.AbsoluteUri + "?snapshot=" + blob1Snapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
                    result = container.ServiceClient.BeginGetBlobReferenceFromServer(blob1SnapshotUri,
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    ICloudBlob blob1SnapshotReference = container.ServiceClient.EndGetBlobReferenceFromServer(result);
                    AssertAreEqual(blob1Snapshot.Properties, blob1SnapshotReference.Properties);

                    result = container.BeginGetBlobReferenceFromServer("pb",
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    ICloudBlob blob2 = container.EndGetBlobReferenceFromServer(result);
                    Assert.IsInstanceOfType(blob2, typeof(CloudPageBlob));

                    result = ((CloudPageBlob)blob2).BeginCreateSnapshot(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    CloudPageBlob blob2Snapshot = ((CloudPageBlob)blob2).EndCreateSnapshot(result);
                    result = blob2.BeginSetProperties(
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    blob2.EndSetProperties(result);
                    Uri blob2SnapshotUri = new Uri(blob2Snapshot.Uri.AbsoluteUri + "?snapshot=" + blob2Snapshot.SnapshotTime.Value.UtcDateTime.ToString("o"));
                    result = container.ServiceClient.BeginGetBlobReferenceFromServer(blob2SnapshotUri,
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    ICloudBlob blob2SnapshotReference = container.ServiceClient.EndGetBlobReferenceFromServer(result);
                    AssertAreEqual(blob2Snapshot.Properties, blob2SnapshotReference.Properties);

                    result = container.ServiceClient.BeginGetBlobReferenceFromServer(blockBlob.Uri,
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    ICloudBlob blob3 = container.ServiceClient.EndGetBlobReferenceFromServer(result);
                    Assert.IsInstanceOfType(blob3, typeof(CloudBlockBlob));

                    result = container.ServiceClient.BeginGetBlobReferenceFromServer(pageBlob.Uri,
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    ICloudBlob blob4 = container.ServiceClient.EndGetBlobReferenceFromServer(result);
                    Assert.IsInstanceOfType(blob4, typeof(CloudPageBlob));

                    string blockBlobToken = blockBlob.GetSharedAccessSignature(policy);
                    StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken);
                    Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri);

                    string pageBlobToken = pageBlob.GetSharedAccessSignature(policy);
                    StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken);
                    Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri);

                    result = container.ServiceClient.BeginGetBlobReferenceFromServer(blockBlobSASUri,
                        ar => waitHandle.Set(),
                        null);
                    waitHandle.WaitOne();
                    ICloudBlob blob5 = container.ServiceClient.EndGetBlobReferenceFromServer(result);
                    Assert.IsInstanceOfType(blob5, typeof(CloudBlockBlob));
//.........這裏部分代碼省略.........
開發者ID:huoxudong125,項目名稱:azure-sdk-for-net,代碼行數:101,代碼來源:CloudBlobContainerTest.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.BeginGetBlobReferenceFromServer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。