/// <summary>Get the complete query builder for creating the Shared Access Signature query.</summary>
        /// <param name="policy">The shared access policy to hash. </param>
        /// <param name="groupPolicyIdentifier">An optional identifier for the policy. </param>
        /// <param name="resourceType">Either "b" for blobs or "c" for containers. </param>
        /// <param name="signature">The signature to use. </param>
        /// <returns>The finished query builder. </returns>
        internal static UriQueryBuilder GetShareAccessSignatureImpl(
            SharedAccessPolicy policy, string groupPolicyIdentifier, string resourceType, string signature)
        {
            CommonUtils.AssertNotNull("policy", policy);
            CommonUtils.AssertNotNullOrEmpty("resourceType", resourceType);
            CommonUtils.AssertNotNull("signature", signature);

            var builder = new UriQueryBuilder();

            // FUTURE blob for blob and container for container
            var permissions = SharedAccessPolicy.PermissionsToString(policy.Permissions);
            if (string.IsNullOrEmpty(permissions))
            {
                permissions = null;
            }

            AddEscapedIfNotNull(
                builder, Constants.QueryConstants.SignedStart, GetDateTimeOrNull(policy.SharedAccessStartTime));
            AddEscapedIfNotNull(
                builder, Constants.QueryConstants.SignedExpiry, GetDateTimeOrNull(policy.SharedAccessExpiryTime));
            builder.Add(Constants.QueryConstants.SignedResource, resourceType);
            AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedPermissions, permissions);
            AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedIdentifierShort, groupPolicyIdentifier);
            AddEscapedIfNotNull(builder, Constants.QueryConstants.Signature, signature);

            return builder;
        }
 /// <summary>Escapes and adds the specified name/value pair to the query builder if it is not null.</summary>
 /// <param name="builder">The builder to add the value to. </param>
 /// <param name="name">The name of the pair. </param>
 /// <param name="value">The value to be escaped. </param>
 internal static void AddEscapedIfNotNull(UriQueryBuilder builder, string name, string value)
 {
     if (value != null)
     {
         builder.Add(name, value);
     }
 }
예제 #3
0
        /// <summary>
        /// Creates the web request.
        /// </summary>
        /// <param name="uri">The request Uri.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="builder">The builder.</param>
        /// <returns>A web request for performing the operation.</returns>
        internal static HttpWebRequest CreateWebRequest(Uri uri, int timeout, UriQueryBuilder builder)
        {
            if (builder == null)
            {
                builder = new UriQueryBuilder();
            }

            if (timeout != 0)
            {
                builder.Add("timeout", timeout.ToString());
            }

            Uri uriRequest = builder.AddToUri(uri);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriRequest);

            request.Headers.Add(Constants.HeaderConstants.StorageVersionHeader, GetTargetVersion());
            request.UserAgent = Request.UserAgent;
            return request;
        }
예제 #4
0
 /// <summary>
 ///   Generates a query builder for building service requests.
 /// </summary>
 /// <returns> A <see cref="UriQueryBuilder" /> for building service requests. </returns>
 internal static UriQueryBuilder GetServiceUriQueryBuilder()
 {
     var uriBuilder = new UriQueryBuilder();
     uriBuilder.Add(Constants.QueryConstants.ResourceType, "service");
     return uriBuilder;
 }
예제 #5
0
 /// <summary>
 /// Creates the web request.
 /// </summary>
 /// <param name="uri">The absolute URI to the container.</param>
 /// <param name="timeout">The server timeout interval.</param>
 /// <param name="query">The query builder to use.</param>
 /// <returns><returns>A web request to use to perform the operation.</returns></returns>
 private static HttpWebRequest CreateWebRequest(Uri uri, int timeout, UriQueryBuilder query)
 {
     return(Request.CreateWebRequest(uri, timeout, query));
 }
예제 #6
0
        /// <summary>
        ///   Gets the properties.
        /// </summary>
        /// <param name="uri"> The Uri to query. </param>
        /// <param name="timeout"> The timeout. </param>
        /// <param name="builder"> The builder. </param>
        /// <returns> A web request for performing the operation. </returns>
        internal static HttpWebRequest GetProperties(Uri uri, int timeout, UriQueryBuilder builder)
        {
            if (builder == null)
            {
                builder = new UriQueryBuilder();
            }

            var request = CreateWebRequest(uri, timeout, builder);

            request.Method = "HEAD";

            return request;
        }
