public void Enqueue(Message message) { lock (queueLock) { //logger.Debug(m => m("Queue {0} have {1} messages.", queueName, queue.Count)); queue.Enqueue(message); } }
private void Send(Message message) { string xml = MessageParser.Serialize(message); byte[] bytes = Monitor.Common.PacketHelper.Encode(xml); int bytesSend = NetworkService.GetHandler(Name).Send(bytes); logger.Debug(m => m("Send {0} bytes", bytesSend)); }
public static Message CreateAuthenticationMessage(string projectId, string gatewayId, string sequence) { Message msg = new Message(); msg.common.project_id = projectId; msg.common.gateway_id = gatewayId; msg.common.type = MessageType.MESSAGE_TYPE_AUTHENTICATION; msg.id_validate = new ValidationSection(); msg.id_validate.operation = MessageType.MESSAGE_TYPE_AUTHENTICATION; msg.id_validate.md5 = EncryptHelper.GetSequenceMd5(sequence); return msg; }
public static Message CreateHeartbeatMessage(string projectId, string gatewayId) { Message msg = new Message(); msg.common.project_id = projectId; msg.common.gateway_id = gatewayId; msg.common.type = MessageType.MESSAGE_TYPE_HEART_BEAT; msg.id_validate = new ValidationSection(); msg.heart_beat = new HeartBeatSection(); msg.id_validate.operation = MessageType.MESSAGE_TYPE_HEART_BEAT; return msg; }
public static string Serialize(Message msg) { System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(Message)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); // Add lib namespace with empty prefix ns.Add("", ""); Encoding ec = SystemInternalSetting.Encoding; string xml = Serialize(x, ec, ns, false, msg); //ISSUE: remove first character return xml.Substring(1); }
public static Message CreateReportMessage(string projectId, string gatewayId) { Message msg = new Message(); msg.common.project_id = projectId; msg.common.gateway_id = gatewayId; msg.common.type = MessageType.MESSAGE_TYPE_REPORT; if (msg.data == null) msg.data = new DataSection(); msg.data.operation = MessageType.MESSAGE_TYPE_REPORT; msg.data.sequence = "Z1"; msg.data.time = String.Format("{0:yyyyMMddHHmmss}", DateTime.Now); List<Meter> meters = new List<Meter>(); for (int i = 1; i < 4; i++) { Meter m = new Meter(); m.id = "X1"; List<Function> functions = new List<Function>(); for (int j = 0; j < 6; j++) { Function f = new Function(); f.id = "Y1"; f.coding = "Indication" + j.ToString(); f.sample_time = String.Format("{0:yyyyMMddHHmmss}", DateTime.Now); f.value = "s"; functions.Add(f); } m.function = functions.ToArray<Function>(); meters.Add(m); } msg.data.meter = meters.ToArray<Meter>(); return msg; }
private void Report(DataSet ds) { for (int row = 0; row < ds.Tables[0].Rows.Count; row++) { Message msg = new Message(); msg.common.project_id = projectId; msg.common.gateway_id = gatewayId; msg.common.type = MessageType.MESSAGE_TYPE_REPORT; if (msg.data == null) msg.data = new DataSection(); msg.data.operation = MessageType.MESSAGE_TYPE_REPORT; msg.data.sequence = ds.Tables[0].Rows[row]["seq"].ToString(); msg.data.time = ds.Tables[0].Rows[row]["time"].ToString(); List<Meter> meters = new List<Meter>(); Meter m = new Meter(); m.id = ds.Tables[0].Rows[row]["meter"].ToString(); List<Function> functions = new List<Function>(); Function f1 = new Function(); f1.id = ds.Tables[0].Rows[row]["function_Battery_tem"].ToString(); f1.coding = "192"; f1.sample_time = ds.Tables[0].Rows[row]["sample_time"].ToString(); f1.value = ds.Tables[0].Rows[row]["Battery_tem"].ToString(); functions.Add(f1); Function f2 = new Function(); f2.id = ds.Tables[0].Rows[row]["function_Irr"].ToString(); f2.coding = "192"; f2.sample_time = ds.Tables[0].Rows[row]["sample_time"].ToString(); f2.value = ds.Tables[0].Rows[row]["Irr"].ToString(); functions.Add(f2); Function f3 = new Function(); f3.id = ds.Tables[0].Rows[row]["function_Sur_tem"].ToString(); f3.coding = "192"; f3.sample_time = ds.Tables[0].Rows[row]["sample_time"].ToString(); f3.value = ds.Tables[0].Rows[row]["Sur_tem"].ToString(); functions.Add(f3); Function f4 = new Function(); f4.id = ds.Tables[0].Rows[row]["function_Totalampac"].ToString(); f4.coding = "192"; f4.sample_time = ds.Tables[0].Rows[row]["sample_time"].ToString(); f4.value = ds.Tables[0].Rows[row]["Totalampac"].ToString(); functions.Add(f4); m.function = functions.ToArray<Function>(); meters.Add(m); msg.data.meter = meters.ToArray<Meter>(); string xml = MessageParser.Serialize(msg); logger.Debug(xml); MessageQueueManager.GetSendQueue(projectId).Enqueue(msg); } }
public static Message CreateRequestMessage(string projectId, string gatewayId) { Message msg = new Message(); msg.common.project_id = projectId; msg.common.gateway_id = gatewayId; msg.common.type = MessageType.MESSAGE_TYPE_REQUEST; msg.id_validate = new ValidationSection(); msg.id_validate.operation = MessageType.MESSAGE_TYPE_REQUEST; return msg; }