/// <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);
     }
 }
        /// <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);
        }
        /// <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);
        }
Example #4
0
        /// <summary>
        /// Sets the ACL for the container.
        /// </summary>
        /// <param name="uri">The absolute URI to the container.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="publicAccess">The type of public access to allow for the container.</param>
        /// <returns><returns>A web request to use to perform the operation.</returns></returns>
        public static HttpWebRequest SetAcl(Uri uri, int timeout, BlobContainerPublicAccessType publicAccess)
        {
            UriQueryBuilder builder = GetContainerUriQueryBuilder();

            builder.Add(Constants.QueryConstants.Component, "acl");

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

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

            if (publicAccess != BlobContainerPublicAccessType.Off)
            {
                request.Headers.Add("x-ms-blob-public-access", publicAccess.ToString().ToLower());
            }

            return(request);
        }
        /// <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>
        /// 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);
        }
        /// <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;
        }
        /// <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;
        }
        /// <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;
        }
Example #10
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;
        }
Example #11
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;
        }
Example #12
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;
 }
        /// <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);

            UriQueryBuilder builder = new UriQueryBuilder();

            // FUTURE blob for blob and container for container
            string 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.SignedIdentifier, groupPolicyIdentifier);
            AddEscapedIfNotNull(builder, Constants.QueryConstants.Signature, signature);

            return builder;
        }
        /// <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);
            }
        }
 /// <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;
 }
        /// <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;
        }
        /// <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;
        }
Example #18
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;
        }
Example #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;
        }
        /// <summary>
        /// Constructs a web request to return a listing of all blobs in the container.
        /// </summary>
        /// <param name="uri">The absolute URI to the blob.</param>
        /// <param name="timeout">The server timeout interval.</param>
        /// <param name="listingContext">A set of parameters for the listing operation.</param>
        /// <returns>A web request to use to perform the operation.</returns>
        public static HttpWebRequest List(Uri uri, int timeout, BlobListingContext listingContext)
        {
            UriQueryBuilder builder = ContainerRequest.GetContainerUriQueryBuilder();

            builder.Add(Constants.QueryConstants.Component, "list");

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

                if (listingContext.Delimiter != null)
                {
                    builder.Add("delimiter", listingContext.Delimiter);
                }

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

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

                if (listingContext.Include != BlobListingDetails.None)
                {
                    StringBuilder sb = new StringBuilder();

                    bool started = false;

                    if ((listingContext.Include & BlobListingDetails.Snapshots) == BlobListingDetails.Snapshots)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("snapshots");
                    }

                    if ((listingContext.Include & BlobListingDetails.UncommittedBlobs) == BlobListingDetails.UncommittedBlobs)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("uncommittedblobs");
                    }

                    if ((listingContext.Include & BlobListingDetails.Metadata) == BlobListingDetails.Metadata)
                    {
                        if (!started)
                        {
                            started = true;
                        }
                        else
                        {
                            sb.Append(",");
                        }

                        sb.Append("metadata");
                    }

                    builder.Add("include", sb.ToString());
                }
            }

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

            request.Method = "GET";

            return(request);
        }
Example #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;
        }
        /// <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;
        }
Example #23
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;
        }
        /// <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;
        }
Example #25
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()));
     }
 }
        /// <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;
        }