예제 #7
0
        /// <summary>
        /// Constructs a web request to set system properties for a blob.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="properties">The blob's properties.</param>
        /// <param name="leaseId">The lease ID, if the blob has an active lease.</param>
        /// <param name="newBlobSize">The new blob size, if the blob is a page blob. Set this parameter to <c>null</c> to keep the existing blob size.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest SetProperties(Uri uri, int timeout, BlobProperties properties, string leaseId, long? newBlobSize)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "properties");

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.ContentLength = 0;
            request.Method = "PUT";

            Request.AddLeaseId(request, leaseId);

            if (newBlobSize.HasValue)
            {
                request.Headers.Add(Constants.HeaderConstants.Size, newBlobSize.Value.ToString(NumberFormatInfo.InvariantInfo));
                properties.Length = newBlobSize.Value;
            }

            Request.AddOptionalHeader(request, Constants.HeaderConstants.CacheControlHeader, properties.CacheControl);
            Request.AddOptionalHeader(request, Constants.HeaderConstants.ContentEncodingHeader, properties.ContentEncoding);
            Request.AddOptionalHeader(request, Constants.HeaderConstants.ContentLanguageHeader, properties.ContentLanguage);
            Request.AddOptionalHeader(request, Constants.HeaderConstants.BlobContentMD5Header, properties.ContentMD5);
            Request.AddOptionalHeader(request, Constants.HeaderConstants.ContentTypeHeader, properties.ContentType);

            return request;
        }
예제 #8
0
 /// <summary>
 /// Adds the snapshot.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="snapshot">The snapshot version, if the blob is a snapshot.</param>
 private static void AddSnapshot(UriQueryBuilder builder, DateTime? snapshot)
 {
     if (snapshot != null)
     {
         builder.Add("snapshot", Request.ConvertDateTimeToSnapshotString(snapshot.Value.ToUniversalTime()));
     }
 }
예제 #9
0
        /// <summary>
        /// Constructs a web request to return the blob's system properties.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="snapshot">The snapshot timestamp, if the blob is a snapshot.</param>
        /// <param name="leaseId">The lease ID.</param>
        /// <returns>A web request for performing the operation.</returns>
        public static HttpWebRequest GetProperties(Uri uri, int timeout, DateTime? snapshot, string leaseId)
        {
            UriQueryBuilder builder = new UriQueryBuilder();

            BlobRequest.AddSnapshot(builder, snapshot);

            var request = Request.GetProperties(uri, timeout, builder);
            Request.AddLeaseId(request, leaseId);
            return request;
        }
예제 #10
0
        /// <summary>
        /// Constructs a web request to return the user-defined metadata for this container.
        /// </summary>
        /// <param name="uri">The absolute URI to the container.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest GetProperties(Uri uri, int timeout)
        {
            UriQueryBuilder containerBuilder = GetContainerUriQueryBuilder();

            return(Request.GetProperties(uri, timeout, containerBuilder));
        }
예제 #11
0
        /// <summary>
        /// Generates a web request to update a message.
        /// </summary>
        /// <param name="uri">The absolute URI to the message to update.</param>
        /// <param name="timeout">The server timeout interval, in seconds.</param>
        /// <param name="popReceipt">The pop receipt of the message.</param>
        /// <param name="visibilityTimeout">The length of time from now during which the message will be invisible, in seconds.</param>
        /// <returns>A web request for the update operation.</returns>
        public static HttpWebRequest UpdateMessage(Uri uri, int timeout, string popReceipt, int visibilityTimeout)
        {
            UriQueryBuilder builder = new UriQueryBuilder();

            builder.Add(Constants.QueryConstants.PopReceipt, popReceipt);
            builder.Add(Constants.QueryConstants.VisibilityTimeout, visibilityTimeout.ToString());

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "PUT";

            return request;
        }
