Exemple #1
0
        public bool DoRecord(DeviceData data)
        {
            /// throw new NotImplementedException();
            ///

            return true;
        }
Exemple #2
0
		public static void DoDataRecord(DeviceData deviceData)
		{
			// TODO: Record it in the files.
            if (deviceData.OriginData != null && deviceData.OriginData.Length > 0)
            {
                if (deviceData.OriginData == DeviceData.BeginFlag)
                {
                    return;
                }
                else if (deviceData.OriginData == DeviceData.ErrorFlag)
                {
                    RecordManager.WriteDataToLog(deviceData.Device, "Error or No Data Received.", RecordType.Origin);
                    return;
                }
                string originLine = deviceData.OriginData;

                // remove temp by kaikai
                //RecordManager.WriteDataToLog(deviceData.Device, originLine.Trim(), RecordType.Origin);
            }

			string line = RecordManager.PackDeviceData(deviceData);
			
            // remove temp by Kaikai
            //RecordManager.WriteDataToLog(deviceData.Device, line, RecordType.Data);

            // Record into MySQL:)
			if (!RecordManager.mysql.DoRecord(deviceData))
			{
				// TODO: Do log this failure.
                RecordManager.WriteDataToLog(deviceData.Device, "Insert to DB Error", RecordType.Data);
			}
		}
Exemple #3
0
		public bool DoRecord(DeviceData data)
		{
			if (this.conn != null && data.Data != null)
			{
                this.conn.Connect();
				bool ret = this.conn.AddRecordData(data.InsertIntoCommand, data);
                this.conn.Disconnect();
				return ret;
			}
			return false;
		}
Exemple #4
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="data"></param>
		/// <returns></returns>
		private bool OnDataArrival(DeviceData deviceData)
		{
            // Record.
			RecordManager.DoDataRecord(deviceData);
            // For Rescue
            Device device = deviceData.Device;
            if (device != null)
            {
                string deviceKey = device.Id.ToLower();
                Program.DeviceManager.UpdateLastModifyTime(deviceKey, DateTime.Now.Ticks);
                return true;
            }
			return false;
		}
Exemple #5
0
        public static void DoDataRecord(DeviceData deviceData)
        {
            // TODO: Record it in the files.
            if (deviceData.OriginData != null && deviceData.OriginData.Length > 0)
            {
                string originLine = deviceData.OriginData;
                RecordManager.WriteDataToLog(deviceData.Device, originLine.Trim(), RecordType.Origin);
            }
            string line = RecordManager.PackDeviceData(deviceData);
            RecordManager.WriteDataToLog(deviceData.Device, line, RecordType.Data);
            if (analysisToolOpen)
            {
                SendToAnalysisWindow(line);
            }

            if (!RecordManager.mysql.DoRecord(deviceData))
            {
                // TODO: Do log this failure.
            }
        }
Exemple #6
0
		protected bool GetDeviceData(byte[] line, DateTime time, out DeviceData dd)
		{
            dd = default(DeviceData);

            string[] data = null;
            try
            {
                data = this.Search(line, this.lastLine);

                this.lastLine = line;
            }
            catch (Exception e)
            {
                RecordManager.DoSystemEventRecord(this, "Parse data failure: " + e.Message);
                return false;
            }

			if (data == null || data.Length == 0)
			{
				return false;
			}
            dd.Time = time;
            object[] fields = Device.GetFieldsData(data, time, this.fieldsConfig);
			dd = new DeviceData(this, fields);
			dd.InsertIntoCommand = this.insertIntoCommand;

			return true;
		}
Exemple #7
0
 private void PostStartStatus()
 {
     DeviceData dd = new DeviceData(this, null);
     dd.OriginData = DeviceData.BeginFlag;
     this.SynchronizationContext.Post(this.DataReceived, dd);
 }
Exemple #8
0
        internal void RecordData(byte[] line)
        {
            DeviceData dd;
            if (!this.GetDeviceData(line, this.currentRecordTime, out dd))
            {
                dd = new DeviceData(this, null);
                dd.OriginData = DeviceData.ErrorFlag;
                this.SynchronizationContext.Post(this.DataReceived, dd);
                return;
            }

            // Post to Main thread to record.
            dd.OriginData = Encoding.ASCII.GetString(line);
            this.SynchronizationContext.Post(this.DataReceived, dd);
        }
