Example #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;
                }
            }
        }
 void ThrowIfConditionFailed(StreamingCondition condition)
 {
     if (!Satisfy(condition))
     {
         throw StreamingErrors.ConditionFailed(this, condition);
     }
 }
 void ThrowIfContainerNotFound()
 {
     if (!_file.Directory.Exists)
     {
         throw StreamingErrors.ContainerNotFound(this);
     }
 }
 void ThrowIfItemNotFound()
 {
     if (!_file.Exists)
     {
         throw StreamingErrors.ItemNotFound(this);
     }
 }
Example #5
0
 public IEnumerable <string> ListItems()
 {
     try
     {
         return(_root.GetFiles().Select(f => f.Name).ToArray());
     }
     catch (DirectoryNotFoundException e)
     {
         throw StreamingErrors.ContainerNotFound(this, e);
     }
 }
Example #6
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;
                }
            }
        }
Example #7
0
        public IEnumerable <string> ListItems()
        {
            try
            {
                return(_directory.ListBlobs()
                       .Select(item => _directory.Uri.MakeRelativeUri(item.Uri).ToString())
                       .ToArray());
            }
            catch (StorageClientException e)
            {
                switch (e.ErrorCode)
                {
                case StorageErrorCode.ContainerNotFound:
                    throw StreamingErrors.ContainerNotFound(this, e);

                default:
                    throw;
                }
            }
        }
Example #8
0
        /// <summary>
        /// Removes the item, ensuring that the specified condition is met.
        /// </summary>
        /// <param name="condition">The condition.</param>
        public void Delete(StreamingCondition condition)
        {
            try
            {
                var options = Map(condition);
                _blob.Delete(options);
            }
            catch (StorageClientException ex)
            {
                switch (ex.ErrorCode)
                {
                case StorageErrorCode.ContainerNotFound:
                    throw StreamingErrors.ContainerNotFound(this, ex);

                case StorageErrorCode.BlobNotFound:
                case StorageErrorCode.ConditionFailed:
                    return;

                default:
                    throw;
                }
            }
        }
Example #9
0
        public void CopyFrom(IStreamingItem sourceItem,
                             StreamingCondition condition,
                             StreamingCondition copySourceCondition,
                             StreamingWriteOptions writeOptions)
        {
            var item = sourceItem as BlobStreamingItem;

            if (item != null)
            {
                try
                {
                    _blob.CopyFromBlob(item._blob, Map(condition, copySourceCondition));
                }
                catch (StorageClientException e)
                {
                    switch (e.ErrorCode)
                    {
                    case StorageErrorCode.BlobNotFound:
                        throw StreamingErrors.ItemNotFound(this, e);

                    default:
                        throw;
                    }
                }
            }
            else
            {
                // based on the default write block size of BLOB
                const int bufferSize = 0x400000;
                Write(
                    targetStream =>
                    sourceItem.ReadInto(
                        (props, stream) => stream.CopyTo(targetStream, bufferSize),
                        copySourceCondition), condition,
                    writeOptions);
            }
        }