예제 #12
0
        /// <summary>
        /// Constructs a web request to return the list of blocks for a block blob.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="snapshot">The snapshot timestamp, if the blob is a snapshot.</param>
        /// <param name="typesOfBlocks">The types of blocks to include in the list: committed, uncommitted, or both.</param>
        /// <param name="leaseId">The lease ID for the blob, if it has an active lease.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest GetBlockList(Uri uri, int timeout, DateTime? snapshot, BlockListingFilter typesOfBlocks, string leaseId)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "blocklist");

            builder.Add("blocklisttype", typesOfBlocks.ToString());
        
            BlobRequest.AddSnapshot(builder, snapshot);

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "GET";

            Request.AddLeaseId(request, leaseId);

            return request;
        }
예제 #13
0
        /// <summary>
        /// Constructs a web request to retrieve a specified number of messages without changing their visibility.
        /// </summary>
        /// <param name="uri">The absolute URI to the queue.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="numberOfMessages">The number of messages to retrieve.</param>
        /// <returns>A web request for performing the specified operation.</returns>
        public static HttpWebRequest PeekMessages(Uri uri, int timeout, int? numberOfMessages)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add("peekonly", "true");

            if (numberOfMessages != null)
            {
                builder.Add("numofmessages", numberOfMessages.ToString());
            }

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "GET";

            return request;
        }
예제 #14
0
        /// <summary>
        /// Generates a web request to add a message to a queue.
        /// </summary>
        /// <param name="uri">The absolute URI to the queue's messages.</param>
        /// <param name="timeout">The server timeout interval, in seconds.</param>
        /// <param name="messageTimeToLive">The message time-to-live in seconds. If null, the service default will be used.</param>
        /// <param name="visibilityTimeout">The length of time from now during which the message will be invisible, in seconds.
        /// If null, the message will be visible immediately.</param>
        /// <returns>A web request for the put operation.</returns>
        public static HttpWebRequest PutMessage(Uri uri, int timeout, int? messageTimeToLive, int? visibilityTimeout)
        {
            UriQueryBuilder builder = new UriQueryBuilder();

            if (visibilityTimeout != null)
            {
                builder.Add(Constants.QueryConstants.VisibilityTimeout, visibilityTimeout.ToString());
            }

            if (messageTimeToLive != null)
            {
                builder.Add(Constants.QueryConstants.MessageTimeToLive, messageTimeToLive.ToString());
            }

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "POST";

            return request;
        }
예제 #15
0
        /// <summary>
        /// Constructs a web request to retrieve a specified number of messages.
        /// </summary>
        /// <param name="uri">The absolute URI to the queue.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="numberOfMessages">The number of messages to retrieve.</param>
        /// <param name="visibilityTimeout">The visibility timeout for the message or messages.</param>
        /// <returns>A web request for the specified operation.</returns>
        public static HttpWebRequest GetMessages(Uri uri, int timeout, int? numberOfMessages, int? visibilityTimeout)
        {
            UriQueryBuilder builder = new UriQueryBuilder();

            if (numberOfMessages != null)
            {
                builder.Add("numofmessages", numberOfMessages.ToString());
            }

            if (visibilityTimeout != null)
            {
                builder.Add(Constants.QueryConstants.VisibilityTimeout, visibilityTimeout.ToString());
            }

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "GET";

            return request;
        }
예제 #16
0
        /// <summary>
        /// Constructs a web request to delete the specified message.
        /// </summary>
        /// <param name="uri">The absolute URI to the queue.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="popReceipt">The pop receipt value for the message.</param>
        /// <returns>A web request for the specified operation.</returns>
        public static HttpWebRequest DeleteMessage(Uri uri, int timeout, string popReceipt)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.PopReceipt, popReceipt);

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "DELETE";

            return request;
        }
예제 #17
0
        /// <summary>
        /// Constructs a web request to set user-defined metadata for the container.
        /// </summary>
        /// <param name="uri">The absolute URI to the container.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest SetMetadata(Uri uri, int timeout)
        {
            UriQueryBuilder containerBuilder = GetContainerUriQueryBuilder();

            return(Request.SetMetadata(uri, timeout, containerBuilder));
        }
