Пример #1
0
        public static void FlushToArchiveFormat(String xmlPath, String resultXmlPath, List <String> ResultsDAT, DateTime absoluteStart)
        {
            XElement    XML     = null;
            List <byte> UPList  = new List <byte>();
            List <byte> FHRList = new List <byte>();

            XML = XMLHelper.LoadTracingsFromXML(xmlPath, UPList, FHRList);
            FlushToArchiveFormat(resultXmlPath, absoluteStart, ResultsDAT, UPList, FHRList);
        }
Пример #2
0
        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();
        }