Exemplo n.º 1
0
        public void CreateShare(string shareName, int retries, int millisecondsBetweenRetries)
        {
            while (true)
            {
                HttpWebRequest request = FileTests.CreateShareRequest(FileContext, shareName);
                Assert.IsTrue(request != null, "Failed to create HttpWebRequest");

                if (FileContext.Credentials != null)
                {
                    FileTests.SignRequest(request, FileContext);
                }
                HttpWebResponse response              = FileTestUtils.GetResponse(request, FileContext);
                HttpStatusCode  statusCode            = response.StatusCode;
                string          statusDescription     = response.StatusDescription;
                StorageExtendedErrorInformation error = StorageExtendedErrorInformation.ReadFromStream(response.GetResponseStream());
                response.Close();

                // if the share is being deleted, retry up to the specified times.
                if (statusCode == HttpStatusCode.Conflict && error != null && error.ErrorCode == FileErrorCodeStrings.ShareBeingDeleted && retries > 0)
                {
                    Thread.Sleep(millisecondsBetweenRetries);
                    retries--;
                    continue;
                }

                break;
            }
        }
Exemplo n.º 2
0
        public async Task CreateShare(string shareName, int retries, int millisecondsBetweenRetries)
        {
            while (true)
            {
                HttpRequestMessage request = FileTests.CreateShareRequest(FileContext, shareName);
                Assert.IsTrue(request != null, "Failed to create HttpRequestMessage");

                HttpResponseMessage response = await FileTestUtils.GetResponse(request, FileContext);

                HttpStatusCode statusCode             = response.StatusCode;
                string         statusDescription      = response.ReasonPhrase;
                StorageExtendedErrorInformation error = await StorageExtendedErrorInformation.ReadFromStreamAsync(await response.Content.ReadAsStreamAsync());

                response.Dispose();

                // if the share is being deleted, retry up to the specified times.
                if (statusCode == HttpStatusCode.Conflict && error != null && error.ErrorCode == FileErrorCodeStrings.ShareBeingDeleted && retries > 0)
                {
                    Thread.Sleep(millisecondsBetweenRetries);
                    retries--;
                    continue;
                }

                Assert.AreNotEqual(HttpStatusCode.NotFound, statusCode, "Failed to create share");

                break;
            }
        }