private void UploadHistoryData(string qn, string eno, string beginTime, string endTime, string sid, string polId) { DateTime f = DeviceTime.Parse(beginTime); DateTime t = DeviceTime.Parse(endTime); if (f >= t) { return; } string deviceKey = Settings.Instance.GetDeviceKeyByEno(eno); string deviceKeyLower = deviceKey.ToLower(); if (deviceKey.Equals("Scada.NaIDevice", StringComparison.OrdinalIgnoreCase)) { // NaIDevice ... Gose here. // 分包 DateTime dt = f; while (dt <= t) { string content = DBDataSource.Instance.GetNaIDeviceData(dt); if (!string.IsNullOrEmpty(content)) { List <DataPacket> pks = null; try { pks = builder.GetDataPackets(deviceKey, dt, content, true); } catch (Exception e) { this.agent.OnHandleHistoryData(deviceKey, e.Message, true); } if (pks != null) { foreach (var p in pks) { this.agent.SendHistoryDataPacket(p); } } } dt = dt.AddSeconds(60 * 5); } } else { List <Dictionary <string, object> > data = new List <Dictionary <string, object> >(); ReadResult r = ReadResult.NoDataFound; string errorMessage = string.Empty; using (var conn = DBDataSource.Instance.CreateMySqlConnection()) { try { conn.Open(); var cmd = conn.CreateCommand(); r = DBDataSource.GetData(cmd, deviceKey, f, t, sid, polId, data, out errorMessage); } catch (Exception e) { string line = string.Format("HD Error: {0} [{1}: {2} ~ {3}]", e.Message, deviceKey, f, t); this.agent.OnHandleHistoryData(deviceKey, line, true); return; } } if (r == ReadResult.ReadOK) { if (data.Count == 0) { return; } foreach (var item in data) { DataPacket p = null; // By different device. if (deviceKey.Equals("Scada.mds", StringComparison.OrdinalIgnoreCase) || deviceKey.Equals("Scada.ais", StringComparison.OrdinalIgnoreCase)) { p = builder.GetFlowDataPacket(deviceKey, item, false); } else if (deviceKey.Equals("Scada.Shelter", StringComparison.OrdinalIgnoreCase)) { p = builder.GetShelterPacket(deviceKey, item); } else { p = builder.GetDataPacket(deviceKey, item); } this.agent.SendHistoryDataPacket(p); } } else { string line = string.Format("HD Error: {0} - {1} [{2}: {3} ~ {4}]", r.ToString(), errorMessage, deviceKey, f, t); this.agent.OnHandleHistoryData(deviceKey, line, true); } } }
/// <summary> /// /// </summary> /// <param name="time"></param> /// <param name="deviceKey"></param> private void SendNonFileDataPackets(DateTime time, string deviceKey) { this.data.Clear(); string errorMessage = string.Empty; var r = DBDataSource.GetData(this.MySqlCommand, deviceKey, time, default(DateTime), null, null, this.data, out errorMessage); if (r == ReadResult.ReadOK) { if (this.data.Count > 0) { DataPacket p = null; if (Case(deviceKey, "Scada.MDS") || Case(deviceKey, "Scada.AIS")) { this.SendFlowDataPackets(deviceKey, this.data[0]); } else if (Case(deviceKey, "scada.shelter")) { this.SendShelterDataPackets(deviceKey, this.data[0]); } else { // 其他数据 if (deviceKey == "scada.hpic" && this.InHpicException) { this.InHpicException = false; DataPacket packet = this.builder.GetExceptionNotifyPacket(deviceKey, false); this.agent.SendExceptionNotify(packet); } p = builder.GetDataPacket(deviceKey, this.data[0], true); if (this.agent.SendDataPacket(p)) { string msg = string.Format("RD: {0}", p.ToString()); Log.GetLogFile(deviceKey).Log(msg); this.UpdateSendDataRecord(deviceKey, false); } if (this.countryCenterAgent != null && this.agent.SendDataDirectlyStarted) { this.countryCenterAgent.SendDataPacket(p); } } } else { string line = string.Format("RD Error: count={0} [{1}: {2}]", this.data.Count, deviceKey, time); Log.GetLogFile(deviceKey).Log(line); } } else { // 发送异常通知 if (r == ReadResult.NoDataFound && deviceKey == "scada.hpic") { if (!this.InHpicException) { this.InHpicException = true; DataPacket packet = this.builder.GetExceptionNotifyPacket(deviceKey, true); this.agent.SendExceptionNotify(packet); } } string line = string.Format("RD Error: {0} - {1} [{2}: {3}]", r.ToString(), errorMessage, deviceKey, time); Log.GetLogFile(deviceKey).Log(line); } }