本文整理汇总了C#中AccessCondition类的典型用法代码示例。如果您正苦于以下问题:C# AccessCondition类的具体用法?C# AccessCondition怎么用?C# AccessCondition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessCondition类属于命名空间,在下文中一共展示了AccessCondition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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
示例3: ApplyAccessCondition
/// <summary>
/// Applies the condition to the web request.
/// </summary>
/// <param name="request">The request to be modified.</param>
/// <param name="accessCondition">Access condition to be added to the request.</param>
internal static void ApplyAccessCondition(this HttpRequestMessage request, AccessCondition accessCondition)
{
if (accessCondition != null)
{
if (!string.IsNullOrEmpty(accessCondition.IfMatchETag))
{
request.Headers.IfMatch.Add(EntityTagHeaderValue.Parse(accessCondition.IfMatchETag));
}
if (!string.IsNullOrEmpty(accessCondition.IfNoneMatchETag))
{
if (accessCondition.IfNoneMatchETag.Equals(EntityTagHeaderValue.Any.ToString(), StringComparison.OrdinalIgnoreCase))
{
request.Headers.IfNoneMatch.Add(EntityTagHeaderValue.Any);
}
else
{
request.Headers.IfNoneMatch.Add(EntityTagHeaderValue.Parse(accessCondition.IfNoneMatchETag));
}
}
request.Headers.IfModifiedSince = accessCondition.IfModifiedSinceTime;
request.Headers.IfUnmodifiedSince = accessCondition.IfNotModifiedSinceTime;
if (!string.IsNullOrEmpty(accessCondition.LeaseId))
{
request.Headers.Add(Constants.HeaderConstants.LeaseIdHeader, accessCondition.LeaseId);
}
}
}
开发者ID:jdkillian,项目名称:azure-sdk-for-net,代码行数:35,代码来源:RequestMessageExtensions.cs
示例4: GetFileRequest
public static HttpWebRequest GetFileRequest(FileContext context, string shareName, string fileName, AccessCondition accessCondition)
{
bool valid = FileTests.ShareNameValidator(shareName) &&
FileTests.FileNameValidator(fileName);
Uri uri = FileTests.ConstructGetUri(context.Address, shareName, fileName);
HttpWebRequest request = null;
OperationContext opContext = new OperationContext();
try
{
request = FileHttpWebRequestFactory.Get(uri, context.Timeout, accessCondition, true, opContext);
}
catch (InvalidOperationException)
{
if (valid)
{
Assert.Fail();
}
}
if (valid)
{
Assert.IsNotNull(request);
Assert.IsNotNull(request.Method);
Assert.AreEqual("GET", request.Method);
FileTestUtils.RangeHeader(request, null);
}
return request;
}
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:27,代码来源:FileTests.cs
示例5: 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
示例6: Put
/// <summary>
/// Constructs a web request to create a new block blob or page blob, or to update the content
/// of an existing block blob.
/// </summary>
/// <param name="uri">The absolute URI to the blob.</param>
/// <param name="timeout">The server timeout interval.</param>
/// <param name="properties">The properties to set for the blob.</param>
/// <param name="blobType">The type of the blob.</param>
/// <param name="pageBlobSize">For a page blob, the size of the blob. This parameter is ignored
/// for block blobs.</param>
/// <param name="accessCondition">The access condition to apply to the request.</param>
/// <returns>A web request to use to perform the operation.</returns>
public static HttpRequestMessage Put(Uri uri, int? timeout, BlobProperties properties, BlobType blobType, long pageBlobSize, AccessCondition accessCondition, HttpContent content, OperationContext operationContext)
{
if (blobType == BlobType.Unspecified)
{
throw new InvalidOperationException(SR.UndefinedBlobType);
}
HttpRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Put, uri, timeout, null /* builder */, content, operationContext);
if (properties.CacheControl != null)
{
request.Headers.CacheControl = CacheControlHeaderValue.Parse(properties.CacheControl);
}
if (content != null)
{
if (properties.ContentType != null)
{
content.Headers.ContentType = MediaTypeHeaderValue.Parse(properties.ContentType);
}
if (properties.ContentMD5 != null)
{
content.Headers.ContentMD5 = Convert.FromBase64String(properties.ContentMD5);
}
if (properties.ContentLanguage != null)
{
content.Headers.ContentLanguage.Add(properties.ContentLanguage);
}
if (properties.ContentEncoding != null)
{
content.Headers.ContentEncoding.Add(properties.ContentEncoding);
}
if (properties.ContentDisposition != null)
{
content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse(properties.ContentDisposition);
}
}
if (blobType == BlobType.PageBlob)
{
request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.PageBlob);
request.Headers.Add(Constants.HeaderConstants.BlobContentLengthHeader, pageBlobSize.ToString(NumberFormatInfo.InvariantInfo));
properties.Length = pageBlobSize;
}
else if (blobType == BlobType.BlockBlob)
{
request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.BlockBlob);
}
else
{
request.Headers.Add(Constants.HeaderConstants.BlobType, Constants.HeaderConstants.AppendBlob);
}
request.ApplyAccessCondition(accessCondition);
return request;
}
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:72,代码来源:BlobHttpRequestMessageFactory.cs
示例7: OpenRead
public Stream OpenRead(AccessCondition accessCondition = null, BlobRequestOptions options = null, OperationContext operationContext = null)
{
this.FetchAttributes(accessCondition, options, operationContext);
AccessCondition streamAccessCondition = AccessCondition.CloneConditionWithETag(accessCondition, this.Properties.ETag);
BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, this.BlobType, this.ServiceClient, false);
return new BlobReadStream(this, streamAccessCondition, modifiedOptions, operationContext);
}
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:7,代码来源:CloudBlockBlob.cs
示例8: 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
示例9: 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
示例10: DownloadText
public static string DownloadText(ICloudBlob blob, Encoding encoding, AccessCondition accessCondition = null, BlobRequestOptions options = null, OperationContext operationContext = null)
{
using (MemoryStream stream = new MemoryStream())
{
blob.DownloadToStream(stream, accessCondition, options, operationContext);
return encoding.GetString(stream.ToArray());
}
}
开发者ID:Juliako,项目名称:azure-sdk-for-net,代码行数:8,代码来源:BlobTestBase35.cs
示例11: BlobWriteStreamBase
/// <summary>
/// Initializes a new instance of the BlobWriteStreamBase class for a block blob.
/// </summary>
/// <param name="blockBlob">Blob reference to write to.</param>
/// <param name="accessCondition">An object that represents the access conditions for the blob. If null, no condition is used.</param>
/// <param name="options">An object that specifies any additional options for the request.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object for tracking the current operation.</param>
protected BlobWriteStreamBase(CloudBlockBlob blockBlob, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
: this(blockBlob.ServiceClient, accessCondition, options, operationContext)
{
this.blockBlob = blockBlob;
this.blockList = new List<string>();
this.blockIdPrefix = new Random().Next().ToString("X8") + "-";
this.buffer = new MemoryStream(this.Blob.StreamWriteSizeInBytes);
}
开发者ID:jdkillian,项目名称:azure-sdk-for-net,代码行数:15,代码来源:BlobWriteStreamBase.cs
示例12: DownloadTextAsync
public static async Task<string> DownloadTextAsync(CloudFile file, Encoding encoding, AccessCondition accessCondition = null, FileRequestOptions options = null, OperationContext operationContext = null)
{
using (MemoryStream stream = new MemoryStream())
{
await file.DownloadToStreamAsync(stream, accessCondition, options, operationContext);
return encoding.GetString(stream.ToArray(), 0, (int)stream.Length);
}
}
开发者ID:tamram,项目名称:azure-storage-net,代码行数:8,代码来源:FileTestBase.cs
示例13: OpenRead
public virtual Stream OpenRead(AccessCondition accessCondition = null, FileRequestOptions options = null, OperationContext operationContext = null)
{
operationContext = operationContext ?? new OperationContext();
this.FetchAttributes(accessCondition, options, operationContext);
AccessCondition streamAccessCondition = AccessCondition.CloneConditionWithETag(accessCondition, this.Properties.ETag);
FileRequestOptions modifiedOptions = FileRequestOptions.ApplyDefaults(options, this.ServiceClient, false);
return new FileReadStream(this, streamAccessCondition, modifiedOptions, operationContext);
}
开发者ID:Gajendra-Bahakar,项目名称:azure-storage-net,代码行数:8,代码来源:CloudFile.cs
示例14: DownloadTextAsync
public static async Task<string> DownloadTextAsync(ICloudBlob blob, Encoding encoding, AccessCondition accessCondition = null, BlobRequestOptions options = null, OperationContext operationContext = null)
{
using (MemoryStream stream = new MemoryStream())
{
await blob.DownloadToStreamAsync(stream.AsOutputStream(), accessCondition, options, operationContext);
byte[] buffer = stream.ToArray();
return encoding.GetString(buffer, 0, buffer.Length);
}
}
开发者ID:Juliako,项目名称:azure-sdk-for-net,代码行数:9,代码来源:BlobTestBaseRT.cs
示例15: BeginOpenWrite
/// <summary>
/// Begins an asynchronous operation to open 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>
/// <param name="callback">The callback delegate that will receive notification when the asynchronous operation completes.</param>
/// <param name="state">A user-defined object that will be passed to the callback delegate.</param>
/// <returns>An <see cref="ICancellableAsyncResult"/> that references the asynchronous operation.</returns>
public ICancellableAsyncResult BeginOpenWrite(AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, AsyncCallback callback, object state)
{
ChainedAsyncResult<Stream> chainedResult = new ChainedAsyncResult<Stream>(callback, state)
{
Result = this.OpenWrite(accessCondition, options, operationContext),
};
chainedResult.OnComplete();
return chainedResult;
}
开发者ID:Juliako,项目名称:azure-sdk-for-net,代码行数:18,代码来源:CloudBlockBlob.cs
示例16: OpenReadAsync
public virtual Task<Stream> OpenReadAsync(AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
{
return Task.Run<Stream>(async () =>
{
await this.FetchAttributesAsync(accessCondition, options, operationContext, cancellationToken);
AccessCondition streamAccessCondition = AccessCondition.CloneConditionWithETag(accessCondition, this.Properties.ETag);
BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, this.BlobType, this.ServiceClient, false);
return new BlobReadStream(this, streamAccessCondition, modifiedOptions, operationContext);
}, cancellationToken);
}
开发者ID:tamram,项目名称:azure-storage-net,代码行数:10,代码来源:CloudBlob.cs
示例17: OpenReadAsync
public IAsyncOperation<IRandomAccessStreamWithContentType> OpenReadAsync(AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
{
return AsyncInfo.Run<IRandomAccessStreamWithContentType>(async (token) =>
{
await this.FetchAttributesAsync(accessCondition, options, operationContext).AsTask(token);
AccessCondition streamAccessCondition = AccessCondition.CloneConditionWithETag(accessCondition, this.Properties.ETag);
BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, this.BlobType, this.ServiceClient, false);
return new BlobReadStreamHelper(this, streamAccessCondition, modifiedOptions, operationContext);
});
}
开发者ID:huoxudong125,项目名称:azure-sdk-for-net,代码行数:10,代码来源:CloudBlockBlob.cs
示例18: AppendBlock
/// <summary>
/// Constructs a web request to commit a block to an append blob.
/// </summary>
/// <param name="uri">A <see cref="System.Uri"/> specifying the absolute URI to the blob.</param>
/// <param name="timeout">An integer specifying the server timeout interval.</param>
/// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the condition that must be met in order for the request to proceed.</param>
/// <param name="content"> The HTTP entity body and content headers.</param>
/// <param name="operationContext">An <see cref="OperationContext"/> object that represents the context for the current operation.</param>
/// <returns>A <see cref="System.Net.HttpWebRequest"/> object.</returns>
public static HttpRequestMessage AppendBlock(Uri uri, int? timeout, AccessCondition accessCondition, HttpContent content, OperationContext operationContext)
{
UriQueryBuilder builder = new UriQueryBuilder();
builder.Add(Constants.QueryConstants.Component, "appendblock");
HttpRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Put, uri, timeout, builder, content, operationContext);
request.ApplyAccessCondition(accessCondition);
request.ApplyAppendCondition(accessCondition);
return request;
}
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:19,代码来源:BlobHttpRequestMessageFactory.cs
示例19: OpenWrite
public CloudBlobStream OpenWrite(long? size, AccessCondition accessCondition = null, BlobRequestOptions options = null, OperationContext operationContext = null)
{
this.attributes.AssertNoSnapshot();
BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, this.BlobType, this.ServiceClient, false);
bool createNew = size.HasValue;
#if !(WINDOWS_RT || ASPNET_K || PORTABLE)
ICryptoTransform transform = null;
modifiedOptions.AssertPolicyIfRequired();
if (modifiedOptions.EncryptionPolicy != null)
{
transform = modifiedOptions.EncryptionPolicy.CreateAndSetEncryptionContext(this.Metadata, true /* noPadding */);
}
#endif
if (createNew)
{
this.Create(size.Value, accessCondition, options, operationContext);
}
else
{
if (modifiedOptions.StoreBlobContentMD5.Value)
{
throw new ArgumentException(SR.MD5NotPossible);
}
#if !(WINDOWS_RT || ASPNET_K || PORTABLE)
if (modifiedOptions.EncryptionPolicy != null)
{
throw new ArgumentException(SR.EncryptionNotSupportedForExistingBlobs);
}
#endif
this.FetchAttributes(accessCondition, options, operationContext);
size = this.Properties.Length;
}
if (accessCondition != null)
{
accessCondition = AccessCondition.GenerateLeaseCondition(accessCondition.LeaseId);
}
#if !(WINDOWS_RT || ASPNET_K || PORTABLE)
if (modifiedOptions.EncryptionPolicy != null)
{
return new BlobEncryptedWriteStream(this, size.Value, createNew, accessCondition, modifiedOptions, operationContext, transform);
}
else
#endif
{
return new BlobWriteStream(this, size.Value, createNew, accessCondition, modifiedOptions, operationContext);
}
}
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:54,代码来源:CloudPageBlob.cs
示例20: UploadTextAsync
public static async Task UploadTextAsync(CloudFile file, string text, Encoding encoding, AccessCondition accessCondition = null, FileRequestOptions options = null, OperationContext operationContext = null)
{
byte[] textAsBytes = encoding.GetBytes(text);
using (MemoryStream stream = new MemoryStream())
{
stream.Write(textAsBytes, 0, textAsBytes.Length);
stream.Seek(0, SeekOrigin.Begin);
file.ServiceClient.DefaultRequestOptions.ParallelOperationThreadCount = 2;
await file.UploadFromStreamAsync(stream, accessCondition, options, operationContext);
}
}
开发者ID:tamram,项目名称:azure-storage-net,代码行数:11,代码来源:FileTestBase.cs
注:本文中的AccessCondition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论