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


C# Blob.BlobRequestOptions类代码示例

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


BlobRequestOptions类属于Microsoft.WindowsAzure.Storage.Blob命名空间,在下文中一共展示了BlobRequestOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeginOpenRead

        public ICancellableAsyncResult BeginOpenRead(AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, AsyncCallback callback, object state)
        {
            StorageAsyncResult<Stream> storageAsyncResult = new StorageAsyncResult<Stream>(callback, state);

            ICancellableAsyncResult result = this.BeginFetchAttributes(
                accessCondition,
                options,
                operationContext,
                ar =>
                {
                    try
                    {
                        this.EndFetchAttributes(ar);
                        storageAsyncResult.UpdateCompletedSynchronously(ar.CompletedSynchronously);
                        AccessCondition streamAccessCondition = AccessCondition.CloneConditionWithETag(accessCondition, this.Properties.ETag);
                        BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, this.BlobType, this.ServiceClient, false);
                        storageAsyncResult.Result = new BlobReadStream(this, streamAccessCondition, modifiedOptions, operationContext);
                        storageAsyncResult.OnComplete();
                    }
                    catch (Exception e)
                    {
                        storageAsyncResult.OnComplete(e);
                    }
                },
                null /* state */);

            storageAsyncResult.CancelDelegate = result.Cancel;
            return storageAsyncResult;
        }
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:29,代码来源:CloudBlockBlob.cs

示例2: SerializableBlobRequestOptions

        /// <summary>
        /// Initializes a new instance of the <see cref="SerializableBlobRequestOptions"/> class.
        /// </summary>
        /// <param name="info">Serialization information.</param>
        /// <param name="context">Streaming context.</param>
        private SerializableBlobRequestOptions(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            bool? disableContentMD5Validation = (bool?)info.GetValue(DisableContentMD5ValidationName, typeof(bool?));
            TimeSpan? maximumExecutionTime = (TimeSpan?)info.GetValue(MaximumExecutionTimeName, typeof(TimeSpan?));
            TimeSpan? serverTimeout = (TimeSpan?)info.GetValue(ServerTimeoutName, typeof(TimeSpan?));
            bool? storeBlobContentMD5 = (bool?)info.GetValue(StoreBlobContentMD5Name, typeof(bool?));
            bool? useTransactionalMD5 = (bool?)info.GetValue(UseTransactionalMD5Name, typeof(bool?));

            if (null != disableContentMD5Validation
                || null != maximumExecutionTime
                || null != serverTimeout
                || null != storeBlobContentMD5
                || null != useTransactionalMD5)
            {
                this.blobRequestOptions = Transfer_RequestOptions.DefaultBlobRequestOptions;

                this.blobRequestOptions.DisableContentMD5Validation = disableContentMD5Validation;
                this.blobRequestOptions.MaximumExecutionTime = maximumExecutionTime;
                this.blobRequestOptions.ServerTimeout = serverTimeout;
                this.blobRequestOptions.StoreBlobContentMD5 = storeBlobContentMD5;
                this.blobRequestOptions.UseTransactionalMD5 = useTransactionalMD5;
            }
            else
            {
                this.blobRequestOptions = null;
            }
        }
开发者ID:ggais,项目名称:azure-storage-net-data-movement,代码行数:33,代码来源:SerializableBlobRequestOptions.cs

示例3: ParallelUpload

        public static void ParallelUpload(this CloudBlockBlob blobRef, string filename, BlobRequestOptions options)
        {
            if (null == options)
            {
                options = new BlobRequestOptions()
                {
                    ServerTimeout = blobRef.ServiceClient.ServerTimeout,
                    //RetryPolicy = new ExponentialRetry(Microsoft.WindowsAzure.Storage.RetryPolicies..DefaultClientBackoff, RetryPolicies.DefaultClientRetryCount)
                };
            }

            // get upload history if any
            UploadInfo uploadInfo = UploadInfo.LoadByUploadFilename(filename);

            using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
            {
                blobRef.ParallelUpload(fs, uploadInfo, options);
            }

            // upload completed no history needed - delete it
            if (File.Exists(uploadInfo.LogFilename))
                File.Delete(uploadInfo.LogFilename);

            Console.WriteLine("\nUpload completed.");
        }
开发者ID:RobBlackwell,项目名称:AzureCommandLineTools,代码行数:25,代码来源:BlobExtensions.cs

