示例#1
0
        private void InitializeLocation()
        {
            RESTCommand <T> cmd = this.RestCMD;

            if (cmd != null)
            {
                switch (cmd.LocationMode)
                {
                case LocationMode.PrimaryOnly:
                case LocationMode.PrimaryThenSecondary:
                    this.CurrentLocation = StorageLocation.Primary;
                    break;

                case LocationMode.SecondaryOnly:
                case LocationMode.SecondaryThenPrimary:
                    this.CurrentLocation = StorageLocation.Secondary;
                    break;

                default:
                    CommonUtility.ArgumentOutOfRange("LocationMode", cmd.LocationMode);
                    break;
                }

                Logger.LogInformational(this.OperationContext, SR.TraceInitLocation, this.CurrentLocation, cmd.LocationMode);
            }
            else
            {
                this.CurrentLocation = StorageLocation.Primary;
            }
        }
示例#2
0
        /// <summary>
        /// Sets the position within the current stream.
        /// </summary>
        /// <param name="offset">A byte offset relative to the origin parameter.</param>
        /// <param name="origin">A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position.</param>
        /// <returns>The new position within the current stream.</returns>
        /// <exception cref="ArgumentException">Thrown if <paramref name="offset"/> is invalid for SeekOrigin.</exception>
        public override long Seek(long offset, SeekOrigin origin)
        {
            long newPosition;

            switch (origin)
            {
            case SeekOrigin.Begin:
                newPosition = offset;
                break;

            case SeekOrigin.Current:
                newPosition = this.position + offset;
                break;

            case SeekOrigin.End:
                newPosition = this.Length + offset;
                break;

            default:
                CommonUtility.ArgumentOutOfRange("origin", origin);
                throw new ArgumentOutOfRangeException("origin");
            }

            CommonUtility.AssertInBounds("offset", newPosition, 0, this.Length);

            this.position = newPosition;
            return(this.position);
        }
示例#3
0
        public override long Seek(long offset, SeekOrigin origin)
        {
            long val;

            switch (origin)
            {
            case SeekOrigin.Begin:
                val = offset;
                break;

            case SeekOrigin.Current:
                val = position + offset;
                break;

            case SeekOrigin.End:
                val = Length + offset;
                break;

            default:
                CommonUtility.ArgumentOutOfRange("origin", origin);
                throw new ArgumentOutOfRangeException("origin");
            }
            CommonUtility.AssertInBounds("offset", val, 0L, Length);
            position = val;
            return(position);
        }
示例#4
0
        private void InitializeLocation()
        {
            RESTCommand <T> restCMD = RestCMD;

            if (restCMD != null)
            {
                switch (restCMD.LocationMode)
                {
                case LocationMode.PrimaryOnly:
                case LocationMode.PrimaryThenSecondary:
                    CurrentLocation = StorageLocation.Primary;
                    break;

                case LocationMode.SecondaryOnly:
                case LocationMode.SecondaryThenPrimary:
                    CurrentLocation = StorageLocation.Secondary;
                    break;

                default:
                    CommonUtility.ArgumentOutOfRange("LocationMode", restCMD.LocationMode);
                    break;
                }
                Logger.LogInformational(OperationContext, "Starting operation with location {0} per location mode {1}.", CurrentLocation, restCMD.LocationMode);
            }
            else
            {
                CurrentLocation = StorageLocation.Primary;
            }
        }
示例#5
0
        /// <summary>
        /// Returns the URI for the storage account endpoint at the specified location.
        /// </summary>
        /// <param name="location">A <see cref="StorageLocation"/> enumeration value.</param>
        /// <returns>The <see cref="System.Uri"/> for the endpoint at the the specified location.</returns>
        public Uri GetUri(StorageLocation location)
        {
            switch (location)
            {
            case StorageLocation.Primary:
                return(this.PrimaryUri);

            case StorageLocation.Secondary:
                return(this.SecondaryUri);

            default:
                CommonUtility.ArgumentOutOfRange("location", location);
                return(null);
            }
        }
示例#6
0
        /// <summary>
        /// Sets the position within the current stream.
        /// </summary>
        /// <param name="offset">A byte offset relative to the origin parameter.</param>
        /// <param name="origin">A value of type <c>SeekOrigin</c> indicating the reference
        /// point used to obtain the new position.</param>
        /// <returns>The new position within the current stream.</returns>
        /// <remarks>Seeking in a FileReadStream disables checksum validation.</remarks>
        public override long Seek(long offset, SeekOrigin origin)
        {
            if (this.lastException != null)
            {
                throw this.lastException;
            }

            long newOffset;

            switch (origin)
            {
            case SeekOrigin.Begin:
                newOffset = offset;
                break;

            case SeekOrigin.Current:
                newOffset = this.currentOffset + offset;
                break;

            case SeekOrigin.End:
                newOffset = this.Length + offset;
                break;

            default:
                CommonUtility.ArgumentOutOfRange("origin", origin);
                throw new ArgumentOutOfRangeException("origin");
            }

            CommonUtility.AssertInBounds("offset", newOffset, 0, this.Length);

            if (newOffset != this.currentOffset)
            {
                long bufferOffset = this.internalBuffer.Position + (newOffset - this.currentOffset);
                if ((bufferOffset >= 0) && (bufferOffset < this.internalBuffer.Length))
                {
                    this.internalBuffer.Position = bufferOffset;
                }
                else
                {
                    this.internalBuffer.SetLength(0);
                }

                this.fileChecksum  = null;
                this.currentOffset = newOffset;
            }

            return(this.currentOffset);
        }
