Пример #1
0
        private DeviceData ParseN42File(NuclideDataSet s, DateTime time)
        {
            object[] data = new object[] { time,
                                           time.AddMinutes(-5), time, s.Coefficients,
                                           s.ChannelData, s.DoseRate, s.Temperature, s.HighVoltage,
                                           s.CalibrationNuclideFound,
                                           s.ReferencePeakEnergyFromPosition };
            DeviceData dd = new DeviceData(this, data);

            dd.InsertIntoCommand = this.insertIntoCommand;
            return(dd);
        }
Пример #2
0
        private void Record(NuclideDataSet set, DateTime now)
        {
            DateTime time = DateTime.Parse(set.EndTime);
            // double minutesAdjust = this.minuteAdjust / 5 * 5 - 5;
            // time = time.AddMinutes(-minutesAdjust);

            var dd = this.ParseN42File(set, time);

            this.SynchronizationContext.Post(this.DataReceived, dd);
            foreach (var nd in set.sets)
            {
                if (nd.Indication == "100")
                {
                    var dd2 = this.ParseNuclideData(nd, time);
                    this.SynchronizationContext.Post(this.DataReceived, dd2);
                }
            }
        }
Пример #3
0
        // TODO: CalibrationNuclideFound and ReferencePeakEnergyFromPosition
        private NuclideDataSet ParseData(XmlDocument doc, XmlNamespaceManager nsmgr)
        {
            //
            string st = doc.Value("//a:Spectrum/a:StartTime", nsmgr);
            // Basicly, we use the EndTime.
            string et = doc.Value("//s:EndTime", nsmgr);


            string co = doc.Value("//a:Calibration[@Type='Energy']//a:Coefficients", nsmgr);

            if (string.IsNullOrEmpty(co))
            {
                co = doc.Value("//a:Coefficients", nsmgr);
            }

            string cd = doc.Value("//a:ChannelData", nsmgr);

            string dr = doc.Value("//a:DoseRate", nsmgr);

            if (dr != null && dr.Length > 0)
            {
                double v;
                if (double.TryParse(dr, out v))
                {
                    dr = (v * 1000).ToString();
                }
                else
                {
                    dr = "0.0 (ERR)";
                }
            }
            string tp = doc.Value("//s:Temperature", nsmgr);
            string hv = doc.Value("//s:HighVoltage", nsmgr);

            // 参考核素状态
            string ns = doc.Value("//s:CalibrationNuclideFound", nsmgr);
            // 参考核素能量
            string ne = doc.Value("//s:ReferencePeakEnergyFromPosition", nsmgr);

            NuclideDataSet set = new NuclideDataSet();

            set.StartTime                       = st;
            set.EndTime                         = et;
            set.Coefficients                    = co;
            set.ChannelData                     = cd;
            set.DoseRate                        = dr;
            set.Temperature                     = tp;
            set.HighVoltage                     = hv;
            set.CalibrationNuclideFound         = (bool)(ns != "false");
            set.ReferencePeakEnergyFromPosition = ne;

            XmlNodeList list = doc.SelectNodes("//a:Nuclide", nsmgr);

            foreach (XmlNode n in list)
            {
                string nn = n.Value("a:NuclideName", nsmgr);

                string ni = n.Value("a:NuclideIDConfidenceIndication", nsmgr);

                string na = n.Value("a:NuclideActivity", nsmgr);

                string nd = n.Value("s:DoseRate", nsmgr);
                if (nd != null && nd.Length > 0)
                {
                    double v;
                    if (double.TryParse(nd, out v))
                    {
                        nd = (v * 1000).ToString();
                    }
                    else
                    {
                        nd = "0.0 (ERR)";
                    }
                }


                string ch = string.Empty;
                string en = string.Empty;

                var peak = n.SelectSingleNode("s:Peak", nsmgr);
                if (peak != null)
                {
                    foreach (XmlAttribute attr in peak.Attributes)
                    {
                        string attrName = attr.Name.ToLower();
                        if (attrName == "channel")
                        {
                            ch = attr.Value;
                        }
                        else if (attrName == "energy")
                        {
                            en = attr.Value;
                        }
                    }
                }

                NuclideData data = new NuclideData()
                {
                    Name    = nn, Activity = na, Indication = ni, DoseRate = nd,
                    Channel = ch, Energy = en
                };
                set.AddNuclideData(data);
            }

            return(set);
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="o"></param>
        private void TimerCallback(object o)
        {
            // The temp file name is fixed.
            DateTime now      = DateTime.Now;
            string   tempFile = this.DeviceConfigPath + "\\temp_download_file.xml";
            string   filePath = string.Empty;

            if (this.IsVirtual)
            {
                filePath = this.DeviceConfigPath + "/sara0231_2012-09-01T03_50_00Z-5min.n42";

                File.Copy(filePath, tempFile, true);
            }
            else
            {
                // Start download ...
                string fileName1 = GetFileNameOnDevice(now);
                // 判断NaI谱文件是否已经成功下载
                if (fileName1 == LastDownLoadFileName)
                {
                    return;
                }

                string fileName2 = GetFileName(now);
                string datePath  = LogPath.GetDeviceLogFilePath(this.Id, now) + "\\" + now.Day.ToString();
                this.DoFolderPolicy(datePath);

                if (!Directory.Exists(datePath))
                {
                    Directory.CreateDirectory(datePath);
                }
                filePath = datePath + "\\" + fileName2;
                if (File.Exists(filePath))
                {
                    return;
                }

                // Download the file.
                string address = this.addr + fileName1;

                using (WebClient client = new WebClient())
                {
                    try
                    {
                        client.Credentials = new NetworkCredential("root", "root");
                        // DO NOT USE the FOLLOWING LINE
                        // client.UseDefaultCredentials = true;
                        if (File.Exists(tempFile))
                        {
                            File.Delete(tempFile);
                        }
                        client.DownloadFile(address, tempFile);
                    }
                    catch (Exception e)
                    {
                        RecordManager.DoSystemEventRecord(this, string.Format("{0} Try to download {1}: Failed.", now, address));
                        RecordManager.DoSystemEventRecord(this, e.Message);

                        return;
                    }
                }

                // 下载成功之后记录,防止多次下载
                LastDownLoadFileName = fileName1;
            }

            Thread.Sleep(1000);
            if (File.Exists(tempFile))
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(tempFile);

                    // XmlElement root = doc.DocumentElement;
                    var nsmgr = new XmlNamespaceManager(doc.NameTable);
                    nsmgr.AddNamespace("a", "http://physics.nist.gov/Divisions/Div846/Gp4/ANSIN4242/2005/ANSIN4242");
                    nsmgr.AddNamespace("s", "http://www.technidata.com/ENVINET/SARA");
                    nsmgr.AddNamespace("e", "http://www.technidata.com/ENVINET");

                    NuclideDataSet set = this.ParseData(doc, nsmgr);
                    this.Record(set, now);

                    File.Move(tempFile, filePath);
                }
                catch (IOException e)
                {
                    RecordManager.DoSystemEventRecord(this, e.Message);
                }
                catch (Exception e)
                {
                    RecordManager.DoSystemEventRecord(this, e.Message);
                }
                finally
                {
                    // TODO: Gzip the file, put it into the Date-folder, then delete this xml file.
                }
            }
        }
