public void SendStartAck(string GateWayID, string DeviceID) { cls_StartAck sc = new cls_StartAck(); sc.Cmd_Result = "OK"; sc.Trace_ID = DateTime.Now.ToString("yyyyMMddHHmmssfff"); string json_msg = JsonConvert.SerializeObject(sc, Newtonsoft.Json.Formatting.Indented); xmlMessage SendOutMsg = new xmlMessage(); SendOutMsg.LineID = GateWayID; SendOutMsg.DeviceID = DeviceID; SendOutMsg.MQTTTopic = "Collect_Start_Ack"; SendOutMsg.MQTTPayload = json_msg; SendMQTTData(SendOutMsg); }
public void StartAck(xmlMessage InputData) { // Parse Mqtt Topic string[] Topic = InputData.MQTTTopic.Split('/'); // /IEW/GateWay/Device/Cmd/Start/Ack string GateWayID = Topic[2].ToString(); string DeviceID = Topic[3].ToString(); cls_StartAck sc = new cls_StartAck(); sc = JsonConvert.DeserializeObject <cls_StartAck>(InputData.MQTTPayload.ToString()); if (ObjectManager.MonitorManager != null) { //cls_Monitor_Gateway_Info gw = ObjectManager.MonitorManager.monitor_list.Where(p => p.gateway_id == GateWayID).FirstOrDefault(); //if (gw != null) //{ /* * cls_Monitor_Device_Info dv = gw.device_list.Where(p => p.device_id == DeviceID).FirstOrDefault(); * if (dv != null) * { * if(sc.Cmd_Result == "OK") * { * gw.gateway_status = "Ready"; * gw.hb_status = "Ready"; * gw.hb_report_time = DateTime.ParseExact(sc.Trace_ID, GlobalVaraible.DATETIME_FORMAT, CultureInfo.InvariantCulture); * dv.device_status = "Ready"; * dv.hb_status = "Ready"; * dv.hb_report_time = DateTime.ParseExact(sc.Trace_ID, "yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); * * //Send message to notify IoTClient for receiving Gateway/Device configuration data * //SendCmdConfig(GateWayID, DeviceID); * } * else * { * gw.gateway_status = "Down"; * gw.hb_status = "Down"; * gw.hb_report_time = DateTime.ParseExact(sc.Trace_ID, "yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); * dv.device_status = "Down"; * dv.hb_status = "Down"; * dv.hb_report_time = DateTime.ParseExact(sc.Trace_ID, "yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); * } * } */ cls_Monitor_Device_Info mdv = ObjectManager.MonitorManager.device_list.Where(o => o.gateway_id == GateWayID && o.device_id == DeviceID).FirstOrDefault(); if (mdv != null) { if (sc.Cmd_Result == "OK") { mdv.device_status = "Ready"; mdv.hb_status = "Ready"; mdv.hb_report_time = DateTime.ParseExact(sc.Trace_ID, "yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); //Send message to notify IoTClient for receiving Gateway/Device configuration data SendCmdConfig(GateWayID, DeviceID); } else { mdv.device_status = "Down"; mdv.hb_status = "Down"; mdv.hb_report_time = DateTime.ParseExact(sc.Trace_ID, "yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); } } //Raise event to notify Online Monitor form to refresh status this.ObjectManager.OnStartAckEventCall(null); //} } }