Ejemplo n.º 1
0
        public async Task CreateContainer(string containerName, bool isPublic, int retries, int millisecondsBetweenRetries)
        {
            HttpStatusCode statusCode;
            StorageExtendedErrorInformation error;

            while (true)
            {
                HttpRequestMessage request = BlobTests.CreateContainerRequest(BlobContext, containerName);
                Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");
                if (isPublic)
                {
                    request.Headers.Add("x-ms-blob-public-access", "container");
                }

                using (HttpResponseMessage response = await BlobTestUtils.GetResponse(request, BlobContext))
                {
                    statusCode = response.StatusCode;
                    string statusDescription = response.ReasonPhrase;
                    error = await StorageExtendedErrorInformation.ReadFromStreamAsync(
                        HttpResponseParsers.GetResponseStream(response));
                }

                // if the container is being deleted, retry up to the specified times.
                if (statusCode == HttpStatusCode.Conflict && error != null && error.ErrorCode == BlobErrorCodeStrings.ContainerBeingDeleted && retries > 0)
                {
                    await Task.Delay(millisecondsBetweenRetries);

                    retries--;
                    continue;
                }

                break;
            }
        }