예제 #18
0
        /// <summary>
        ///   Sets the metadata.
        /// </summary>
        /// <param name="uri"> The blob Uri. </param>
        /// <param name="timeout"> The timeout. </param>
        /// <param name="builder"> The builder. </param>
        /// <returns> A web request for performing the operation. </returns>
        internal static HttpWebRequest SetMetadata(Uri uri, int timeout, UriQueryBuilder builder)
        {
            if (builder == null)
            {
                builder = new UriQueryBuilder();
            }

            builder.Add(Constants.QueryConstants.Component, "metadata");
            var request = CreateWebRequest(uri, timeout, builder);

            request.ContentLength = 0;
            request.Method = "PUT";

            return request;
        }
예제 #19
0
        /// <summary>
        /// Constructs a web request to use to acquire, renew, release or break the lease for the blob.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="action">The lease action to perform.</param>
        /// <param name="leaseId">The lease ID.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest Lease(Uri uri, int timeout, LeaseAction action, string leaseId)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "lease");

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.ContentLength = 0;
            request.Method = "PUT";

            Request.AddLeaseId(request, leaseId);

            // acquire, renew, release, or break; required
            request.Headers.Add("x-ms-lease-action", action.ToString());

            return request;
        }
예제 #20
0
        /// <summary>
        /// Constructs a web request to delete a blob.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="snapshot">The snapshot timestamp, if the blob is a snapshot.</param>
        /// <param name="deleteSnapshotsOption">A set of options indicating whether to delete only blobs, only snapshots, or both.</param>
        /// <param name="leaseId">The lease ID, if the blob has an active lease.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest Delete(Uri uri, int timeout, DateTime? snapshot, DeleteSnapshotsOption deleteSnapshotsOption, string leaseId)
        {
            UriQueryBuilder builder = new UriQueryBuilder();

            if (snapshot != null && deleteSnapshotsOption != DeleteSnapshotsOption.None)
            {
                throw new InvalidOperationException(String.Format(SR.DeleteSnapshotsNotValidError, "deleteSnapshotsOption", "snapshot"));
            }

            BlobRequest.AddSnapshot(builder, snapshot);

            var request = Request.Delete(uri, timeout, builder);

            Request.AddLeaseId(request, leaseId);

            switch (deleteSnapshotsOption)
            {
                case DeleteSnapshotsOption.None:
                     break; // nop
                case DeleteSnapshotsOption.IncludeSnapshots:
                     request.Headers.Add(
                         Constants.HeaderConstants.DeleteSnapshotHeader,
                         Constants.HeaderConstants.IncludeSnapshotsValue);
                     break;
                case DeleteSnapshotsOption.DeleteSnapshotsOnly:
                     request.Headers.Add(
                         Constants.HeaderConstants.DeleteSnapshotHeader, 
                         Constants.HeaderConstants.SnapshotsOnlyValue);
                    break;
            }

            return request;
        }
예제 #21
0
        /// <summary>
        /// Constructs a web request to create or update a blob by committing a block list.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="properties">The properties to set for the blob.</param>
        /// <param name="leaseId">The lease ID, if the blob has an active lease.</param>
        /// <returns>A web request for performing the operation.</returns>
        public static HttpWebRequest PutBlockList(
            Uri uri,
            int timeout,
            BlobProperties properties,
            string leaseId)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "blocklist");

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "PUT";

            Request.AddLeaseId(request, leaseId);

            Request.AddOptionalHeader(request, Constants.HeaderConstants.CacheControlHeader, properties.CacheControl);
            Request.AddOptionalHeader(request, Constants.HeaderConstants.ContentTypeHeader, properties.ContentType);
            Request.AddOptionalHeader(request, Constants.HeaderConstants.BlobContentMD5Header, properties.ContentMD5);
            Request.AddOptionalHeader(request, Constants.HeaderConstants.ContentLanguageHeader, properties.ContentLanguage);
            Request.AddOptionalHeader(request, Constants.HeaderConstants.ContentEncodingHeader, properties.ContentEncoding);

            return request;
        }
