/// <summary> /// Aborts the creation of the image and deletes it /// </summary> public void Stop() { CloseAll(); if (OnMessage != null) { EventSenderArgs e = new EventSenderArgs(@"Sending was canceled"); OnMessage(e); } }
/// <summary> /// Starts the thread creating the ISO file /// </summary> void bgSender_DoWork(object sender, DoWorkEventArgs e) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); if (this.UploadHash != "") { long MediumSize = new System.IO.FileInfo(PathToIso).Length; HttpWebRequest httpWebRequest = HttpWebRequest.Create(Settings.UploadLink) as HttpWebRequest; WebHeaderCollection httpHdr = httpWebRequest.Headers; httpHdr.Add("x-cdarcha-mediaid:" + this.UploadId.Replace("-", "").ToLower()); httpHdr.Add("x-cdarcha-checksum:" + this.UploadHash.Replace("-", "").ToLower()); httpHdr.Add("x-cdarcha-mediasize:" + MediumSize.ToString()); httpHdr.Add("x-cdarcha-quickid:" + this.QuickId); httpHdr.Add("x-cdarcha-filetype:iso"); httpHdr.Add("x-cdarcha-mediareadproblem:" + (this.MediumReadProblem ? "1" : "0")); httpHdr.Add("x-cdarcha-forcedupload:" + (this.ForcedUpload ? "1" : "0")); httpWebRequest.Timeout = 9000000; httpWebRequest.Method = "POST"; httpWebRequest.SendChunked = true; httpWebRequest.AllowWriteStreamBuffering = false; httpWebRequest.ContentType = "application/octet-stream"; Stream st = httpWebRequest.GetRequestStream(); try { //Read buffer blocks from source and write them to the ISO file long progress = 0; using (FileStream fs = File.Open(PathToIso, FileMode.Open)) { int bufferSize = (progress + BUFFER > MediumSize) ? Convert.ToInt32(MediumSize - progress) : BUFFER; byte[] buffer = new byte[bufferSize]; while (fs.Read(buffer, 0, bufferSize) > 0) { if (bgSender.CancellationPending) { e.Cancel = true; Stop(); break; } st.Write(buffer, 0, bufferSize); progress += bufferSize; if (OnProgress != null) { //Progress int percent = Convert.ToInt32((progress * 100) / MediumSize); EventSenderArgs eArgs = new EventSenderArgs(progress, percent); OnProgress(eArgs); } } } } catch (Exception ex) { if (OnMessage != null) { EventSenderArgs eArgs = new EventSenderArgs("Error while creating the image: " + ex.Message); OnMessage(eArgs); } } finally { if (OnFinish != null) { EventSenderArgs eArgs = new EventSenderArgs(stopWatch.Elapsed); OnFinish(eArgs); } } st.Close(); HttpWebResponse res = (HttpWebResponse)httpWebRequest.GetResponse(); res.Close(); } }