示例#7
0
        private static CommandLocationMode GetListingLocationMode(TableContinuationToken token)
        {
            if (token != null && token.TargetLocation.HasValue)
            {
                switch (token.TargetLocation.Value)
                {
                case StorageLocation.Primary:
                    return(CommandLocationMode.PrimaryOnly);

                case StorageLocation.Secondary:
                    return(CommandLocationMode.SecondaryOnly);
                }
                CommonUtility.ArgumentOutOfRange("TargetLocation", token.TargetLocation.Value);
            }
            return(CommandLocationMode.PrimaryOrSecondary);
        }
示例#8
0
        /// <summary>
        /// Constructs a web request to return a specified range of the file's content, together with its properties and metadata.
        /// </summary>
        /// <param name="uri">The absolute URI to the file.</param>
        /// <param name="timeout">The server timeout interval, in seconds.</param>
        /// <param name="offset">The byte offset at which to begin returning content.</param>
        /// <param name="count">The number of bytes to return, or null to return all bytes through the end of the file.</param>
        /// <param name="shareSnapshot">A <see cref="DateTimeOffset"/> specifying the share snapshot timestamp, if the share is a snapshot.</param>
        /// <param name="accessCondition">The access condition to apply to the request.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static StorageRequestMessage Get(Uri uri, int?timeout, long?offset, long?count, ChecksumRequested rangeContentChecksumRequested, DateTimeOffset?shareSnapshot, AccessCondition accessCondition, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
        {
            if (offset.HasValue && offset.Value < 0)
            {
                CommonUtility.ArgumentOutOfRange("offset", offset);
            }

            rangeContentChecksumRequested.AssertInBounds(offset, count, Constants.MaxRangeGetContentMD5Size, Constants.MaxRangeGetContentCRC64Size);

            StorageRequestMessage request = Get(uri, timeout, shareSnapshot, accessCondition, content, operationContext, canonicalizer, credentials);

            AddRange(request, offset, count);

            request.ApplyRangeContentChecksumRequested(offset, rangeContentChecksumRequested);

            return(request);
        }
示例#9
0
        /// <summary>
        /// Calculates the new position within the current stream for a Seek operation.
        /// </summary>
        /// <param name="offset">A byte offset relative to the origin parameter.</param>
        /// <param name="origin">A value of type <c>SeekOrigin</c> indicating the reference
        /// point used to obtain the new position.</param>
        /// <returns>The new position within the current stream.</returns>
        protected long GetNewOffset(long offset, SeekOrigin origin)
        {
            if (!this.CanSeek)
            {
                throw new NotSupportedException();
            }

            if (this.lastException != null)
            {
                throw this.lastException;
            }

            long newOffset;

            switch (origin)
            {
            case SeekOrigin.Begin:
                newOffset = offset;
                break;

            case SeekOrigin.Current:
                newOffset = this.currentOffset + offset;
                break;

            case SeekOrigin.End:
                newOffset = this.Length + offset;
                break;

            default:
                CommonUtility.ArgumentOutOfRange("origin", origin);
                throw new ArgumentOutOfRangeException("origin");
            }

            CommonUtility.AssertInBounds("offset", newOffset, 0, this.Length);

            if ((newOffset % Constants.PageSize) != 0)
            {
                CommonUtility.ArgumentOutOfRange("offset", offset);
            }

            return(newOffset);
        }