예제 #22
0
        /// <summary>
        /// Constructs a web request to get the blob's content, properties, and metadata.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="snapshot">The snapshot version, if the blob is a snapshot.</param>
        /// <param name="leaseId">The lease ID for the blob, if it has an active lease.</param>
        /// <returns>A web request for performing the operation.</returns>
        public static HttpWebRequest Get(Uri uri, int timeout, DateTime? snapshot, string leaseId)
        {
            UriQueryBuilder builder = new UriQueryBuilder();

            BlobRequest.AddSnapshot(builder, snapshot);

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "GET";

            if (leaseId != null)
            {
                Request.AddLeaseId(request, leaseId);
            }

            return request;
        }
예제 #23
0
        /// <summary>
        /// Constructs a web request to delete the container and all of blobs within it.
        /// </summary>
        /// <param name="uri">The absolute URI to the container.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest Delete(Uri uri, int timeout)
        {
            UriQueryBuilder containerBuilder = GetContainerUriQueryBuilder();

            return(Request.Delete(uri, timeout, containerBuilder));
        }
예제 #24
0
        /// <summary>
        /// Constructs a web request to return the list of active page ranges for a page blob.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="snapshot">The snapshot timestamp, if the blob is a snapshot.</param>
        /// <param name="leaseId">The lease ID, if the blob has an active lease.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest GetPageRanges(Uri uri, int timeout, DateTime? snapshot, string leaseId)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "pagelist");

            BlobRequest.AddSnapshot(builder, snapshot);

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "GET";

            Request.AddLeaseId(request, leaseId);

            return request;
        }
예제 #25
0
        /// <summary>
        /// Constructs a web request to return a listing of all containers in this storage account.
        /// </summary>
        /// <param name="uri">The absolute URI for the account.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="listingContext">A set of parameters for the listing operation.</param>
        /// <param name="detailsIncluded">Additional details to return with the listing.</param>
        /// <returns>A web request for the specified operation.</returns>
        public static HttpWebRequest List(Uri uri, int timeout, ListingContext listingContext, ContainerListingDetails detailsIncluded)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "list");

            if (listingContext != null)
            {
                if (listingContext.Prefix != null)
                {
                    builder.Add("prefix", listingContext.Prefix);
                }

                if (listingContext.Marker != null)
                {
                    builder.Add("marker", listingContext.Marker);
                }

                if (listingContext.MaxResults != null)
                {
                    builder.Add("maxresults", listingContext.MaxResults.ToString());
                }
            }

            if ((detailsIncluded & ContainerListingDetails.Metadata) != 0)
            {
                builder.Add("include", "metadata");
            }

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "GET";

            return request;
        }
예제 #26
0
        /// <summary>
        /// Constructs a web request to write a block to a block blob.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="blockId">The block ID for this block.</param>
        /// <param name="leaseId">The lease ID for the blob, if it has an active lease.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest PutBlock(Uri uri, int timeout, string blockId, string leaseId)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "block");

            builder.Add("blockid", blockId);

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "PUT";

            Request.AddLeaseId(request, leaseId);

            return request;
        }
예제 #27
0
 /// <summary>
 /// Gets the container Uri query builder.
 /// </summary>
 /// <returns>A <see cref="UriQueryBuilder"/> for the container.</returns>
 internal static UriQueryBuilder GetContainerUriQueryBuilder()
 {
     UriQueryBuilder uriBuilder = new UriQueryBuilder();
     uriBuilder.Add(Constants.QueryConstants.ResourceType, "container");
     return uriBuilder;
 }
