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


C# CloudBlockBlob.OpenWriteAsync方法代碼示例

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


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

示例1: BlobWriteExpectLeaseSuccessAsync

        /// <summary>
        /// Test blob writing, expecting success.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="sourceBlob">A blob to use as the source of a copy.</param>
        /// <param name="testAccessCondition">The access condition to use.</param>
        private async Task BlobWriteExpectLeaseSuccessAsync(CloudBlockBlob testBlob, CloudBlob sourceBlob, AccessCondition testAccessCondition)
        {
            await testBlob.SetMetadataAsync(testAccessCondition, null /* options */, null);
            await testBlob.SetPropertiesAsync(testAccessCondition, null /* options */, null);
            await UploadTextAsync(testBlob, "No Problem", Encoding.UTF8, testAccessCondition, null /* options */, null);
            await testBlob.StartCopyAsync(TestHelper.Defiddler(sourceBlob.Uri), null /* source access condition */, testAccessCondition, null /* options */, null);

            while (testBlob.CopyState.Status == CopyStatus.Pending)
            {
                await Task.Delay(1000);
                await testBlob.FetchAttributesAsync();
            }

            var writeStream = await testBlob.OpenWriteAsync(testAccessCondition, null /* options */, null);
            Stream stream = writeStream.AsStreamForWrite();
            stream.WriteByte(0);
            await stream.FlushAsync();

            await testBlob.DeleteAsync(DeleteSnapshotsOption.None, testAccessCondition, null /* options */, null);
        }
開發者ID:benaadams,項目名稱:azure-storage-net,代碼行數:26,代碼來源:LeaseTests.cs

示例2: BlobWriteExpectLeaseSuccessTask

        /// <summary>
        /// Test blob writing, expecting success.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="sourceBlob">A blob to use as the source of a copy.</param>
        /// <param name="testAccessCondition">The access condition to use.</param>
        private void BlobWriteExpectLeaseSuccessTask(CloudBlockBlob testBlob, CloudBlob sourceBlob, AccessCondition testAccessCondition)
        {
            testBlob.SetMetadataAsync(testAccessCondition, null /* options */, new OperationContext()).Wait();
            testBlob.SetPropertiesAsync(testAccessCondition, null /* options */, new OperationContext()).Wait();
            UploadTextTask(testBlob, "No Problem", Encoding.UTF8, testAccessCondition, null /* options */, new OperationContext());
            testBlob.StartCopyAsync(
                TestHelper.Defiddler(sourceBlob.Uri),
                null /* source access condition */,
                testAccessCondition,
                null /* options */,
                new OperationContext()).Wait();

            while (testBlob.CopyState.Status == CopyStatus.Pending)
            {
                Thread.Sleep(1000);
                testBlob.FetchAttributesAsync().Wait();
            }

            Stream stream = testBlob.OpenWriteAsync(testAccessCondition, null /* options */, new OperationContext()).Result;
            stream.WriteByte(0);
            stream.Flush();

            testBlob.DeleteAsync(DeleteSnapshotsOption.None, testAccessCondition, null /* options */, new OperationContext());
        }
開發者ID:benaadams,項目名稱:azure-storage-net,代碼行數:30,代碼來源:LeaseTests.cs

示例3: BlobCreateExpectLeaseFailureAsync

        /// <summary>
        /// Test blob creation, expecting lease failure.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="sourceBlob">A blob to use as the source of a copy.</param>
        /// <param name="testAccessCondition">The failing access condition to use.</param>
        /// <param name="expectedErrorCode">The expected error code.</param>
        /// <param name="description">The reason why these calls should fail.</param>
        private async Task BlobCreateExpectLeaseFailureAsync(CloudBlockBlob testBlob, CloudBlockBlob sourceBlob, AccessCondition testAccessCondition, HttpStatusCode expectedStatusCode, string expectedErrorCode, string description)
        {
            OperationContext operationContext = new OperationContext();
            await TestHelper.ExpectedExceptionAsync(
                async () => await UploadTextAsync(testBlob, "No Dice", Encoding.UTF8, testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Upload Text)",
                expectedStatusCode,
                expectedErrorCode);
            await TestHelper.ExpectedExceptionAsync(
                async () => await testBlob.StartCopyAsync(TestHelper.Defiddler(sourceBlob.Uri), null /* source access condition */, testAccessCondition, null /* options */, operationContext),
                operationContext,
                description + " (Copy From)",
                expectedStatusCode,
                expectedErrorCode);

            var writeStream = await testBlob.OpenWriteAsync(testAccessCondition, null /* options */, operationContext);
            Stream stream = writeStream.AsStreamForWrite();
            await TestHelper.ExpectedExceptionAsync(
                async () =>
                {
                    stream.WriteByte(0);
                    await stream.FlushAsync();
                },
                operationContext,
                description + " (Write Stream)",
                expectedStatusCode,
                expectedErrorCode);
        }
開發者ID:benaadams,項目名稱:azure-storage-net,代碼行數:37,代碼來源:LeaseTests.cs

示例4: BlobCreateExpectLeaseFailureTask

        /// <summary>
        /// Test blob creation, expecting lease failure.
        /// </summary>
        /// <param name="testBlob">The blob to test.</param>
        /// <param name="sourceBlob">A blob to use as the source of a copy.</param>
        /// <param name="testAccessCondition">The failing access condition to use.</param>
        /// <param name="expectedErrorCode">The expected error code.</param>
        /// <param name="description">The reason why these calls should fail.</param>
        private void BlobCreateExpectLeaseFailureTask(CloudBlockBlob testBlob, CloudBlockBlob sourceBlob, AccessCondition testAccessCondition, HttpStatusCode expectedStatusCode, string expectedErrorCode, string description)
        {
            TestHelper.ExpectedException(
                () => UploadTextTask(testBlob, "No Dice", Encoding.UTF8, testAccessCondition, null /* options */),
                description + " (Upload Text)",
                expectedStatusCode,
                expectedErrorCode);
            TestHelper.ExpectedExceptionTask(
                testBlob.StartCopyAsync(TestHelper.Defiddler(sourceBlob.Uri), null /* source access condition */, testAccessCondition, null /* options */, new OperationContext()),
                description + " (Copy From)",
                expectedStatusCode,
                expectedErrorCode);

            Stream stream = testBlob.OpenWriteAsync(testAccessCondition, null /* options */, new OperationContext()).Result;
            TestHelper.ExpectedException(
                () =>
                {
                    stream.WriteByte(0);
                    stream.Flush();
                },
                description + " (Write Stream)",
                expectedStatusCode,
                expectedErrorCode);
        }
開發者ID:benaadams,項目名稱:azure-storage-net,代碼行數:32,代碼來源:LeaseTests.cs


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