示例4: ListBlobsSegmented

 private Task<BlobResultSegment> ListBlobsSegmented(string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int? maxResults, BlobContinuationToken continuationToken, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken = default(CancellationToken))
 {
     return AsyncTaskUtil.RunAsyncCancellable<BlobResultSegment>(
         _inner.BeginListBlobsSegmented(prefix, useFlatBlobListing, blobListingDetails, maxResults, continuationToken, options, operationContext, null, null),
         _inner.EndListBlobsSegmented,
         cancellationToken);
 }
开发者ID:Porges,项目名称:azure-storage-async,代码行数:7,代码来源:AsyncCloudBlobClient.cs

示例5: ListContainersSegmented

 private Task<ContainerResultSegment> ListContainersSegmented(string prefix, ContainerListingDetails detailsIncluded, int? maxResults, BlobContinuationToken continuationToken, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken = default(CancellationToken))
 {
     return AsyncTaskUtil.RunAsyncCancellable<ContainerResultSegment>(
         _inner.BeginListContainersSegmented(prefix, detailsIncluded, maxResults, continuationToken, options, operationContext, null, null),
         _inner.EndListContainersSegmented,
         cancellationToken);
 }
开发者ID:Porges,项目名称:azure-storage-async,代码行数:7,代码来源:AsyncCloudBlobClient.cs

示例6: UploadByteArray

 /// <summary>
 /// UploadByteArray has been removed from Azure 2.0 SDK.
 /// Adding a method here for backward compatibility
 /// </summary>
 /// <param name="blob"></param>
 /// <param name="data"></param>
 /// <param name="options"></param>
 public static void UploadByteArray(this ICloudBlob blob, byte[] data, BlobRequestOptions options)
 {
     using (var ms = new MemoryStream(data))
     {
         blob.UploadFromStream(ms, null, options);
     }
 }
开发者ID:anilnakkala,项目名称:skewrl,代码行数:14,代码来源:AzureExtensions.cs

示例7: DownloadFileFromBlobToDisk

        private void DownloadFileFromBlobToDisk()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                ConfigurationManager.AppSettings["kcinfo344"]);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("lecture8");

            BlobRequestOptions options = new BlobRequestOptions();
            options.MaximumExecutionTime = new TimeSpan(0, 100, 0);
            options.ServerTimeout = new TimeSpan(0, 100, 0);

            if (container.Exists())
            {
                foreach (IListBlobItem item in container.ListBlobs(null, false))
                {
                    if (item.GetType() == typeof(CloudBlockBlob))
                    {
                        CloudBlockBlob blob = (CloudBlockBlob)item;
                        LocalResource myStorage = RoleEnvironment.GetLocalResource("lessonStorage");
                        string filePath = Path.Combine(myStorage.RootPath, "wiki.txt");
                        using (FileStream fs = new FileStream(filePath, FileMode.Create))
                        {
                            blob.DownloadToStream(fs, null, options);
                        }
                    }
                }
            }
        }
开发者ID:kxchiu,项目名称:INFO344,代码行数:28,代码来源:[PA+2]WebService.asmx.cs

示例8: OpenWrite

        public Stream OpenWrite(long? size, AccessCondition accessCondition = null, BlobRequestOptions options = null, OperationContext operationContext = null)
        {
            this.attributes.AssertNoSnapshot();
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.PageBlob, this.ServiceClient);
            bool createNew = size.HasValue;

            if (createNew)
            {
                this.Create(size.Value, accessCondition, modifiedOptions, operationContext);
            }
            else
            {
                if (modifiedOptions.StoreBlobContentMD5.Value)
                {
                    throw new ArgumentException(SR.MD5NotPossible);
                }

                this.FetchAttributes(accessCondition, modifiedOptions, operationContext);
                size = this.Properties.Length;
            }

            if (accessCondition != null)
            {
                accessCondition = AccessCondition.GenerateLeaseCondition(accessCondition.LeaseId);
            }

            return new BlobWriteStream(this, size.Value, createNew, accessCondition, modifiedOptions, operationContext);
        }
开发者ID:jdkillian,项目名称:azure-sdk-for-net,代码行数:28,代码来源:CloudPageBlob.cs