예제 #28
0
        /// <summary>
        /// Constructs a web request to write or clear a range of pages in a page blob.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="properties">The blob's properties.</param>
        /// <param name="leaseId">The lease ID, if the blob has an active lease.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest PutPage(Uri uri, int timeout, PutPageProperties properties, string leaseId)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "page");

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.Method = "PUT";

            Request.AddLeaseId(request, leaseId);

            Request.AddOptionalHeader(request, Constants.HeaderConstants.RangeHeader, properties.Range.ToString());

            // Page write is either update or clean; required
            request.Headers.Add(Constants.HeaderConstants.PageWrite, properties.PageWrite.ToString());

            return request;
        }
        /// <summary>
        /// Parses the query.
        /// </summary>
        /// <param name="queryParameters">The query parameters.</param>
        /// <param name="credentials">The credentials.</param>
        internal static void ParseQuery(NameValueCollection queryParameters, out StorageCredentialsSharedAccessSignature credentials)
        {
            string signature = null;
            string signedStart = null;
            string signedExpiry = null;
            string signedResource = null;
            string sigendPermissions = null;
            string signedIdentifier = null;
            string signedVersion = null;

            bool sasParameterFound = false;

            credentials = null;

            foreach (var key in queryParameters.AllKeys)
            {
                switch (key.ToLower())
                {
                    case Constants.QueryConstants.SignedStart:
                        signedStart = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedExpiry:
                        signedExpiry = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedPermissions:
                        sigendPermissions = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedResource:
                        signedResource = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedIdentifier:
                        signedIdentifier = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.Signature:
                        signature = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    case Constants.QueryConstants.SignedVersion:
                        signedVersion = queryParameters[key];
                        sasParameterFound = true;
                        break;

                    default:
                        break;
                    //// string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.InvalidQueryParametersInsideBlobAddress, key.ToLower());
                    //// throw new ArgumentException(errorMessage);
                }
            }

            if (sasParameterFound)
            {
                if (signature == null || signedResource == null)
                {
                    string errorMessage = string.Format(CultureInfo.CurrentCulture, SR.MissingMandatoryParamtersForSAS);
                    throw new ArgumentException(errorMessage);
                }

                UriQueryBuilder builder = new UriQueryBuilder();
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedStart, signedStart);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedExpiry, signedExpiry);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedPermissions, sigendPermissions);
                builder.Add(Constants.QueryConstants.SignedResource, signedResource);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedIdentifier, signedIdentifier);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.SignedVersion, signedVersion);
                AddEscapedIfNotNull(builder, Constants.QueryConstants.Signature, signature);

                string token = builder.ToString();
                credentials = new StorageCredentialsSharedAccessSignature(token);
            }
        }
예제 #30
0
        /// <summary>
        /// Constructs a web request to create a snapshot of a blob.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest Snapshot(Uri uri, int timeout)
        {
            UriQueryBuilder builder = new UriQueryBuilder();
            builder.Add(Constants.QueryConstants.Component, "snapshot");

            HttpWebRequest request = CreateWebRequest(uri, timeout, builder);

            request.ContentLength = 0;
            request.Method = "PUT";

            return request;
        }
예제 #31
0
        /// <summary>
        ///   Creates the specified Uri.
        /// </summary>
        /// <param name="uri"> The Uri to create. </param>
        /// <param name="timeout"> The timeout. </param>
        /// <param name="builder"> The builder. </param>
        /// <returns> A web request for performing the operation. </returns>
        internal static HttpWebRequest Create(Uri uri, int timeout, UriQueryBuilder builder)
        {
            if (builder == null)
            {
                builder = new UriQueryBuilder();
            }

            var request = CreateWebRequest(uri, timeout, builder);
            request.ContentLength = 0;
            request.Method = "PUT";

            return request;
        }
예제 #32
0
 /// <summary>
 /// Creates the web request.
 /// </summary>
 /// <param name="uri">The Uri of the resource.</param>
 /// <param name="timeout">The timeout to apply.</param>
 /// <param name="query">The query builder to use.</param>
 /// <returns>The resulting <see cref="HttpWebRequest"/>.</returns>
 private static HttpWebRequest CreateWebRequest(Uri uri, int timeout, UriQueryBuilder query)
 {
     return Request.CreateWebRequest(uri, timeout, query);
 }
예제 #33
0
        /// <summary>
        ///   Deletes the specified Uri.
        /// </summary>
        /// <param name="uri"> The Uri to delete. </param>
        /// <param name="timeout"> The timeout. </param>
        /// <param name="builder"> The builder. </param>
        /// <returns> A web request for performing the operation. </returns>
        internal static HttpWebRequest Delete(Uri uri, int timeout, UriQueryBuilder builder)
        {
            if (builder == null)
            {
                builder = new UriQueryBuilder();
            }

            var request = CreateWebRequest(uri, timeout, builder);

            request.Method = "DELETE";

            return request;
        }