当前位置: 首页>>代码示例>>C#>>正文


C# Blob.CloudPageBlob类代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudPageBlob的典型用法代码示例。如果您正苦于以下问题:C# CloudPageBlob类的具体用法?C# CloudPageBlob怎么用?C# CloudPageBlob使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CloudPageBlob类属于Microsoft.WindowsAzure.Storage.Blob命名空间,在下文中一共展示了CloudPageBlob类的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: Initialize

        public void Initialize()
        {
            vmPowershellCmdlets = new ServiceManagementCmdletTestHelper();
            vmPowershellCmdlets.ImportAzurePublishSettingsFile();
            defaultAzureSubscription = vmPowershellCmdlets.SetDefaultAzureSubscription(Resource.DefaultSubscriptionName);
            Assert.AreEqual(Resource.DefaultSubscriptionName, defaultAzureSubscription.SubscriptionName);
            storageAccountKey = vmPowershellCmdlets.GetAzureStorageAccountKey(defaultAzureSubscription.CurrentStorageAccount);
            Assert.AreEqual(defaultAzureSubscription.CurrentStorageAccount, storageAccountKey.StorageAccountName);

            destination = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd"));
            patchDestination = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd"));

            destinationSasUri = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd"));
            patchDestinationSasUri = string.Format(@"http://{0}.blob.core.windows.net/vhdstore/{1}", defaultAzureSubscription.CurrentStorageAccount, Utilities.GetUniqueShortName("PSTestAzureVhd"));
            var destinationBlob = new CloudPageBlob(new Uri(destinationSasUri), new StorageCredentials(storageAccountKey.StorageAccountName, storageAccountKey.Primary));
            var patchDestinationBlob = new CloudPageBlob(new Uri(patchDestinationSasUri), new StorageCredentials(storageAccountKey.StorageAccountName, storageAccountKey.Primary));
            var policy = new SharedAccessBlobPolicy()
            {
                Permissions =
                    SharedAccessBlobPermissions.Delete |
                    SharedAccessBlobPermissions.Read |
                    SharedAccessBlobPermissions.Write |
                    SharedAccessBlobPermissions.List,
                SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromHours(1)
            };
            var destinationBlobToken = destinationBlob.GetSharedAccessSignature(policy);
            var patchDestinationBlobToken = patchDestinationBlob.GetSharedAccessSignature(policy);
            destinationSasUri += destinationBlobToken;
            patchDestinationSasUri += patchDestinationBlobToken;

            blobUrlRoot = string.Format(@"http://{0}.blob.core.windows.net/", defaultAzureSubscription.CurrentStorageAccount);

            perfFile = "perf.csv";
        }
开发者ID:bielawb,项目名称:azure-sdk-tools,代码行数:34,代码来源:AddAzureVhdTest.cs

示例3: FillFromBlobAsync

 public async Task FillFromBlobAsync(CloudPageBlob blob)
 {
     using (var stream = blob.OpenRead())
     {
         stream.Seek(this.GetBaseAddress(), SeekOrigin.Begin);
         await stream.ReadAsync(_data, 0, AzurePageBlob.PageSize);
     }
 }
开发者ID:valeriob,项目名称:StreamRepository,代码行数:8,代码来源:Page.cs

示例4: FillFromBlob

 public void FillFromBlob(CloudPageBlob blob)
 {
     using (var stream = blob.OpenRead())
     {
         stream.Seek(this.GetBaseAddress(), SeekOrigin.Begin);
         stream.Read(_data, 0, AzurePageBlob.PageSize);
     }
 }
开发者ID:valeriob,项目名称:StreamRepository,代码行数:8,代码来源:Page.cs

示例5: PageBlobWriter

 internal PageBlobWriter(
     TransferScheduler scheduler,
     SyncTransferController controller,
     CancellationToken cancellationToken)
     : base(scheduler, controller, cancellationToken)
 {
     this.pageBlob = this.TransferJob.Destination.Blob as CloudPageBlob;
 }
开发者ID:BeauGesteMark,项目名称:azure-storage-net-data-movement,代码行数:8,代码来源:PageBlobWriter.cs

示例6: FakeStoragePageBlob

 public FakeStoragePageBlob(MemoryBlobStore store, string blobName, IStorageBlobContainer parent)
 {
     _store = store;
     _blobName = blobName;
     _parent = parent;
     _containerName = parent.Name;
     _metadata = new Dictionary<string, string>();
     _sdkObject = new CloudPageBlob(new Uri("http://localhost/" + _containerName + "/" + blobName));
 }
开发者ID:Bjakes1950,项目名称:azure-webjobs-sdk,代码行数:9,代码来源:FakeStoragePageBlob.cs

示例7: PageBlobReader

 public PageBlobReader(
     TransferScheduler scheduler,
     SyncTransferController controller,
     CancellationToken cancellationToken)
     :base(scheduler, controller, cancellationToken)
 {
     pageBlob = this.SharedTransferData.TransferJob.Source.Blob as CloudPageBlob;
     Debug.Assert(null != this.pageBlob, "Initializing a PageBlobReader, the source location should be a CloudPageBlob instance.");
 }
