Example #1
0
        /// <summary>
        /// Generates and validates a request to break a lease.
        /// </summary>
        /// <param name="context">The blob context.</param>
        /// <param name="containerName">The container name.</param>
        /// <param name="blobName">The blob name.</param>
        /// <param name="breakPeriod">The break period.</param>
        /// <returns>A web request for the operation.</returns>
        public static HttpRequestMessage BreakLeaseRequest(BlobContext context, string containerName, string blobName, int?breakPeriod, AccessCondition accessCondition)
        {
            HttpRequestMessage request;
            OperationContext   opContext = new OperationContext();

            if (blobName != null)
            {
                // blob lease
                Uri uri = BlobTests.ConstructPutUri(context.Address, containerName, blobName);
                request = BlobHttpRequestMessageFactory.Lease(
                    uri,
                    context.Timeout,
                    LeaseAction.Break,
                    null /* proposed lease ID */,
                    null /* lease duration */,
                    breakPeriod,
                    accessCondition,
                    null,
                    opContext,
                    SharedKeyCanonicalizer.Instance,
                    context.Credentials);
            }
            else
            {
                // container lease
                Uri uri = BlobClientTests.ConstructUri(context.Address, containerName);
                request = ContainerHttpRequestMessageFactory.Lease(
                    uri,
                    context.Timeout,
                    LeaseAction.Break,
                    null /* proposed lease ID */,
                    null /* lease duration */,
                    breakPeriod,
                    accessCondition,
                    null,
                    opContext,
                    SharedKeyCanonicalizer.Instance,
                    context.Credentials);
            }
            Assert.IsNotNull(request);
            Assert.AreEqual(HttpMethod.Put, request.Method);
            BlobTestUtils.VersionHeader(request, false);
            BlobTestUtils.LeaseIdHeader(request, null);
            BlobTestUtils.LeaseActionHeader(request, "break");
            BlobTestUtils.LeaseDurationHeader(request, null);
            BlobTestUtils.ProposedLeaseIdHeader(request, null);
            BlobTestUtils.BreakPeriodHeader(request, breakPeriod.HasValue ? breakPeriod.Value.ToString() : null);
            return(request);
        }
Example #2
0
        public static HttpRequestMessage ListContainersRequest(BlobContext context, ListingContext listingContext)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address);
            OperationContext   opContext = new OperationContext();
            HttpRequestMessage request   = ContainerHttpRequestMessageFactory.List(uri, context.Timeout, listingContext, ContainerListingDetails.Metadata, null,
                                                                                   opContext,
                                                                                   SharedKeyCanonicalizer.Instance,
                                                                                   context.Credentials);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual(HttpMethod.Get, request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }
Example #3
0
        public static HttpRequestMessage DeleteContainerRequest(BlobContext context, string containerName, AccessCondition accessCondition)
        {
            Uri uri = BlobClientTests.ConstructUri(context.Address, containerName);
            OperationContext   opContext = new OperationContext();
            HttpRequestMessage request   = ContainerHttpRequestMessageFactory.Delete(uri, context.Timeout, accessCondition, null,
                                                                                     opContext,
                                                                                     SharedKeyCanonicalizer.Instance,
                                                                                     context.Credentials);

            Assert.IsNotNull(request);
            Assert.IsNotNull(request.Method);
            Assert.AreEqual(HttpMethod.Delete, request.Method);
            BlobTestUtils.RangeHeader(request, null);
            BlobTestUtils.LeaseIdHeader(request, null);
            return(request);
        }
 /// <summary>
 /// Constructs a web request to create a new 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 StorageRequestMessage Create(Uri uri, int?timeout, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
 {
     return(ContainerHttpRequestMessageFactory.Create(uri, timeout, content, operationContext, BlobContainerPublicAccessType.Off, canonicalizer, credentials));
 }
        /// <summary>
        /// Generates a web request to return a listing of all blobs in the container.
        /// </summary>
        /// <param name="uri">The absolute URI to the container.</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 StorageRequestMessage ListBlobs(Uri uri, int?timeout, BlobListingContext listingContext, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
        {
            UriQueryBuilder builder = ContainerHttpRequestMessageFactory.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.HasValue)
                {
                    builder.Add("maxresults", listingContext.MaxResults.ToString());
                }

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

                    bool started = false;

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

                        sb.Append("snapshots");
                    }

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

                        sb.Append("uncommittedblobs");
                    }

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

                        sb.Append("metadata");
                    }

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

                        sb.Append("copy");
                    }

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

            StorageRequestMessage request = HttpRequestMessageFactory.CreateRequestMessage(HttpMethod.Get, uri, timeout, builder, content, operationContext, canonicalizer, credentials);

            return(request);
        }
 /// <summary>
 /// Constructs a web request to create a new 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 HttpRequestMessage Create(Uri uri, int?timeout, HttpContent content, OperationContext operationContext)
 {
     return(ContainerHttpRequestMessageFactory.Create(uri, timeout, content, operationContext, BlobContainerPublicAccessType.Off));
 }