示例#1
0
        private static void WaitTillComplete(string stateOfCopyOperation, Uri blobUri, string accountName, string accountKey)
        {
            if (stateOfCopyOperation == "success")
            {
                return;
            }

            while (true)
            {
                System.Threading.Thread.Sleep(5000);
                BlobProperties properties = GetBlobProperties.Get(blobUri, accountName, accountKey);

                if (properties.CopyStatus == CopyStatus.Success)
                {
                    break;
                }
                if (properties.CopyStatus != CopyStatus.Pending)
                {
                    throw new ApplicationFailedException(string.Format(CultureInfo.InvariantCulture, "Error copying blob - Copy status {0} - Error description {1}", properties.CopyStatus, properties.CopyStatusDescription));
                }
                Console.WriteLine("Copying blob in progress - copied {0} of {1}", properties.BytesCopied, properties.BytesTotal);
            }
        }
示例#2
0
        public static BlobProperties Get(Uri blobUri, string accountName, string accountKey)
        {
            HttpWebRequest request = CreateRequest(blobUri);
            request.ServicePoint.Expect100Continue = false;

            string canonicalizedRequest = CanonicalizeRequest(request, blobUri, accountName);
            string sha = GetSHA(canonicalizedRequest, Convert.FromBase64String(accountKey));
            request.Headers.Add("Authorization", string.Format(CultureInfo.InvariantCulture, "{0} {1}:{2}", "SharedKey", accountName, sha));

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                BlobProperties blobProperties = new BlobProperties()
                {
                    BlobType = response.Headers["x-ms-blob-type"],
                    CopyStatusDescription = response.Headers["x-ms-copy-status-description"],
                    LastModified = response.Headers["Last-Modified"]
                };

                blobProperties.SetCopyProgress(response.Headers["x-ms-copy-progress"]);
                blobProperties.SetCopyStatus(response.Headers["x-ms-copy-status"]);

                return blobProperties;
            }
        }