void Worker_DoWork(object sender, DoWorkEventArgs e) { XElement XML = null; List <byte> UPList = new List <byte>(); List <byte> FHRList = new List <byte>(); XML = XMLHelper.LoadTracingsFromXML(textBoxInPath.Text, UPList, FHRList); int nShift = 0; DateTime time = DateTime.Now.AddSeconds(-(int)numericUpDownSliceInterval.Value); AbsoluteStart = time; var token = PatternsAddOnTestClient.Instance.CurrentToken; int nSlice = checkBoxSliceData.Checked ? (int)numericUpDownSliceInterval.Value : UPList.Count; while (nShift < UPList.Count) { var sublistSize = checkBoxSliceData.Checked ? Math.Min(UPList.Count - nShift, nSlice) : UPList.Count; var upSubList = CommonHelper.Sublist(UPList, nShift, sublistSize); var fhrSubList = CommonHelper.Sublist(FHRList, nShift * 4, Math.Min(sublistSize * 4, FHRList.Count - (nShift * 4))); LastTracingTimeStamp = time.AddSeconds(nShift); var dataStr = XMLHelper.PrepareXML(upSubList, fhrSubList, time.AddSeconds(nShift), LastDetected); var client = new RestClient(PatternsAddOnTestClient.Instance.CurrentHost); var request = new RestRequest("Sessions/" + token, Method.POST) { Timeout = 6000, RequestFormat = DataFormat.Xml }; request.AddParameter("text/xml", dataStr, ParameterType.RequestBody); var response = client.Execute(request); System.Diagnostics.Trace.WriteLine("Response code: " + response.ResponseStatus.ToString()); Process proc = Process.GetCurrentProcess(); var mem = proc.PrivateMemorySize64; Trace.WriteLine("Memory usage: " + mem.ToString()); if (response.StatusCode != System.Net.HttpStatusCode.Accepted && response.StatusCode != System.Net.HttpStatusCode.MethodNotAllowed) { break; } var content = response.Content; // raw content as string if (content.Equals(String.Empty)) { return; } var contentElement = XElement.Parse(content); var tokenIds = from c in contentElement.Elements() select c; var tokenId = tokenIds.Count() > 1 ? tokenIds.ElementAt(1).Value : String.Empty; if (tokenId.Equals(String.Empty)) { return; } nShift += nSlice; if (nShift >= UPList.Count) { break; } if (checkBoxSliceData.Checked) { int sleep = 1500; if (checkBoxRTInterval.Checked) { sleep = (int)numericUpDownSliceInterval.Value * 1000; } else { sleep = numericUpDownDelay.Visible ? (int)numericUpDownDelay.Value : 1500; } Thread.Sleep(sleep); } else { Thread.Sleep(1500); } } GC.Collect(); }
void ResultsWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { Trace.WriteLine("Results received."); if (!ResultTimer.Enabled) { MessageBox.Show("Work complete"); buttonRun.Text = "Run"; if (checkBoxFlush.Checked) { if (textBoxResult.Text.ToLower().IndexOf(".dat") > 0) { using (StreamWriter sw = new StreamWriter(textBoxResult.Text)) { foreach (var item in ResultsDAT) { sw.WriteLine(item); } } } else { var xml = (from c in ResultsXML.Elements() select c); var xmlArr = xml.ToArray(); ResultsXML.Elements().Remove(); ResultsXML.Add(xmlArr.Distinct()); XElement XML = XElement.Load(textBoxInPath.Text); if (XML.Elements("fhr-sample").Count() > 0 && XML.Elements("up-sample").Count() > 0) { var FHRElems = from b in XML.Descendants("fhr-sample") select b; var UPElems = from c in XML.Descendants("up-sample") select c; ResultsXML.Add(FHRElems); ResultsXML.Add(UPElems); } else if (XML.Elements("visit").Count() > 0) { List <byte> FHRList = new List <byte>(); List <byte> UPList = new List <byte>(); XMLHelper.LoadRawTracings(UPList, FHRList, XML); foreach (var item in UPList) { ResultsXML.Add(new XElement("up-sample", new XAttribute("value", item))); } foreach (var item in FHRList) { ResultsXML.Add(new XElement("fhr-sample", new XAttribute("value", item))); } } ResultsXML.Save(textBoxResult.Text); } if (checkBoxArcive.Enabled && checkBoxArcive.Checked) { XMLWriter.FlushToArchiveFormat(textBoxInPath.Text, textBoxResult.Text, ResultsDAT, AbsoluteStart); } } Running = false; } }