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


C# Blob.CloudBlob類代碼示例

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


CloudBlob類屬於Microsoft.WindowsAzure.Storage.Blob命名空間,在下文中一共展示了CloudBlob類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestAccess

        private static void TestAccess(string sasToken, SharedAccessBlobPermissions permissions, SharedAccessBlobHeaders headers, CloudBlobContainer container, CloudBlob blob)
        {
            CloudBlob SASblob;
            StorageCredentials credentials = string.IsNullOrEmpty(sasToken) ?
                new StorageCredentials() :
                new StorageCredentials(sasToken);

            if (container != null)
            {
                container = new CloudBlobContainer(credentials.TransformUri(container.Uri));
                if (blob.BlobType == BlobType.BlockBlob)
                {
                    SASblob = container.GetBlockBlobReference(blob.Name);
                }
                else if (blob.BlobType == BlobType.PageBlob)
                {
                    SASblob = container.GetPageBlobReference(blob.Name);
                }
                else
                {
                    SASblob = container.GetAppendBlobReference(blob.Name);
                }
            }
            else
            {
                if (blob.BlobType == BlobType.BlockBlob)
                {
                    SASblob = new CloudBlockBlob(credentials.TransformUri(blob.Uri));
                }
                else if (blob.BlobType == BlobType.PageBlob)
                {
                    SASblob = new CloudPageBlob(credentials.TransformUri(blob.Uri));
                }
                else
                {
                    SASblob = new CloudAppendBlob(credentials.TransformUri(blob.Uri));
                }
            }

            HttpStatusCode failureCode = sasToken == null ? HttpStatusCode.NotFound : HttpStatusCode.Forbidden;

            // We want to ensure that 'create', 'add', and 'write' permissions all allow for correct writing of blobs, as is reasonable.
            if (((permissions & SharedAccessBlobPermissions.Create) == SharedAccessBlobPermissions.Create) || ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write))
            {
                if (blob.BlobType == BlobType.PageBlob)
                {
                    CloudPageBlob SASpageBlob = (CloudPageBlob)SASblob;
                    SASpageBlob.Create(512);
                    CloudPageBlob pageBlob = (CloudPageBlob)blob;
                    byte[] buffer = new byte[512];
                    buffer[0] = 2;  // random data

                    if (((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write))
                    {
                        SASpageBlob.UploadFromByteArray(buffer, 0, 512);
                    }
                    else
                    {
                        TestHelper.ExpectedException(
                            () => SASpageBlob.UploadFromByteArray(buffer, 0, 512),
                            "pageBlob SAS token without Write perms should not allow for writing/adding",
                            failureCode);
                        pageBlob.UploadFromByteArray(buffer, 0, 512);
                    }
                }
                else if (blob.BlobType == BlobType.BlockBlob)
                {
                    if ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write)
                    {
                        UploadText(SASblob, "blob", Encoding.UTF8);
                    }
                    else
                    {
                        TestHelper.ExpectedException(
                            () => UploadText(SASblob, "blob", Encoding.UTF8),
                            "Block blob SAS token without Write or perms should not allow for writing",
                            failureCode);
                        UploadText(blob, "blob", Encoding.UTF8);
                    }
                }
                else // append blob
                {
                    // If the sas token contains Feb 2012, append won't be accepted 
                    if (sasToken.Contains(Constants.VersionConstants.February2012))
                    {
                        UploadText(blob, "blob", Encoding.UTF8);
                    }
                    else
                    {
                        CloudAppendBlob SASAppendBlob = SASblob as CloudAppendBlob;
                        SASAppendBlob.CreateOrReplace();

                        byte[] textAsBytes = Encoding.UTF8.GetBytes("blob");
                        using (MemoryStream stream = new MemoryStream())
                        {
                            stream.Write(textAsBytes, 0, textAsBytes.Length);
                            stream.Seek(0, SeekOrigin.Begin);

                            if (((permissions & SharedAccessBlobPermissions.Add) == SharedAccessBlobPermissions.Add) || ((permissions & SharedAccessBlobPermissions.Write) == SharedAccessBlobPermissions.Write))
                            {
//.........這裏部分代碼省略.........
開發者ID:benaadams,項目名稱:azure-storage-net,代碼行數:101,代碼來源:SASTests.cs

示例2: AzureBlobLocation

        /// <summary>
        /// Initializes a new instance of the <see cref="AzureBlobLocation"/> class.
        /// </summary>
        /// <param name="blob">CloudBlob instance as a location in a transfer job. 
        /// It could be a source, a destination.</param>
        public AzureBlobLocation(CloudBlob blob)
        {
            if (null == blob)
            {
                throw new ArgumentNullException("blob");
            }

            this.Blob = blob;
        }
開發者ID:ggais,項目名稱:azure-storage-net-data-movement,代碼行數:14,代碼來源:AzureBlobLocation.cs

示例3: PutNextEntry

        protected override void PutNextEntry(CloudBlob blob)
        {
            var entry = TarEntry.CreateTarEntry(GetEntryName(blob));

            entry.Size = blob.Properties.Length;
            entry.ModTime = (blob.Properties.LastModified ?? new DateTimeOffset(2000, 01, 01, 00, 00, 00, TimeSpan.Zero)).UtcDateTime;

            _archiveStream.PutNextEntry(entry);
        }
開發者ID:glueckkanja,項目名稱:azure-blob-to-archive,代碼行數:9,代碼來源:TarCore.cs

示例4: WaitForCopyAsync

 public static async Task WaitForCopyAsync(CloudBlob blob)
 {
     bool copyInProgress = true;
     while (copyInProgress)
     {
         await Task.Delay(1000);
         await blob.FetchAttributesAsync();
         copyInProgress = (blob.CopyState.Status == CopyStatus.Pending);
     }
 }
開發者ID:benaadams,項目名稱:azure-storage-net,代碼行數:10,代碼來源:BlobTestBase.cs

示例5: AzureStorageBlob

 /// <summary>
 /// Azure storage blob constructor
 /// </summary>
 /// <param name="blob">ICloud blob object</param>
 public AzureStorageBlob(CloudBlob blob)
 {
     Name = blob.Name;
     ICloudBlob = blob;
     BlobType = blob.BlobType;
     Length = blob.Properties.Length;
     ContentType = blob.Properties.ContentType;
     LastModified = blob.Properties.LastModified;
     SnapshotTime = blob.SnapshotTime;
 }
開發者ID:docschmidt,項目名稱:azure-powershell,代碼行數:14,代碼來源:AzureStorageBlob.cs

示例6: WaitForCopyTask

 public static void WaitForCopyTask(CloudBlob blob)
 {
     bool copyInProgress = true;
     while (copyInProgress)
     {
         Thread.Sleep(1000);
         blob.FetchAttributesAsync().Wait();
         copyInProgress = (blob.CopyState.Status == CopyStatus.Pending);
     }
 }
開發者ID:Gajendra-Bahakar,項目名稱:azure-storage-net,代碼行數:10,代碼來源:BlobTestBase.cs

示例7: LoadBlobBytesAsync

		public async Task<byte[]> LoadBlobBytesAsync(Uri location)
		{
			var blob = new CloudBlob (location);

			await blob.FetchAttributesAsync ();

			byte[] target = new byte[blob.Properties.Length];

			await blob.DownloadToByteArrayAsync (target, 0);
		
			return target;
		}
開發者ID:codemillmatt,項目名稱:CheesedStorage,代碼行數:12,代碼來源:CheeseStorageService.cs

示例8: TestAccessTask

        private static void TestAccessTask(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
        {
            StorageCredentials credentials = new StorageCredentials();
            container = new CloudBlobContainer(container.Uri, credentials);
            CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);

            if (accessType.Equals(BlobContainerPublicAccessType.Container))
            {
                blob.FetchAttributesAsync().Wait();
                BlobContinuationToken token = null;
                do
                {
                    BlobResultSegment results = container.ListBlobsSegmented(token);
                    results.Results.ToArray();
                    token = results.ContinuationToken;
                }
                while (token != null);
                container.FetchAttributesAsync().Wait();
            }
            else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
            {
                blob.FetchAttributesAsync().Wait();

                TestHelper.ExpectedExceptionTask(
                    container.ListBlobsSegmentedAsync(null),
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedExceptionTask(
                    container.FetchAttributesAsync(),
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
            else
            {
                TestHelper.ExpectedExceptionTask(
                    blob.FetchAttributesAsync(),
                    "Fetch blob attributes while public access does not allow",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedExceptionTask(
                    container.ListBlobsSegmentedAsync(null),
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedExceptionTask(
                    container.FetchAttributesAsync(),
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
        }
開發者ID:Gajendra-Bahakar,項目名稱:azure-storage-net,代碼行數:48,代碼來源:CloudBlobContainerTest.cs

示例9: TestAccessAsync

        private static async Task TestAccessAsync(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
        {
            StorageCredentials credentials = new StorageCredentials();
            container = new CloudBlobContainer(container.Uri, credentials);
            CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);
            OperationContext context = new OperationContext();
            BlobRequestOptions options = new BlobRequestOptions();


            if (accessType.Equals(BlobContainerPublicAccessType.Container))
            {
                await blob.FetchAttributesAsync();
                await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context);
                await container.FetchAttributesAsync();
            }
            else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
            {
                await blob.FetchAttributesAsync();
                await TestHelper.ExpectedExceptionAsync(
                    async () => await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context),
                    context,
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                await TestHelper.ExpectedExceptionAsync(
                    async () => await container.FetchAttributesAsync(null, options, context),
                    context,
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
            else
            {
                await TestHelper.ExpectedExceptionAsync(
                    async () => await blob.FetchAttributesAsync(null, options, context),
                    context,
                    "Fetch blob attributes while public access does not allow",
                    HttpStatusCode.NotFound);
                await TestHelper.ExpectedExceptionAsync(
                    async () => await container.ListBlobsSegmentedAsync(null, true, BlobListingDetails.All, null, null, options, context),
                    context,
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                await TestHelper.ExpectedExceptionAsync(
                    async () => await container.FetchAttributesAsync(null, options, context),
                    context,
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
        }
開發者ID:mirobers,項目名稱:azure-storage-net,代碼行數:48,代碼來源:CloudBlobContainerTest.cs

示例10: Equals

        /// <summary>
        /// Determines whether two blobs have the same Uri and SnapshotTime.
        /// </summary>
        /// <param name="blob">Blob to compare.</param>
        /// <param name="comparand">Comparand object.</param>
        /// <returns>True if the two blobs have the same Uri and SnapshotTime; otherwise, false.</returns>
        internal static bool Equals(
            CloudBlob blob,
            CloudBlob comparand)
        {
            if (blob == comparand)
            {
                return true;
            }

            if (null == blob || null == comparand)
            {
                return false;
            }

            return blob.Uri.Equals(comparand.Uri) &&
                blob.SnapshotTime.Equals(comparand.SnapshotTime);
        }
開發者ID:ggais,項目名稱:azure-storage-net-data-movement,代碼行數:23,代碼來源:StorageExtensions.cs

示例11: CreateVideo

        private Video CreateVideo(CloudBlob blob)
        {
            if (blob == null)
            {
                return null;
            }

            blob.FetchAttributes();

            return new Video
            {
                Title = blob.Metadata[NameField],
                Name = blob.Name,
                StorageUrl = blob.Uri.ToString(),
                ContentDeliveryNetworkUrl = $"https://{_config.CdnEndpointName}.vo.msecnd.net/{ContainerName}/{blob.Name}"
            };
        }
開發者ID:kpi-ua,項目名稱:MediaHack,代碼行數:17,代碼來源:Cloud.cs

示例12: BlobReadStreamBase

        /// <summary>
        /// Initializes a new instance of the BlobReadStreamBase class.
        /// </summary>
        /// <param name="blob">Blob reference to read from</param>
        /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed. If <c>null</c>, no condition is used.</param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param>
        /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
        protected BlobReadStreamBase(CloudBlob blob, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
        {
            if (options.UseTransactionalMD5.Value)
            {
                CommonUtility.AssertInBounds("StreamMinimumReadSizeInBytes", blob.StreamMinimumReadSizeInBytes, 1, Constants.MaxRangeGetContentMD5Size);
            }

            this.blob = blob;
            this.blobProperties = new BlobProperties(blob.Properties);
            this.currentOffset = 0;
            this.streamMinimumReadSizeInBytes = this.blob.StreamMinimumReadSizeInBytes;
            this.internalBuffer = new MultiBufferMemoryStream(blob.ServiceClient.BufferManager);
            this.accessCondition = accessCondition;
            this.options = options;
            this.operationContext = operationContext;
            this.blobMD5 = (this.options.DisableContentMD5Validation.Value || string.IsNullOrEmpty(this.blobProperties.ContentMD5)) ? null : new MD5Wrapper();
            this.lastException = null;
        }
開發者ID:Gajendra-Bahakar,項目名稱:azure-storage-net,代碼行數:25,代碼來源:BlobReadStreamBase.cs

示例13: AssertAreEqual

 public static void AssertAreEqual(CloudBlob expected, CloudBlob actual)
 {
     if (expected == null)
     {
         Assert.IsNull(actual);
     }
     else
     {
         Assert.IsNotNull(actual);
         Assert.AreEqual(expected.BlobType, actual.BlobType);
         Assert.AreEqual(expected.Uri, actual.Uri);
         Assert.AreEqual(expected.StorageUri, actual.StorageUri);
         Assert.AreEqual(expected.SnapshotTime, actual.SnapshotTime);
         Assert.AreEqual(expected.IsSnapshot, actual.IsSnapshot);
         Assert.AreEqual(expected.SnapshotQualifiedUri, actual.SnapshotQualifiedUri);
         AssertAreEqual(expected.Properties, actual.Properties);
         AssertAreEqual(expected.CopyState, actual.CopyState);
     }
 }
開發者ID:Gajendra-Bahakar,項目名稱:azure-storage-net,代碼行數:19,代碼來源:BlobTestBase.Common.cs

示例14: TestAccess

        private static void TestAccess(BlobContainerPublicAccessType accessType, CloudBlobContainer container, CloudBlob inputBlob)
        {
            StorageCredentials credentials = new StorageCredentials();
            container = new CloudBlobContainer(container.Uri, credentials);
            CloudPageBlob blob = new CloudPageBlob(inputBlob.Uri, credentials);

            if (accessType.Equals(BlobContainerPublicAccessType.Container))
            {
                blob.FetchAttributes();
                container.ListBlobs().ToArray();
                container.FetchAttributes();
            }
            else if (accessType.Equals(BlobContainerPublicAccessType.Blob))
            {
                blob.FetchAttributes();
                TestHelper.ExpectedException(
                    () => container.ListBlobs().ToArray(),
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedException(
                    () => container.FetchAttributes(),
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
            else
            {
                TestHelper.ExpectedException(
                    () => blob.FetchAttributes(),
                    "Fetch blob attributes while public access does not allow",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedException(
                    () => container.ListBlobs().ToArray(),
                    "List blobs while public access does not allow for listing",
                    HttpStatusCode.NotFound);
                TestHelper.ExpectedException(
                    () => container.FetchAttributes(),
                    "Fetch container attributes while public access does not allow",
                    HttpStatusCode.NotFound);
            }
        }
開發者ID:Gajendra-Bahakar,項目名稱:azure-storage-net,代碼行數:40,代碼來源:CloudBlobContainerTest.cs

示例15: BlobAsyncCopyController

        public BlobAsyncCopyController(
            TransferScheduler transferScheduler,
            TransferJob transferJob,
            CancellationToken cancellationToken)
            : base(transferScheduler, transferJob, cancellationToken)
        {
            this.destLocation = transferJob.Destination as AzureBlobLocation;
            CloudBlob transferDestBlob = this.destLocation.Blob;
            if (null == transferDestBlob)
            {
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.ParameterCannotBeNullException,
                        "Dest.Blob"),
                    "transferJob");
            }

            if (transferDestBlob.IsSnapshot)
            {
                throw new ArgumentException(Resources.DestinationMustBeBaseBlob, "transferJob");
            }

            AzureBlobLocation sourceBlobLocation = transferJob.Source as AzureBlobLocation;
            if (sourceBlobLocation != null)
            {
                if (sourceBlobLocation.Blob.BlobType != transferDestBlob.BlobType)
                {
                    throw new ArgumentException(Resources.SourceAndDestinationBlobTypeDifferent, "transferJob");
                }

                if (StorageExtensions.Equals(sourceBlobLocation.Blob, transferDestBlob))
                {
                    throw new InvalidOperationException(Resources.SourceAndDestinationLocationCannotBeEqualException);
                }
            }

            this.destBlob = transferDestBlob;
        }
開發者ID:ggais,項目名稱:azure-storage-net-data-movement,代碼行數:39,代碼來源:BlobAsyncCopyController.cs


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