示例9: OpenWriteAsync

        public virtual Task<CloudBlobStream> OpenWriteAsync(bool createNew, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
        {
            this.attributes.AssertNoSnapshot();
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.AppendBlob, this.ServiceClient, false);
            if (!createNew && modifiedOptions.StoreBlobContentMD5.Value)
            {
                throw new ArgumentException(SR.MD5NotPossible);
            }

            return Task.Run(async () =>
            {
                if (createNew)
                {
                    await this.CreateOrReplaceAsync(accessCondition, options, operationContext, cancellationToken);
                }
                else
                {
                    // Although we don't need any properties from the service, we should make this call in order to honor the user specified conditional headers
                    // while opening an existing stream and to get the append position for an existing blob if user didn't specify one.
                    await this.FetchAttributesAsync(accessCondition, options, operationContext, cancellationToken);
                }

                if (accessCondition != null)
                {
                    accessCondition = new AccessCondition() { LeaseId = accessCondition.LeaseId, IfAppendPositionEqual = accessCondition.IfAppendPositionEqual, IfMaxSizeLessThanOrEqual = accessCondition.IfMaxSizeLessThanOrEqual };
                }

                CloudBlobStream stream = new BlobWriteStream(this, accessCondition, modifiedOptions, operationContext);
                return stream;
            }, cancellationToken);
        }
开发者ID:mirobers,项目名称:azure-storage-net,代码行数:31,代码来源:CloudAppendBlob.cs

示例10: LocationModeWithMissingUriAsync

        public async Task LocationModeWithMissingUriAsync()
        {
            AssertSecondaryEndpoint();

            CloudBlobClient client = GenerateCloudBlobClient();
            CloudBlobClient primaryOnlyClient = new CloudBlobClient(client.BaseUri, client.Credentials);
            CloudBlobContainer container = primaryOnlyClient.GetContainerReference("nonexistingcontainer");

            BlobRequestOptions options = new BlobRequestOptions()
            {
                LocationMode = LocationMode.SecondaryOnly,
                RetryPolicy = new NoRetry(),
            };

            Exception e = await TestHelper.ExpectedExceptionAsync<Exception>(
                async () => await container.FetchAttributesAsync(null, options, null),
                "Request should fail when an URI is not provided for the target location");
            Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException));

            options.LocationMode = LocationMode.SecondaryThenPrimary;
            e = await TestHelper.ExpectedExceptionAsync<Exception>(
                async () => await container.FetchAttributesAsync(null, options, null),
                "Request should fail when an URI is not provided for the target location");
            Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException));

            options.LocationMode = LocationMode.PrimaryThenSecondary;
            e = await TestHelper.ExpectedExceptionAsync<Exception>(
                async () => await container.FetchAttributesAsync(null, options, null),
                "Request should fail when an URI is not provided for the target location");
            Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException));
        }
开发者ID:tamram,项目名称:azure-storage-net,代码行数:31,代码来源:SecondaryTests.cs

示例11: OpenWriteAsync

        /// <summary>
        /// Opens a stream for writing to the blob.
        /// </summary>
        /// <param name="size">The size of the write operation, in bytes. The size must be a multiple of 512.</param>
        /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the blob. If <c>null</c>, no condition is used.</param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies any additional options for the request.</param>
        /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
        /// <returns>A stream to be used for writing to the blob.</returns>
        public IAsyncOperation<IOutputStream> OpenWriteAsync(long? size, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
        {
            this.attributes.AssertNoSnapshot();
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.PageBlob, this.ServiceClient);
            bool createNew = size.HasValue;

            if (!createNew && modifiedOptions.StoreBlobContentMD5.Value)
            {
                throw new ArgumentException(SR.MD5NotPossible);
            }

            return AsyncInfo.Run(async (token) =>
            {
                if (createNew)
                {
                    await this.CreateAsync(size.Value, accessCondition, modifiedOptions, operationContext);
                }
                else
                {
                    await this.FetchAttributesAsync(accessCondition, modifiedOptions, operationContext);
                    size = this.Properties.Length;
                }

                if (accessCondition != null)
                {
                    accessCondition = AccessCondition.GenerateLeaseCondition(accessCondition.LeaseId);
                }

                return new BlobWriteStream(this, size.Value, createNew, accessCondition, modifiedOptions, operationContext).AsOutputStream();
            });
        }
开发者ID:nberardi,项目名称:azure-sdk-for-net,代码行数:39,代码来源:CloudPageBlob.cs

