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); }
/// <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 IntegrityFailure(IStreamingItem item, Exception inner = null) { var message = string.Format(CultureInfo.InvariantCulture, "Local hash differs from metadata. Item was probably corrupted in trasfer, please retry: '{0}'.", item.FullPath); return new StreamingItemIntegrityException(message, inner); }
public static Exception ContainerNotFound(IStreamingItem item, Exception inner = null) { var message = string.Format(CultureInfo.InvariantCulture, "Storage container was not found for: '{0}'.", item.FullPath); return(new StreamingContainerNotFoundException(message, inner)); }
/// <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 IntegrityFailure(IStreamingItem item, Exception inner = null) { var message = string.Format(CultureInfo.InvariantCulture, "Local hash differs from metadata. Item was probably corrupted in trasfer, please retry: '{0}'.", item.FullPath); return(new StreamingItemIntegrityException(message, inner)); }
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)); }
public static void WriteText(this IStreamingItem item, string text, Encoding encoding) { item.Write(s => { using (var writer = new StreamWriter(s, encoding)) { writer.Write(text); } }); }
public static string ReadText(this IStreamingItem item) { string result = null; item.ReadInto((props, stream) => { using (var reader = new StreamReader(stream)) { result = reader.ReadToEnd(); } }); return(result); }
/// <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); }
protected void ShouldHaveBytes(IStreamingItem streamingItem, byte[] bytes, StreamingCondition condition = default(StreamingCondition)) { StreamingItemInfo streamingItemInfo = null; byte[] actualBytes = null; using (var ms = new MemoryStream()) { streamingItem.ReadInto((properties, stream) => { stream.CopyTo(ms); actualBytes = ms.ToArray(); streamingItemInfo = properties; }, condition); } Assert.AreEqual(bytes, actualBytes); Assert.That(streamingItemInfo.ETag, Is.Not.Empty); }
/// <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); } }
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); } }
protected void ShouldHaveGuid(IStreamingItem streamingItem, Guid g, StreamingCondition condition = default(StreamingCondition)) { var set = false; Guid actual = Guid.Empty; StreamingItemInfo streamingItemInfo = null; streamingItem.ReadInto((properties, stream) => { var b = new byte[16]; stream.Read(b, 0, 16); actual = new Guid(b); set = true; streamingItemInfo = properties; }, condition); Assert.AreEqual(g, actual); Assert.That(streamingItemInfo.ETag, Is.Not.Empty); set = true; Assert.IsTrue(set); }
internal bool Contains(IStreamingItem item) { return(GetRealContainer()._items.ContainsKey(item.FullPath)); }
protected void Write(IStreamingItem streamingItem, byte[] bytes, StreamingCondition condition = default(StreamingCondition)) { streamingItem.Write(stream => stream.Write(bytes, 0, bytes.Length), condition, WriteOptions); }
protected void TryToRead(IStreamingItem item, StreamingCondition condition = default(StreamingCondition)) { item.ReadInto((props, stream) => stream.Read(new byte[1], 0, 1), condition); }
public static Exception ItemNotFound(IStreamingItem item, Exception inner = null) { var message = string.Format(CultureInfo.InvariantCulture, "Storage item was not found: '{0}'.", item.FullPath); return new StreamingItemNotFoundException(message, inner); }
internal bool Contains(IStreamingItem item) { return GetRealContainer()._items.ContainsKey(item.FullPath); }
protected void Write(IStreamingItem streamingItem, Guid g, StreamingCondition condition = default(StreamingCondition)) { streamingItem.Write(stream => stream.Write(g.ToByteArray(), 0, 16), condition, WriteOptions); }