/// <summary> /// Creates this storage item from another. /// </summary> /// <param name="sourceItem">The target.</param> /// <param name="condition">The condition.</param> /// <param name="copySourceCondition">The copy source condition.</param> /// <param name="options">The options.</param> /// <exception cref="StreamingItemNotFoundException">when source storage is not found</exception> /// <exception cref="StreamingItemIntegrityException">when integrity check fails</exception> public void CopyFrom(IStreamingItem sourceItem, StreamingCondition condition, StreamingCondition copySourceCondition, StreamingWriteOptions options) { var item = sourceItem as FileStreamingItem; if (item != null) { Refresh(); ThrowIfContainerNotFound(); ThrowIfConditionFailed(condition); item.Refresh(); item.ThrowIfContainerNotFound(); item.ThrowIfItemNotFound(); item.ThrowIfConditionFailed(copySourceCondition); item._file.CopyTo(_file.FullName, true); } else { const int bufferSize = 64 * 1024; Write( targetStream => sourceItem.ReadInto((props, stream) => stream.CopyTo(targetStream, bufferSize), copySourceCondition), condition, options); } }
void ThrowIfConditionFailed(StreamingCondition condition) { if (!Satisfy(condition)) { throw StreamingErrors.ConditionFailed(this, condition); } }
/// <summary> /// Creates this storage item from another. /// </summary> /// <param name="sourceItem">The target.</param> /// <param name="condition">The condition.</param> /// <param name="copySourceCondition">The copy source condition.</param> /// <param name="options">The options.</param> /// <exception cref="StreamingItemNotFoundException">when source storage is not found</exception> /// <exception cref="StreamingItemIntegrityException">when integrity check fails</exception> public void CopyFrom(IStreamingItem sourceItem, StreamingCondition condition, StreamingCondition copySourceCondition, StreamingWriteOptions options) { var item = sourceItem as FileStreamingItem; if (item != null) { Refresh(); ThrowIfContainerNotFound(); ThrowIfConditionFailed(condition); item.Refresh(); item.ThrowIfContainerNotFound(); item.ThrowIfItemNotFound(); item.ThrowIfConditionFailed(copySourceCondition); item._file.CopyTo(_file.FullName, true); } else { const int bufferSize = 64*1024; Write( targetStream => sourceItem.ReadInto((props, stream) => stream.CopyTo(targetStream, bufferSize), copySourceCondition), condition, options); } }
public static Exception ConditionFailed(IStreamingItem item, StreamingCondition condition, Exception inner = null) { var message = string.Format(CultureInfo.InvariantCulture, "Storage condition '{0}' failed for '{1}'", condition, item.FullPath); return(new StreamingConditionFailedException(message, inner)); }
bool Satisfy(StreamingCondition condition) { return (GetUnconditionalInfo().Convert( s => new LocalStreamingInfo(s.ETag)).Convert( s => condition.Satisfy(new[] { s }), () => condition.Satisfy(new LocalStreamingInfo[0]))); }
bool Satisfy(StreamingCondition condition) { var info = GetUnconditionalInfo(); return(info .Convert(s => new LocalStreamingInfo(s.ETag)) .Convert(s => condition.Satisfy(s), () => condition.Satisfy())); }
/// <summary> /// Gets the info about this item. It returns empty result if the item does not exist or does not match the condition /// </summary> /// <param name="condition">The condition.</param> /// <returns></returns> public Optional <StreamingItemInfo> GetInfo(StreamingCondition condition = new StreamingCondition()) { if (_parent.Contains(this) && Satisfy(condition)) { return(GetUnconditionalInfo()); } return(Optional <StreamingItemInfo> .Empty); }
/// <summary> /// Removes the item, ensuring that the specified condition is met. /// </summary> /// <param name="condition">The condition.</param> public void Delete(StreamingCondition condition = new StreamingCondition()) { ThrowIfContainerNotFound(); if (!_parent.Contains(this) || !Satisfy(condition)) { return; } _parent.Remove(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 = new StreamingCondition()) { ThrowIfContainerNotFound(); ThrowIfItemNotFound(); ThrowIfConditionFailed(condition); var props = GetUnconditionalInfo().Value; using (var stream = new MemoryStream(_content)) reader(props, stream); }
/// <summary> /// Gets the info about this item. It returns empty result if the item does not exist or does not match the condition /// </summary> /// <param name="condition">The condition.</param> /// <returns></returns> public Optional <StreamingItemInfo> GetInfo(StreamingCondition condition) { Refresh(); //ThrowIfContainerNotFound(); if (_file.Exists && Satisfy(condition)) { return(GetUnconditionalInfo()); } return(Optional <StreamingItemInfo> .Empty); }
/// <summary> /// Removes the item, ensuring that the specified condition is met. /// </summary> /// <param name="condition">The condition.</param> public void Delete(StreamingCondition condition) { Refresh(); ThrowIfContainerNotFound(); if (_file.Exists && Satisfy(condition)) { _file.Delete(); } }
/// <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="options">The options.</param> /// <returns>number of bytes written</returns> /// <exception cref="StreamingItemIntegrityException">when integrity check fails during the upload</exception> public long Write(Action <Stream> writer, StreamingCondition condition = new StreamingCondition(), StreamingWriteOptions options = StreamingWriteOptions.None) { ThrowIfContainerNotFound(); ThrowIfConditionFailed(condition); _parent.Add(this); using (var stream = new MemoryStream()) { writer(stream); _content = stream.ToArray(); } return(_content.Length); }
/// <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) { Refresh(); ThrowIfContainerNotFound(); ThrowIfItemNotFound(); ThrowIfConditionFailed(condition); var props = GetUnconditionalInfo().Value; using (var read = OpenForRead()) { reader(props, read); } }
/// <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="options">The options.</param> /// <returns>number of bytes written</returns> /// <exception cref="StreamingItemIntegrityException">when integrity check fails during the upload</exception> public long Write(Action <Stream> writer, StreamingCondition condition, StreamingWriteOptions options) { Refresh(); ThrowIfContainerNotFound(); ThrowIfConditionFailed(condition); using (var file = OpenForWrite()) { writer(file); // stream will probably be closed here. } Refresh(); return(_file.Length); }
/// <summary> /// Creates this storage item from another. /// </summary> /// <param name="sourceItem">The target.</param> /// <param name="condition">The condition.</param> /// <param name="copySourceCondition">The copy source condition.</param> /// <param name="options">The options.</param> /// <exception cref="StreamingItemNotFoundException">when source storage is not found</exception> /// <exception cref="StreamingItemIntegrityException">when integrity check fails</exception> public void CopyFrom(IStreamingItem sourceItem, StreamingCondition condition = new StreamingCondition(), StreamingCondition copySourceCondition = new StreamingCondition(), StreamingWriteOptions options = StreamingWriteOptions.None) { var source = sourceItem as MemoryStreamingItem; if (source != null) { ThrowIfContainerNotFound(); ThrowIfConditionFailed(condition); source.ThrowIfContainerNotFound(); source.ThrowIfItemNotFound(); source.ThrowIfConditionFailed(copySourceCondition); _content = source._content; _parent.Add(this); } else Write(targetStream => sourceItem.ReadInto((props, stream) => stream.CopyTo(targetStream, 65536), copySourceCondition), condition, options); }
/// <summary> /// Creates this storage item from another. /// </summary> /// <param name="sourceItem">The target.</param> /// <param name="condition">The condition.</param> /// <param name="copySourceCondition">The copy source condition.</param> /// <param name="options">The options.</param> /// <exception cref="StreamingItemNotFoundException">when source storage is not found</exception> /// <exception cref="StreamingItemIntegrityException">when integrity check fails</exception> public void CopyFrom(IStreamingItem sourceItem, StreamingCondition condition = new StreamingCondition(), StreamingCondition copySourceCondition = new StreamingCondition(), StreamingWriteOptions options = StreamingWriteOptions.None) { var source = sourceItem as MemoryStreamingItem; if (source != null) { ThrowIfContainerNotFound(); ThrowIfConditionFailed(condition); source.ThrowIfContainerNotFound(); source.ThrowIfItemNotFound(); source.ThrowIfConditionFailed(copySourceCondition); _content = source._content; _parent.Add(this); } else { Write(targetStream => sourceItem.ReadInto((props, stream) => stream.CopyTo(targetStream, 65536), copySourceCondition), condition, options); } }
void ThrowIfConditionFailed(StreamingCondition condition) { if (!Satisfy(condition)) throw StreamingErrors.ConditionFailed(this, condition); }
bool Satisfy(StreamingCondition condition) { return GetUnconditionalInfo().Convert( s => new LocalStreamingInfo(s.ETag)).Convert( s => condition.Satisfy(new[] { s }), () => condition.Satisfy(new LocalStreamingInfo[0])); }
/// <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="options">The options.</param> /// <returns>number of bytes written</returns> /// <exception cref="StreamingItemIntegrityException">when integrity check fails during the upload</exception> public long Write(Action<Stream> writer, StreamingCondition condition, StreamingWriteOptions options) { Refresh(); ThrowIfContainerNotFound(); ThrowIfConditionFailed(condition); using (var file = OpenForWrite()) { writer(file); // stream will probably be closed here. } Refresh(); return _file.Length; }
bool Satisfy(StreamingCondition condition) { var info = GetUnconditionalInfo(); return info .Convert(s => new LocalStreamingInfo(s.ETag)) .Convert(s => condition.Satisfy(s), () => condition.Satisfy()); }
/// <summary> /// Gets the info about this item. It returns empty result if the item does not exist or does not match the condition /// </summary> /// <param name="condition">The condition.</param> /// <returns></returns> public Optional<StreamingItemInfo> GetInfo(StreamingCondition condition) { Refresh(); //ThrowIfContainerNotFound(); if (_file.Exists && Satisfy(condition)) return GetUnconditionalInfo(); return Optional<StreamingItemInfo>.Empty; }
/// <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) { Refresh(); ThrowIfContainerNotFound(); ThrowIfItemNotFound(); ThrowIfConditionFailed(condition); var props = GetUnconditionalInfo().Value; using (var read = OpenForRead()) { reader(props, read); } }
/// <summary> /// Removes the item, ensuring that the specified condition is met. /// </summary> /// <param name="condition">The condition.</param> public void Delete(StreamingCondition condition) { Refresh(); ThrowIfContainerNotFound(); if (_file.Exists && Satisfy(condition)) _file.Delete(); }
/// <summary> /// Removes the item, ensuring that the specified condition is met. /// </summary> /// <param name="condition">The condition.</param> public void Delete(StreamingCondition condition = new StreamingCondition()) { ThrowIfContainerNotFound(); if (!_parent.Contains(this) || !Satisfy(condition)) return; _parent.Remove(this); }
/// <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="options">The options.</param> /// <returns>number of bytes written</returns> /// <exception cref="StreamingItemIntegrityException">when integrity check fails during the upload</exception> public long Write(Action<Stream> writer, StreamingCondition condition = new StreamingCondition(), StreamingWriteOptions options = StreamingWriteOptions.None) { ThrowIfContainerNotFound(); ThrowIfConditionFailed(condition); _parent.Add(this); using (var stream = new MemoryStream()) { writer(stream); _content = stream.ToArray(); } return _content.Length; }
/// <summary> /// Gets the info about this item. It returns empty result if the item does not exist or does not match the condition /// </summary> /// <param name="condition">The condition.</param> /// <returns></returns> public Optional<StreamingItemInfo> GetInfo(StreamingCondition condition = new StreamingCondition()) { if (_parent.Contains(this) && Satisfy(condition)) return GetUnconditionalInfo(); return Optional<StreamingItemInfo>.Empty; }
/// <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 = new StreamingCondition()) { ThrowIfContainerNotFound(); ThrowIfItemNotFound(); ThrowIfConditionFailed(condition); var props = GetUnconditionalInfo().Value; using (var stream = new MemoryStream(_content)) reader(props, stream); }