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


C# AccessCondition類代碼示例

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


AccessCondition類屬於命名空間,在下文中一共展示了AccessCondition類的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: 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


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