Пример #1
0
        public async Task <string> GetETagAsync(IStorageBlob blob, CancellationToken cancellationToken)
        {
            try
            {
                await blob.FetchAttributesAsync(cancellationToken);
            }
            catch (StorageException exception)
            {
                // Note that specific exception codes are not available for FetchAttributes, which makes a HEAD request.

                if (exception.IsNotFound())
                {
                    // Blob does not exist.
                    return(null);
                }
                else if (exception.IsOk())
                {
                    // If the blob type is incorrect (block vs. page) a 200 OK is returned but the SDK throws an
                    // exception.
                    return(null);
                }
                else
                {
                    throw;
                }
            }

            return(blob.Properties.ETag);
        }
        public static async Task <bool> TryFetchAttributesAsync(this IStorageBlob blob,
                                                                CancellationToken cancellationToken)
        {
            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }

            try
            {
                await blob.FetchAttributesAsync(cancellationToken);

                return(true);
            }
            catch (StorageException exception)
            {
                // Remember specific error codes are not available for Fetch (HEAD request).

                if (exception.IsNotFound())
                {
                    return(false);
                }
                else if (exception.IsOk())
                {
                    // If the blob type is incorrect (block vs. page) a 200 OK is returned but the SDK throws an
                    // exception.
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
Пример #3
0
        public async Task<string> GetETagAsync(IStorageBlob blob, CancellationToken cancellationToken)
        {
            try
            {
                await blob.FetchAttributesAsync(cancellationToken);
            }
            catch (StorageException exception)
            {
                // Note that specific exception codes are not available for FetchAttributes, which makes a HEAD request.

                if (exception.IsNotFound())
                {
                    // Blob does not exist.
                    return null;
                }
                else if (exception.IsOk())
                {
                    // If the blob type is incorrect (block vs. page) a 200 OK is returned but the SDK throws an
                    // exception.
                    return null;
                }
                else
                {
                    throw;
                }
            }

            return blob.Properties.ETag;
        }