Exemple #9
0
        private void PostStartStatus()
        {
            DeviceData dd = new DeviceData(this, null);

            this.SynchronizationContext.Post(this.DataReceived, dd);
        }
Exemple #10
0
        private bool GetDeviceData(byte[] line, DateTime time, out DeviceData dd)
        {
            if (time == default(DateTime))
            {
                time = DateTime.Now;
            }
            string[] data = null;
            try
            {
                data = this.dataParser.Search(line, lastLine);
                this.lastLine = line;
            }
            catch (Exception e)
            {
                RecordManager.DoSystemEventRecord(this, "Parse data failure");
            }

            dd = default(DeviceData);
            if (data == null || data.Length == 0)
            {
                return false;
            }
            dd.Time = time;
            object[] fields = Device.GetFieldsData(data, time, this.fieldsConfig);
            dd = new DeviceData(this, fields);
            dd.InsertIntoCommand = this.insertIntoCommand;
            // deviceData.FieldsConfig = this.fieldsConfig;
            return true;
        }
Exemple #11
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;
 }
Exemple #12
0
 private bool GetDeviceData(string[] data, DateTime time, out DeviceData deviceData)
 {
     deviceData = default(DeviceData);
     if (data == null || data.Length == 0)
     {
         return false;
     }
     deviceData.Time = time;
     double value = 0.0;
     if (double.TryParse(data[1], out value))
     {
         data[1] = string.Format("{0:f1}", value * this.factor1);
     }
     else
     {
         data[1] = string.Format("{0:f1}", this.factor1);
     }
     
     object[] fields = Device.GetFieldsData(data, time, this.fieldsConfig);
     deviceData = new DeviceData(this, fields);
     deviceData.InsertIntoCommand = this.insertIntoCommand;
     //deviceData.FieldsConfig = this.fieldsConfig;
     return true;
 }
Exemple #13
0
 public bool DoRecord(DeviceData data)
 {
     if (data.Data != null)
     {
         bool ret = this.conn.AddRecordData(data.InsertIntoCommand, data.Time, data.Data);
         return ret;
     }
     return false;
 }
Exemple #14
0
 public bool DoRecord(DeviceData data)
 {
     /// throw new NotImplementedException();
     ///
     return(true);
 }
Exemple #15
0
        private void Record(string str)
        {
            DateTime time = DateTime.Now;

            object[] data = new object[]{ time, this.SID, str};

            DeviceData dd = new DeviceData(this, data);
            dd.InsertIntoCommand = this.insertIntoCommand;

            this.SynchronizationContext.Post(this.DataReceived, dd);
        }
