// resolve resumable task file, continue in proper position
 private void ResumeDownloadInPossible(HeadObjectResult result, string localFile)
 {
     this.resumableInfo = DownloadResumableInfo.LoadFromResumableFile(resumableTaskFile);
     if (this.resumableInfo != null)
     {
         if ((result.crc64ecma == null || result.crc64ecma == resumableInfo.crc64ecma) &&
             this.resumableInfo.eTag == result.eTag &&
             this.resumableInfo.lastModified == result.lastModified &&
             this.resumableInfo.contentLength == result.size)
         {
             // load parts downloaded
             if (this.resumableInfo.slicesDownloaded != null)
             {
                 // process downloaded parts
                 foreach (DownloadSliceStruct downloadedSlice in resumableInfo.slicesDownloaded)
                 {
                     // remove from current queue
                     DownloadSliceStruct calculatedSlice;
                     bool ret = this.sliceList.TryGetValue(downloadedSlice.partNumber, out calculatedSlice);
                     if (!ret)
                     {
                         // resumable file broken
                         break;
                     }
                     if (calculatedSlice.sliceStart == downloadedSlice.sliceStart &&
                         calculatedSlice.sliceEnd == downloadedSlice.sliceEnd)
                     {
                         if (this.sliceToRemove == null)
                         {
                             this.sliceToRemove = new HashSet <int>();
                         }
                         this.sliceToRemove.Add(downloadedSlice.partNumber);
                     }
                     // add to merging list
                     string tmpFileName = localDir + "." + localFileName + ".cosresumable." + downloadedSlice.partNumber;
                     this.tmpFilePaths.Add(tmpFileName);
                 }
             }
             else
             {
                 this.resumableInfo.slicesDownloaded = new List <DownloadSliceStruct>();
             }
         }
     }
     else
     {
         this.resumableInfo = new DownloadResumableInfo();
         this.resumableInfo.contentLength    = result.size;
         this.resumableInfo.crc64ecma        = result.crc64ecma;
         this.resumableInfo.eTag             = result.eTag;
         this.resumableInfo.lastModified     = result.lastModified;
         this.resumableInfo.slicesDownloaded = new List <DownloadSliceStruct>();
         resumableInfo.Persist(resumableTaskFile);
     }
 }
 public static DownloadResumableInfo LoadFromResumableFile(string taskFile)
 {
     try
     {
         using (FileStream stream = File.OpenRead(taskFile))
         {
             DownloadResumableInfo resumableInfo = XmlParse.Deserialize <DownloadResumableInfo>(stream);
             return(resumableInfo);
         }
     }
     catch (System.Exception)
     {
         return(null);
     }
 }