예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        /// <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);
            }
        }
예제 #6
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);
            }
        }
예제 #7
0
        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);
        }
예제 #8
0
        /// <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);
            }
        }
예제 #9
0
 protected void TryToRead(IStreamingItem item, StreamingCondition condition = default(StreamingCondition))
 {
     item.ReadInto((props, stream) => stream.Read(new byte[1], 0, 1), condition);
 }