Ejemplo n.º 1
0
        //const string ContentCompression = "gzip";

        /// <summary>
        /// Performs the write operation, ensuring that the condition is met.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="condition">The condition.</param>
        /// <param name="writeOptions">The write options.</param>
        public long Write(Action <Stream> writer, StreamingCondition condition, StreamingWriteOptions writeOptions)
        {
            try
            {
                var mapped = Map(condition);

                return(BlobStorageUtil.Write(mapped, _blob, writer, writeOptions));
            }
            catch (StorageServerException ex)
            {
                switch (ex.ErrorCode)
                {
                case StorageErrorCode.ServiceIntegrityCheckFailed:
                    throw StreamingErrors.IntegrityFailure(this, ex);

                default:
                    throw;
                }
            }
            catch (StorageClientException ex)
            {
                switch (ex.ErrorCode)
                {
                case StorageErrorCode.ConditionFailed:
                    throw StreamingErrors.ConditionFailed(this, condition, ex);

                case StorageErrorCode.ContainerNotFound:
                    throw StreamingErrors.ContainerNotFound(this, ex);

                default:
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public Optional <StreamingItemInfo> GetInfo(StreamingCondition condition)
        {
            try
            {
                _blob.FetchAttributes(Map(condition));
                return(BlobStorageUtil.MapFetchedAttrbitues(_blob));
            }
            catch (StorageClientException e)
            {
                switch (e.ErrorCode)
                {
                case StorageErrorCode.ContainerNotFound:
                case StorageErrorCode.ResourceNotFound:
                case StorageErrorCode.BlobNotFound:
                case StorageErrorCode.ConditionFailed:
                    return(Optional <StreamingItemInfo> .Empty);

                case StorageErrorCode.BadRequest:
                    switch (e.StatusCode)
                    {
                    case HttpStatusCode.PreconditionFailed:
                        return(Optional <StreamingItemInfo> .Empty);

                    default:
                        throw;
                    }
                }
                throw;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempts to read the storage item.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="condition">The condition.</param>
        /// <exception cref="StreamingItemNotFoundException">if the item does not exist.</exception>
        /// <exception cref="StreamingContainerNotFoundException">if the container for the item does not exist</exception>
        /// <exception cref="StreamingItemIntegrityException">when integrity check fails</exception>
        public void ReadInto(ReaderDelegate reader, StreamingCondition condition)
        {
            try
            {
                var mapped = Map(condition);
                BlobStorageUtil.Read(mapped, _blob, reader);
            }
            catch (StreamingItemIntegrityException e)
            {
                throw StreamingErrors.IntegrityFailure(this, e);
            }
            catch (StorageClientException e)
            {
                switch (e.ErrorCode)
                {
                case StorageErrorCode.ContainerNotFound:
                    throw StreamingErrors.ContainerNotFound(this, e);

                case StorageErrorCode.ResourceNotFound:
                case StorageErrorCode.BlobNotFound:
                    throw StreamingErrors.ItemNotFound(this, e);

                case StorageErrorCode.ConditionFailed:
                    throw StreamingErrors.ConditionFailed(this, condition, e);

                case StorageErrorCode.ServiceIntegrityCheckFailed:
                    throw StreamingErrors.IntegrityFailure(this, e);

                case StorageErrorCode.BadRequest:
                    switch (e.StatusCode)
                    {
                    // for some reason Azure Storage happens to get here as well
                    case HttpStatusCode.PreconditionFailed:
                    case HttpStatusCode.NotModified:
                        throw StreamingErrors.ConditionFailed(this, condition, e);

                    default:
                        throw;
                    }

                default:
                    throw;
                }
            }
        }