本文整理汇总了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;
}
示例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;
}
}
示例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.");
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
}
}
示例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);
}
示例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);
}
示例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));
}
示例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();
});
}
示例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);
}
示例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);
}
示例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);
}