Exemple #16
0
		public bool AddRecordData(string commandText, DeviceData data)
		{
            try
            {
                if (this.cmd != null)
                {
                    this.cmd.CommandText = commandText;
                    var items = data.Data;
                    for (int i = 0; i < items.Length; ++i)
                    {
                        string at = string.Format("@{0}", i + 1);
                        this.cmd.Parameters.AddWithValue(at, items[i]);
                    }
                    
                    int num = this.cmd.ExecuteNonQuery();
                    if (num != 1)
                    {
                        this.cmd.Parameters.Clear();
                        return false;
                    }
                    // If exception, the params would NOT clear.
                    // cmd.Parameters.Clear();

                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                RecordManager.DoSystemEventRecord(data.Device, string.Format("{0} => {1}", commandText, e.Message), RecordType.Error);
                //this.RetryConnection(e);
                cmd.Parameters.Clear();
                return false;
            }
            finally
            {
                if (this.cmd != null)
                {
                    this.cmd.Parameters.Clear();
                }
            }
			return true;
		}
Exemple #17
0
 private DeviceData ParseNuclideData(NuclideData nd, DateTime time)
 {
     object[] data = new object[]{
         time, nd.Name, nd.Activity, nd.Indication, nd.DoseRate, nd.Channel, nd.Energy
     };
     DeviceData dd = new DeviceData(this, data);
     dd.InsertIntoCommand = this.insertIntoCommand2;
     return dd;
 }
Exemple #18
0
        private void OnDataTimer(object sender, EventArgs e)
        {
            int[] handles = this.results.Select((r) => r.HandleServer).ToArray();
            OPCItemState[] states;
            if (this.group.SyncRead(OPCDATASOURCE.OPC_DS_DEVICE, handles, out states))
            {
                if (this.start)
                {
                    // Start
                    DateTime time;
                    if (this.OnRightTime(out time))
                    {
                        if (time == this.lastRecordTime)
                        {
                            return;
                        }

                        this.lastRecordTime = time;

                        if (this.beginTime == default(DateTime))
                        {
                            this.beginTime = time;
                        }

                        object[] values = states.Select((s) => s.DataValue).ToArray();
                        string valueLine = string.Join(", ", values);
                        RecordManager.DoSystemEventRecord(this, valueLine, RecordType.Origin, true);

                        this.latestTime = time;
                        string status = values[6].ToString();
                        RecordManager.DoSystemEventRecord(this, string.Format("STATUS:{0}", status), RecordType.Event, true);
                        if (this.stopping && status == "0")
                        {
                            this.endTime = time;
                            this.stopping = false;
                            this.start = false;
                            RecordManager.DoSystemEventRecord(this, string.Format("Stopped SID={0}", this.Sid), RecordType.Event, true);
                            this.PutDeviceFile(false);
                        }
                        byte statusb = (status == "1") ? (byte)1 : (byte)0;
                        object[] data = new object[] { time, this.Sid, this.beginTime, this.endTime, values[3], values[4], values[5], statusb, 0, 0, 0 };
                        DeviceData deviceData = new DeviceData(this, data);
                        deviceData.InsertIntoCommand = this.insertSQL;
                        RecordManager.DoDataRecord(deviceData);

                        // HERE
                        if (this.start)
                        {
                            this.MarkEndTime(this.endTime);
                        }
                    }
                }
                else
                {
                    // Not start
                    object[] values = states.Select((s) => s.DataValue).ToArray();
                    string status = values[6].ToString();
                    if (status == "0")
                    {
                        this.start = false;
                    }
                    else if (status == "1")
                    {
                        this.start = true;
                    }
                }
            }
            else
            {
                RecordManager.DoSystemEventRecord(this, "Read Faild", RecordType.Event, true);
            }
        }
Exemple #19
0
 private static string PackDeviceData(DeviceData deviceData)
 {
     if (deviceData.Data == null)
     {
         return "<DeviceData::Data Is Null>";
     }
     StringBuilder sb = new StringBuilder();
     foreach (object o in deviceData.Data)
     {
         if (o != null)
         {
             sb.Append(o.ToString()).Append(" ");
         }
     }
     return sb.ToString();
 }
Exemple #20
0
 private void MarkEndTime(DateTime endTime)
 {
     DeviceData deviceData = new DeviceData(this, new object[]{});
     deviceData.InsertIntoCommand = string.Format("update {0} set EndTime='{1}' where time='{2}'", this.tableName, endTime, endTime);
     RecordManager.DoDataRecord(deviceData);
 }
Exemple #21
0
        internal void RecordData(byte[] line)
        {
            // Defect: HPIC need check the right time here.
            // if ActionInterval == 0, the time trigger not depends send-time.
            DateTime rightTime = default(DateTime);
            if (!this.recordTimePolicy.NowAtRightTime(out rightTime) ||
                this.currentRecordTime == rightTime)
            {
                return;
            }

            this.currentRecordTime = rightTime;

            DeviceData dd;
            if (!this.GetDeviceData(line, this.currentRecordTime, out dd))
            {
                dd = new DeviceData(this, null);
                dd.OriginData = DeviceData.ErrorFlag;
                this.SynchronizationContext.Post(this.DataReceived, dd);
                return;
            }

            // Post to Main thread to record.
            dd.OriginData = Encoding.ASCII.GetString(line);
            this.SynchronizationContext.Post(this.DataReceived, dd);
        }