public virtual void AssignFrom(AlarmEntity entity) { if (entity == null) throw new ArgumentNullException(nameof(entity)); this.Id = entity.Id; this.Weekdays = entity.Weekdays; this.ShortTime = entity.ShortTime; this.IsEnabled = entity.IsEnabled; this.Task = entity.Task.ToViewModel(); this.Bell = entity.Bell; }
//////事件名称列表 // 门: //1.door is closed 门已关闭 //2.door is open 门已打开 //3.door is open too long 开门时间过长 (报警信息) //4.door opened without authorization 非法开门(报警信息) //5.door is open permanently 门解锁、或者翻译为门常开 //读卡器: //1.access 合法卡刷卡进入 //2.authorized, person did not enter 合法卡刷卡但未进入,或者翻译为超时(报警信息) //3.NOT authorized, no authorization 卡片未授权(报警信息) //4.NOT authorized, card is unknown 卡片未知(报警信息) //5.NOT authorized, 1 * wrong pincode 密码错误(报警信息) //6.NOT authorized, distress pincode used 胁迫报警(报警信息) //7.access, via remote command 远程开门 public AlarmEntity tcpToAlarm(string tcpMsg) { AlarmEntity alarm = new AlarmEntity(); var items = tcpMsg.Split(new string[] { @"/" }, StringSplitOptions.RemoveEmptyEntries); foreach (string item in items) { var kvPair = item.Split(new string[] { @"=" }, StringSplitOptions.RemoveEmptyEntries); { switch (kvPair[0].Trim()) { case "ltim": //时间 alarm.body.alarmTime = DateTime.ParseExact(kvPair[1].Replace("W", "").Trim(), "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture).ToString("yyyy-MM-dd HH:mm:ss"); break; case "Devices.type": //设备类型 if (kvPair[1].Replace("\"", "") == "NORMDOOR") { alarm.body.equClassCode = "01"; alarm.body.equClassName = "门"; } if (kvPair[1].Replace("\"", "").Contains("WIE1")) //读卡器 { alarm.body.equClassCode = "02"; alarm.body.equClassName = "读卡器"; } break; case "Devices.displaytext": //设备名称 alarm.body.alarmEquName = kvPair[1].Replace("\"", "").Trim(); alarm.body.alarmName = kvPair[1].Replace("\"", "").Trim(); break; case "Devices.id": //设备编号 alarm.body.alarmEquCode = kvPair[1].Replace("\"", "").Trim(); break; case "MSGTEXT": //事件名称 switch (kvPair[1].Replace("\"", "").Trim()) { case "door is open too long": alarm.body.alarmTypeCode = "03"; alarm.body.alarmTypeName = "开门时间过长"; break; case "door opened without authorization": alarm.body.alarmTypeCode = "04"; alarm.body.alarmTypeName = "非法开门"; break; case "door is open permanently": alarm.body.alarmTypeCode = "05"; alarm.body.alarmTypeName = "门常开"; break; case "authorized, person did not enter": alarm.body.alarmTypeCode = "06"; alarm.body.alarmTypeName = "超时"; break; case "NOT authorized, no authorization": alarm.body.alarmTypeCode = "07"; alarm.body.alarmTypeName = "卡片未授权"; break; case "NOT authorized, card is unknown": alarm.body.alarmTypeCode = "08"; alarm.body.alarmTypeName = "卡片未知"; break; case "NOT authorized, 1* wrong pincode": alarm.body.alarmTypeCode = "09"; alarm.body.alarmTypeName = "密码错误"; break; case "NOT authorized, distress pincode used": alarm.body.alarmTypeCode = "10"; alarm.body.alarmTypeName = "胁迫报警"; break; default: break; } break; //case "Areas.areaid"://区域id // alarm.body.areaId = "" + kvPair[1].Replace("\"", "").Trim(); // break; //case "Areas.name"://区域名称 // alarm.body.areaName = "" + kvPair[1].Replace("\"", "").Trim(); // break; //case "Cards.cardid"://刷卡id // break; //case "Cards.cardno"://刷卡no // break; //case "Persons.persid"://刷卡人id // break; //case "Persons.persno"://刷卡人no // break; //case "Persons.firstname"://刷卡人姓 // break; //case "Persons.lastname"://刷卡人名 // break; default: break; } } } return(alarm); }
private void startListener() { IPAddress address = IPAddress.Parse(localIp); IPEndPoint ep = new IPEndPoint(address, int.Parse(port)); TcpListener listener = new TcpListener(ep); listener.Start(); startReceiveData(); byte[] buffer = new byte[2 * 8192]; var sender = listener.AcceptTcpClient(); sender.ReceiveBufferSize = 2 * 8192; // Set the timeout for synchronous receive methods to // 40 second (1000 milliseconds.) because after 30 seconds without any new message an ALIVE message // should be received sender.ReceiveTimeout = 60 * 1000; while (true) { // Accept connection again // if ((sender == null) || !sender.Connected) { sender = listener.AcceptTcpClient(); // blocking call ... } // Try to read received message // int iReadNum = 0; iReadNum = sender.GetStream().Read(buffer, 0, sender.ReceiveBufferSize); //bytesize // Any message received? if (iReadNum == 0) { // Here simple retry again.. Timeout and reconnect handling should be implemented continue; } // Message received .. it is always of type unicode! string tcpMessage = System.Text.Encoding.Unicode.GetString(buffer).Substring(0, iReadNum / 2); Debug.WriteLine(tcpMessage); // The format of the received message string is described in the next chapter “Event messsages” if (tcpMessage.Contains("ALIVE="))//如果是心跳 { string dtStr = tcpMessage.Substring(tcpMessage.IndexOf("ALIVE="), 20); } if (tcpMessage.Contains("START=") || tcpMessage.Contains("ALIVE=")) { continue; } if (tcpMessage.Contains("MSGTEXT=\"door is closed\"") || tcpMessage.Contains("MSGTEXT=\"door is open\"")) //开门关门暂不处理 { continue; } else if (tcpMessage.Contains("MSGTEXT=\"access\"") || tcpMessage.Contains("MSGTEXT=\"access, via remote command\""))//合法卡刷卡、远程开门,发送至正常刷卡队列 { SwipeEntity swipte = tcpToSwipe(tcpMessage); string message = swipte.toJson(); KafkaWorker.sendSwipeMessage(message); } else //报警信息发送至报警队列 { AlarmEntity alarm = tcpToAlarm(tcpMessage); string message = alarm.toJson(); KafkaWorker.sendAlarmMessage(message); } } }
public AlarmEvent(AlarmEntity alarm) { this.Alarm = alarm; this.TimeDiff = alarm.SinceLessonStart ?? default; }
private static AlarmExistsResult Check(AlarmEntity alarmPeriod, string message) { if (alarmPeriod == null) return new AlarmExistsResult(false, message, null); return new AlarmExistsResult(true, null, alarmPeriod); }
public AlarmExistsResult(bool isSucceed, string message, AlarmEntity alarmPeriod) :base(isSucceed,message) { this.AlarmPeriod = alarmPeriod; }
public void SetCtls(AlarmEntity entity) { throw new NotImplementedException(); }