示例12: OpenWrite

        /// <summary>
        /// Opens a stream for writing to the blob.
        /// </summary>
        /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the blob. If <c>null</c>, no condition is used.</param>
        /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies any additional options for the request.</param>
        /// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
        /// <returns>A stream to be used for writing to the blob.</returns>
        public Stream OpenWrite(AccessCondition accessCondition = null, BlobRequestOptions options = null, OperationContext operationContext = null)
        {
            this.attributes.AssertNoSnapshot();
            BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.BlockBlob, this.ServiceClient);

            if ((accessCondition != null) && accessCondition.IsConditional)
            {
                try
                {
                    this.FetchAttributes(accessCondition, modifiedOptions, operationContext);
                }
                catch (StorageException e)
                {
                    if ((e.RequestInformation != null) &&
                        (e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.NotFound) &&
                        string.IsNullOrEmpty(accessCondition.IfMatchETag))
                    {
                        // If we got a 404 and the condition was not an If-Match,
                        // we should continue with the operation.
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return new BlobWriteStream(this, accessCondition, modifiedOptions, operationContext);
        }
开发者ID:jdkillian,项目名称:azure-sdk-for-net,代码行数:36,代码来源:CloudBlockBlob.cs

示例13: ListBlobsSegmentedAsync

		public static async Task<ReadOnlyCollection<IListBlobItem>> ListBlobsSegmentedAsync(
			this CloudBlobDirectory container,
			bool useFlatBlobListing,
			int pageSize,
			BlobListingDetails details,
			BlobRequestOptions options,
			OperationContext operationContext,
			IProgress<IEnumerable<IListBlobItem>> progress = null,
			CancellationToken cancellationToken = default(CancellationToken)) {
			options = options ?? new BlobRequestOptions();
			var results = new List<IListBlobItem>();
			BlobContinuationToken continuation = null;
			BlobResultSegment segment;
			do {
				segment = await Task.Factory.FromAsync(
					(cb, state) => container.BeginListBlobsSegmented(useFlatBlobListing, details, pageSize, continuation, options, operationContext, cb, state).WithCancellation(cancellationToken),
					ar => container.EndListBlobsSegmented(ar),
					null);
				if (progress != null) {
					progress.Report(segment.Results);
				}
				results.AddRange(segment.Results);
				continuation = segment.ContinuationToken;
			} while (continuation != null);

			return new ReadOnlyCollection<IListBlobItem>(results);
		}
开发者ID:AArnott,项目名称:Microsoft.WindowsAzure.StorageClient.Async,代码行数:27,代码来源:AzureBlobStorageExtensions.cs

示例14: RetryDelayShouldBeCancellableAsync

        public async Task RetryDelayShouldBeCancellableAsync()
        {
            TaskCompletionSource<bool> responseTask = new TaskCompletionSource<bool>();
            BlobRequestOptions options = new BlobRequestOptions();
            options.RetryPolicy = new AlwaysRetry(TimeSpan.FromMinutes(1), 1);
            OperationContext context = new OperationContext();
            context.ResponseReceived += (sender, e) => responseTask.SetResult(true);

            CloudBlobClient blobClient = GenerateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference("test" + DateTime.UtcNow.Ticks.ToString());
            CancellationTokenSource token = new CancellationTokenSource();
            Task task = container.FetchAttributesAsync(null, options, context).AsTask(token.Token);

            await responseTask.Task;
            await Task.Delay(10 * 1000);

            Stopwatch stopwatch = Stopwatch.StartNew();

            try
            {
                token.Cancel();
                await task;
            }
            catch (Exception)
            {
                // This is expected, because we went for an invalid domain name.
            }

            stopwatch.Stop();

            Assert.IsTrue(stopwatch.Elapsed < TimeSpan.FromSeconds(10), stopwatch.Elapsed.ToString());
            Assert.AreEqual(1, context.RequestResults.Count);
        }
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:33,代码来源:RetryPoliciesTests.cs

示例15: SetServiceProperties

 public Task SetServiceProperties(ServiceProperties properties, BlobRequestOptions requestOptions = null, OperationContext operationContext = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return AsyncTaskUtil.RunAsyncCancellable(
         _inner.BeginSetServiceProperties(properties, requestOptions, operationContext, null, null),
         _inner.EndSetServiceProperties,
         cancellationToken);
 }
开发者ID:Porges,项目名称:azure-storage-async,代码行数:7,代码来源:AsyncCloudBlobClient.cs


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