private void Client_DataReceived(object sender, SimpleTCP.Message e) { FileWorker.LogHelper.WriteLog("刷卡信息:" + e.MessageString); string[] messageArr = e.MessageString.Split(new string[] { "TRDS" }, StringSplitOptions.RemoveEmptyEntries); for (int j = 0; j < messageArr.Length; j++) { messageArr[j] = "TRDS" + messageArr[j]; } for (int i = 0; i < messageArr.Length; i++) { string[] receMessage = messageArr[i].Split(new char[] { '|' }); if (receMessage[0] == "TRDS") { if (receMessage.Length >= 10) { AccessEntity accessEnt = AccessParseTool.parseAccess(receMessage); string jsonMess = accessEnt.toJson(); KafkaWorker.sendAccessMessage(jsonMess); anoAlarm = GetConfigMess(); if (anoAlarm.Keys.Contains(receMessage[9])) { AlarmEntity alarmEnt = AlarmParseTool.parseAlarm(receMessage, anoAlarm); string jsonAlarm = alarmEnt.toJson(); KafkaWorker.sendAlarmMessage(jsonAlarm); } } else { FileWorker.LogHelper.WriteLog("刷卡信息不全," + messageArr[i]); } } } }
private void axHSCEventSDK1_NewEvent(object sender, EventArgs e) { if (eventDic.ContainsKey(axHSCEventSDK1.sEventName))//报警信息 { var alarmEntity = AlarmParseTool.parseAlarm(axHSCEventSDK1, eventDic); if (alarmEntity != null) { string alarmMessage = alarmEntity.toJson(); FileWorker.LogHelper.WriteLog("正在向kafka发送报警数据" + alarmMessage); Debug.WriteLine(alarmMessage); KafkaWorker.sendAlarmMessage(alarmMessage); } } else if (axHSCEventSDK1.sEventName == "正常开门")//正常刷卡信息 { var cardId = axHSCEventSDK1.sUserCardID; axHSCCardHolderSDK1.sCardID = cardId; axHSCCardHolderSDK1.GetPIDUserInfo(); var accessEntity = AccessParseTool.parseAccess(axHSCEventSDK1, axHSCCardHolderSDK1); if (accessEntity != null) { string accessMessage = accessEntity.toJson(); FileWorker.LogHelper.WriteLog("正在向kafka发送正常刷卡数据" + accessMessage); KafkaWorker.sendAccessMessage(accessMessage); } } else if (axHSCEventSDK1.sEventName == "控制器上线")//设备状态信息 { var deviceEntity = DeviceStateParseTool.parseDeviceState(axHSCEventSDK1, "ES01"); if (deviceEntity != null) { string deviceMessage = deviceEntity.toJson(); FileWorker.LogHelper.WriteLog("正在向kafka发送设备状态数据" + deviceMessage); KafkaWorker.sendDeviceMessage(deviceMessage); } } else if (axHSCEventSDK1.sEventName == "控制器离线") { var deviceEntity = DeviceStateParseTool.parseDeviceState(axHSCEventSDK1, "ES02"); if (deviceEntity != null) { string deviceMessage = deviceEntity.toJson(); FileWorker.LogHelper.WriteLog("正在向kafka发送设备状态数据" + deviceMessage); KafkaWorker.sendDeviceMessage(deviceMessage); } } }
public void UpdateTestClient(Obj obixObj, Watch watch) { //FileWorker.LogHelper.WriteLog("收到数据:"+watch.type.ToString()+";;长度是"+obixObj.list().Length.ToString()); if (watch.type == WatchType.Alarm) { if (obixObj.list().Length > 0) { if (obixObj.list()[0].list().Length > 0) { //FileWorker.LogHelper.WriteLog("obixObj.list()[0].list().Length长度是" + obixObj.list()[0].list().Length.ToString()); if (obixObj.list()[0].list()[0].list().Length > 0) { //FileWorker.LogHelper.WriteLog("obixObj.list()[0].list()[0].list().Length长度是" + obixObj.list()[0].list()[0].list().Length.ToString()); foreach (Obj obj in obixObj.list()[0].list()[0].list()) { try { string time = ((Abstime)obj.get("timestamp")).Val.ToString(); string type = ((Int)obj.get("eventType")).Val.ToString(); string desc = obj.Display.ToString(); object id = obj.Href; object ack = obj.get("ack"); object clear = obj.get("clear"); object pointDescription = null; object priority = ((Int)obj.get("priority")).Val; string source = string.Empty; string alarmType = null; string fname = string.Empty; string lname = string.Empty; object cardnumber = null; string user = string.Empty; string card = string.Empty; string deviceName = string.Empty; string deptName = string.Empty; if (obj.get("companyname") != null) { deptName = obj.get("companyname").ToString(); } if (obj.get("devicedescription") != null) { deviceName = obj.get("devicedescription").ToString(); } if (obj.get("source") != null) { source = obj.get("source").Href.ToString(); } if (obj.get("fname") != null) { fname = obj.get("fname").ToString(); } if (obj.get("lname") != null) { lname = obj.get("lname").ToString(); } if (obj.get("cardnumber") != null) { cardnumber = obj.get("cardnumber").Href; } if (obj.get("accessUser") != null) { user = obj.get("accessUser").Href.ToString(); } if (obj.get("accessCredential") != null) { card = obj.get("accessCredential").Href.ToString(); } if (obj.get("AlarmStatus") != null) { alarmType = ((Str)obj.get("AlarmStatus")).Val; } if (obj.get("pointdescription") != null) { pointDescription = ((Str)obj.get("pointdescription")).Val; } FileWorker.LogHelper.WriteLog(string.Format("eventType:{0};desc:{1};source:{2};user:{3};credential:{4}", type, desc, source, user, card)); if (source != string.Empty) { source = DataFormatTool.pickTailFromString(source); } time = DataFormatTool.formatDatetime(time); //event type=500是刷卡,只有刷卡时才产生卡号、人员编号 if (type == "500") { if (card != string.Empty) { card = DataFormatTool.pickTailFromString(card); } if (user != string.Empty) { user = DataFormatTool.pickTailFromString(user); } AccessEntity access = AccessParseTool.parseAccess(card, source, "1", user, time, deptName, deviceName, lname + fname, "", "刷卡+密码开门"); KafkaWorker.sendAccessMessage(access.toJson()); //continue; } if (type == "608")//按钮开门,无卡号、人员编号 { AccessEntity access = AccessParseTool.parseAccess("", source, "2", "", time, "", deviceName, "", "", "按钮开门"); KafkaWorker.sendAccessMessage(access.toJson()); continue; } if (type == "903" || type == "10903") { DeviceStateEntity devState = DeviceStateParseTool.parseDeviceState(source, type); KafkaWorker.sendDeviceMessage(devState.toJson()); } //423,400,10900,900,500,903 if (alarmRuleDic.ContainsKey(type))//报警 { AlarmEntity alarm = AlarmParseTool.parseAlarm(source, alarmRuleDic[type].Item1, alarmRuleDic[type].Item2, time, airportIata, airportName); KafkaWorker.sendAlarmMessage(alarm.toJson()); continue; } } catch (Exception ex) { FileWorker.LogHelper.WriteLog("消息接收及解析、发送过程中出现异常:" + ex.Message); continue; } } } } } } #region 暂时不用 else //watch.type == WatchType.Object { if (obixObj.list().Length > 0) { DateTime updateTime = DateTime.Now; foreach (Obj obj in obixObj.list()[0].list()) { //bool rowFound = false; //for (int i = 0; i < grd.Rows.Count; i++) //{ // if (grd.Rows[i].Cells[0].Value.Equals(obj.Href)) // { // if (obj.isErr()) // { // //Object deleted in PW // grd.Rows.RemoveAt(i); // } // else // { // grd.Rows[i].Cells[1].Value = DateTime.Now; // updateTime = (DateTime)grd.Rows[i].Cells[1].Value; // } // rowFound = true; // break; // } //} //if (!rowFound) //{ // updateTime = DateTime.Now; // //grd.Rows.Add(obj.Href, updateTime); //} ////when object's parent url is subscribed. //System.Uri uri = obj.Href.toUri(); //if (uri.Segments.Length >= 5) //{ // string strUri = uri.ToString(); // if (strUri.EndsWith("/")) // strUri = strUri.Substring(0, strUri.Length - 1); // int nIndex = strUri.LastIndexOf("/"); // strUri = strUri.Substring(0, nIndex); // for (int i = 0; i < grd.Rows.Count; i++) // { // string strObjHref = Convert.ToString(grd.Rows[i].Cells[0].Value); // if (strObjHref.EndsWith("/")) // strObjHref = strObjHref.Substring(0, strObjHref.Length - 1); // if (strObjHref.Equals(strUri)) // { // grd.Rows[i].Cells[1].Value = updateTime; // break; // } // } //} } } } #endregion }