示例#10
0
        protected static StorageLocation GetNextLocation(StorageLocation lastLocation, LocationMode locationMode)
        {
            switch (locationMode)
            {
            case LocationMode.PrimaryOnly:
                return(StorageLocation.Primary);

            case LocationMode.SecondaryOnly:
                return(StorageLocation.Secondary);

            case LocationMode.PrimaryThenSecondary:
            case LocationMode.SecondaryThenPrimary:
                return((lastLocation == StorageLocation.Primary) ?
                       StorageLocation.Secondary :
                       StorageLocation.Primary);

            default:
                CommonUtility.ArgumentOutOfRange("LocationMode", locationMode);
                return(StorageLocation.Primary);
            }
        }
        /// <summary>
        /// Constructs a web request to return a specified range of the blob's content, together with its properties and metadata.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval, in seconds.</param>
        /// <param name="snapshot">The snapshot version, if the blob is a snapshot.</param>
        /// <param name="offset">The byte offset at which to begin returning content.</param>
        /// <param name="count">The number of bytes to return, or null to return all bytes through the end of the blob.</param>
        /// <param name="accessCondition">The access condition to apply to the request.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpRequestMessage Get(Uri uri, int?timeout, DateTimeOffset?snapshot, long?offset, long?count, bool rangeContentMD5, AccessCondition accessCondition, HttpContent content, OperationContext operationContext)
        {
            if (offset.HasValue && offset.Value < 0)
            {
                CommonUtility.ArgumentOutOfRange("offset", offset);
            }

            if (offset.HasValue && rangeContentMD5)
            {
                CommonUtility.AssertNotNull("count", count);
                CommonUtility.AssertInBounds("count", count.Value, 1, Constants.MaxBlockSize);
            }

            HttpRequestMessage request = Get(uri, timeout, snapshot, accessCondition, content, operationContext);

            AddRange(request, offset, count);

            if (offset.HasValue && rangeContentMD5)
            {
                request.Headers.Add(Constants.HeaderConstants.RangeContentMD5Header, Constants.HeaderConstants.TrueHeader);
            }

            return(request);
        }
        /// <summary>
        /// Constructs a web request to return a specified range of the file's content, together with its properties and metadata.
        /// </summary>
        /// <param name="uri">The absolute URI to the file.</param>
        /// <param name="timeout">The server timeout interval, in seconds.</param>
        /// <param name="offset">The byte offset at which to begin returning content.</param>
        /// <param name="count">The number of bytes to return, or null to return all bytes through the end of the file.</param>
        /// <param name="shareSnapshot">A <see cref="DateTimeOffset"/> specifying the share snapshot timestamp, if the share is a snapshot.</param>
        /// <param name="accessCondition">The access condition to apply to the request.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static StorageRequestMessage Get(Uri uri, int?timeout, long?offset, long?count, bool rangeContentMD5, DateTimeOffset?shareSnapshot, AccessCondition accessCondition, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
        {
            if (offset.HasValue && offset.Value < 0)
            {
                CommonUtility.ArgumentOutOfRange("offset", offset);
            }

            if (offset.HasValue && rangeContentMD5)
            {
                CommonUtility.AssertNotNull("count", count);
                CommonUtility.AssertInBounds("count", count.Value, 1, Constants.MaxRangeGetContentMD5Size);
            }

            StorageRequestMessage request = Get(uri, timeout, shareSnapshot, accessCondition, content, operationContext, canonicalizer, credentials);

            AddRange(request, offset, count);

            if (offset.HasValue && rangeContentMD5)
            {
                request.Headers.Add(Constants.HeaderConstants.RangeContentMD5Header, Constants.HeaderConstants.TrueHeader);
            }

            return(request);
        }
示例#13
0
        /// <summary>
        /// Constructs a web request to return a specified range of the file's content, together with its properties and metadata.
        /// </summary>
        /// <param name="uri">The absolute URI to the file.</param>
        /// <param name="timeout">The server timeout interval, in seconds.</param>
        /// <param name="offset">The byte offset at which to begin returning content.</param>
        /// <param name="count">The number of bytes to return, or null to return all bytes through the end of the file.</param>
        /// <param name="rangeContentMD5">If set to <c>true</c>, request an MD5 header for the specified range.</param>
        /// <param name="shareSnapshot">A <see cref="DateTimeOffset"/> specifying the share snapshot timestamp, if the share is a snapshot.</param>
        /// <param name="accessCondition">The access condition to apply to the request.</param>
        /// <param name="useVersionHeader">A flag indicating whether to set the x-ms-version HTTP header.</param>
        /// <param name="operationContext">An <see cref="OperationContext" /> object for tracking the current operation.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        internal static HttpWebRequest Get(Uri uri, int?timeout, long?offset, long?count, bool rangeContentMD5, DateTimeOffset?shareSnapshot, AccessCondition accessCondition, bool useVersionHeader, OperationContext operationContext)
        {
            if (offset.HasValue && offset.Value < 0)
            {
                CommonUtility.ArgumentOutOfRange("offset", offset);
            }

            if (offset.HasValue && rangeContentMD5)
            {
                CommonUtility.AssertNotNull("count", count);
                CommonUtility.AssertInBounds("count", count.Value, 1, Constants.MaxRangeGetContentMD5Size);
            }

            HttpWebRequest request = Get(uri, timeout, shareSnapshot, accessCondition, useVersionHeader, operationContext);

            AddRange(request, offset, count);

            if (offset.HasValue && rangeContentMD5)
            {
                request.Headers.Add(Constants.HeaderConstants.RangeContentMD5Header, Constants.HeaderConstants.TrueHeader);
            }

            return(request);
        }