Пример #5
0
		// TODO: CalibrationNuclideFound and ReferencePeakEnergyFromPosition
        private NuclideDataSet ParseData(XmlDocument doc, XmlNamespaceManager nsmgr)
        {
            // 
            string st = doc.Value("//a:Spectrum/a:StartTime", nsmgr);
            // Basicly, we use the EndTime.
            string et = doc.Value("//s:EndTime", nsmgr);

            string co = doc.Value("//a:Coefficients", nsmgr);

            string cd = doc.Value("//a:ChannelData", nsmgr);

            string dr = doc.Value("//a:DoseRate", nsmgr);
            if (dr != null && dr.Length > 0)
            {
                double v;
                if (double.TryParse(dr, out v))
                {
                    dr = (v * 1000).ToString();
                }
                else
                {
                    dr = "0.0 (ERR)";
                }
            }
            string tp = doc.Value("//s:Temperature", nsmgr);
            string hv = doc.Value("//s:HighVoltage", nsmgr);

            // 参考核素状态
            string ns = doc.Value("//s:CalibrationNuclideFound", nsmgr);
            // 参考核素能量
            string ne = doc.Value("//s:ReferencePeakEnergyFromPosition", nsmgr);

            NuclideDataSet set = new NuclideDataSet();
            set.StartTime = st;
            set.EndTime = et;
            set.Coefficients = co;
            set.ChannelData = cd;
            set.DoseRate = dr;
            set.Temperature = tp;
            set.HighVoltage = hv;
            set.CalibrationNuclideFound = (bool)(ns != "false");
            set.ReferencePeakEnergyFromPosition = ne;

            XmlNodeList list = doc.SelectNodes("//a:Nuclide", nsmgr);

            foreach (XmlNode n in list)
            {
                string nn = n.Value("a:NuclideName", nsmgr);

                string ni = n.Value("a:NuclideIDConfidenceIndication", nsmgr);

                string na = n.Value("a:NuclideActivity", nsmgr);

                string nd = n.Value("s:DoseRate", nsmgr);
                if (nd != null && nd.Length > 0)
                {
                    double v;
                    if (double.TryParse(nd, out v))
                    {
                        nd = (v * 1000).ToString();
                    }
                    else
                    {
                        nd = "0.0 (ERR)";
                    }
                }


                string ch = string.Empty;
                string en = string.Empty;

                var peak = n.SelectSingleNode("s:Peak", nsmgr);
                if (peak != null)
                {
                    foreach (XmlAttribute attr in peak.Attributes)
                    {
                        string attrName = attr.Name.ToLower();
                        if (attrName == "channel")
                        {
                            ch = attr.Value;
                        }
                        else if (attrName == "energy")
                        {
                            en = attr.Value;
                        }
                    }
                }

                NuclideData data = new NuclideData() { 
                    Name = nn, Activity = na, Indication = ni, DoseRate = nd,
                    Channel = ch, Energy = en
                };
                set.AddNuclideData(data);
            }

            return set;
        }
Пример #6
0
 private DeviceData ParseN42File(NuclideDataSet s, DateTime time)
 {
     object[] data = new object[]{ time,
         time.AddMinutes(-5) , time, s.Coefficients, 
         s.ChannelData, s.DoseRate, s.Temperature, s.HighVoltage, 
         s.CalibrationNuclideFound, 
         s.ReferencePeakEnergyFromPosition
     };
     DeviceData dd = new DeviceData(this, data);
     dd.InsertIntoCommand = this.insertIntoCommand;
     return dd;
 }
Пример #7
0
        private void Record(NuclideDataSet set, DateTime now)
        {
            DateTime time = DateTime.Parse(set.EndTime);
            // double minutesAdjust = this.minuteAdjust / 5 * 5 - 5;
            // time = time.AddMinutes(-minutesAdjust);

            var dd = this.ParseN42File(set, time);
            this.SynchronizationContext.Post(this.DataReceived, dd);
            foreach (var nd in set.sets)
            {
                if (nd.Indication == "100")
                {
                    var dd2 = this.ParseNuclideData(nd, time);
                    this.SynchronizationContext.Post(this.DataReceived, dd2);
                }
            }
        }