/// <summary>
 /// Initializes a new instance of the <see cref="CloudBlobClient"/> class.
 /// </summary>
 /// <param name="uploadUrl">The upload URL.</param>
 /// <param name="file">The file to upload.</param>
 public CloudBlobClient(Uri uploadUrl, UserFile file)
 {
     if (file != null)
     {
         this.request            = new RequestGenerator(uploadUrl, file.FileName);
         this.packager           = new DataPacket();
         this.lockingObject      = new object();
         this.cancellationTokens = new CancellationTokenSource();
         this.file    = file;
         this.packets = this.packager.TransformStreamToPackets(file.FileStream).ToList <DataPacket>();
     }
 }
 /// <summary>
 /// Blocks the list write to stream callback.
 /// </summary>
 /// <param name="asynchronousResult">The asynchronous result.</param>
 private void BlockListWriteToStreamCallback(IAsyncResult asynchronousResult)
 {
     if (!this.cancellationTokens.IsCancellationRequested)
     {
         AsyncWebRequestState requestState = (AsyncWebRequestState)asynchronousResult.AsyncState;
         HttpWebRequest       webRequest   = (HttpWebRequest)requestState.WebRequestState;
         Stream requestStream = webRequest.EndGetRequestStream(asynchronousResult);
         var    writer        = XmlWriter.Create(requestStream, new XmlWriterSettings()
         {
             Encoding = Encoding.UTF8
         });
         RequestGenerator.UncommittedBlockBlobList(this.packets.Count()).Save(writer);
         writer.Flush();
         requestStream.Close();
         requestState.WebRequestState = webRequest;
         webRequest.BeginGetResponse(new AsyncCallback(this.BlockListReadHttpResponseCallback), requestState);
     }
 }