void ThrowIfItemNotFound() { if (!_file.Exists) { throw StreamingErrors.ItemNotFound(this); } }
/// <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; } } }
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); } }