开发者ID:BeauGesteMark,项目名称:azure-storage-net-data-movement,代码行数:9,代码来源:PageBlobReader.cs

示例8: Init

        public static void Init(CloudPageBlob blob)
        {
            if (ls == null)
            {
                ms = new MemoryStream();
                var geoIpFileStream = blob.OpenRead();
                geoIpFileStream.CopyTo(ms);
                ls = new LookupService(ms);                
            }

        }
开发者ID:agentvnod,项目名称:tfctvoldcode,代码行数:11,代码来源:Utility.cs

示例9: BlobCreatorBase

        protected BlobCreatorBase(FileInfo localVhd, BlobUri blobDestination, ICloudPageBlobObjectFactory blobObjectFactory, bool overWrite)
        {
            this.localVhd = localVhd;
            this.blobObjectFactory = blobObjectFactory;
            this.destination = new Uri(blobDestination.BlobPath);
            this.blobDestination = blobDestination;
            this.overWrite = overWrite;

            this.destinationBlob = blobObjectFactory.Create(blobDestination);
            this.requestOptions = this.blobObjectFactory.CreateRequestOptions();
        }
开发者ID:Viachaslau,项目名称:azure-sdk-tools,代码行数:11,代码来源:BlobCreatorBase.cs

示例10: 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

示例11: 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

示例12: BlobEncryptedWriteStream

        /// <summary>
        /// Initializes a new instance of the BlobWriteStream class for a page blob.
        /// </summary>
        /// <param name="pageBlob">Blob reference to write to.</param>
        /// <param name="pageBlobSize">Size of the page blob.</param>
        /// <param name="createNew">Use <c>true</c> if the page blob is newly created, <c>false</c> otherwise.</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>
        /// <param name="transform">The ICryptoTransform function for the request.</param>        
        internal BlobEncryptedWriteStream(CloudPageBlob pageBlob, long pageBlobSize, bool createNew, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, ICryptoTransform transform)
        {
            CommonUtility.AssertNotNull("transform", transform);

            if (options.EncryptionPolicy.EncryptionMode != BlobEncryptionMode.FullBlob)
            {
                throw new InvalidOperationException(SR.InvalidEncryptionMode, null);
            }

            // Since this is done on the copy of the options object that the client lib maintains and not on the user's options object and is done after getting 
            // the transform function, it should be fine. Setting this ensures that an error is not thrown when PutPage is called internally from the write method on the stream.
            options.SkipEncryptionPolicyValidation = true;

            this.transform = transform;
            this.writeStream = new BlobWriteStream(pageBlob, pageBlobSize, createNew, accessCondition, options, operationContext) { IgnoreFlush = true };
            this.cryptoStream = new CryptoStream(this.writeStream, transform, CryptoStreamMode.Write);
        }
开发者ID:Gajendra-Bahakar,项目名称:azure-storage-net,代码行数:27,代码来源:BlobEncryptedWriteStream.cs

示例13: LeaderMethod

		async Task LeaderMethod(CancellationToken token, CloudPageBlob blob) {
			var processors = Environment.ProcessorCount;
			int parallelism = processors / 2;
			if (parallelism < 1) {
				parallelism = 1;
			}
			_log.Information("Node is a leader with {processors} processors. Setting parallelism to {parallelism}", 
				processors, 
				parallelism);

			using (var scheduler = MessageWriteScheduler.Create(_account, parallelism)) {
				try {
					_log.Information("Message write scheduler created");
					_api.EnableDirectWrites(scheduler);
					
					// tell the world who is the leader
					await _info.WriteToBlob(_account);
					// sleep till cancelled
					await Task.Delay(-1, token);
				}
				catch (OperationCanceledException) {
					// expect this exception to be thrown in normal circumstances or check the cancellation token, because
					// if the lease can't be renewed, the token will signal a cancellation request.
					_log.Information("Shutting down the scheduler");
					// shutdown the scheduler
					_api.DisableDirectWrites();


					var shutdown = scheduler.Shutdown();
					if (shutdown.Wait(5000)) {
						_log.Information("Scheduler is down");
					} else {
						_log.Error("Scheduler failed to shutdown in time");
					}
				}
				finally {
					_api.DisableDirectWrites();
					_log.Information("This node is no longer a leader");
				}
			}
		}
开发者ID:perokvist,项目名称:messageVault,代码行数:41,代码来源:LeaderLock.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: HandleUserInput

        private static void HandleUserInput(CloudBlobContainer container, CloudPageBlob pageBlob)
        {
            Console.WriteLine("Save file? Y/N");

              var result = Console.ReadLine();

              if (String.IsNullOrEmpty(result))
              {
            return;
              }

              switch (result.ToLower())
              {
            case "y":
              {
            _blobDownloader.SavePageBlob(container, pageBlob);
              } break;
            default:
              {
            Console.WriteLine("welp");
            break;
              }
              }
        }
开发者ID:LFSb,项目名称:AzureBlobList,代码行数:24,代码来源:Program.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudPageBlob类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。