Ejemplo n.º 1
0
 void IJob.Execute(IJobExecutionContext context)
 {
     if (!_stop)
     {
         KafkaWorker.startGetMessage();
     }
 }
Ejemplo n.º 2
0
        private void ReceiveMessage(object obj)
        {
            IPEndPoint remoteIpep = new IPEndPoint(IPAddress.Parse(serverIp), serverPort);

            while (true)
            {
                try
                {
                    byte[] bytRecv    = udpcRecv.Receive(ref remoteIpep);
                    string bytRecvStr = string.Join(" ", bytRecv);
                    FileWorker.LogHelper.WriteLog("接收到的原始数据是:" + bytRecvStr);
                    string msg = Encoding.Default.GetString(bytRecv);
                    FileWorker.LogHelper.WriteLog("原始数据解析后是:" + msg);

                    AlarmEntity alarm        = udpToAlarm(msg);
                    string      messageAlarm = alarm.toJson();
                    KafkaWorker.sendAlarmMessage(messageAlarm);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
 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]);
             }
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 定时查询数据
        /// </summary>
        public void cyclicWork()
        {
            string strConn = ConfigWorker.GetConfigValue("connectString");
            //strConn = "server=127.0.0.1;database=CEMData;uid=sa;pwd=qq.123456";
            string tableName = ConfigWorker.GetConfigValue("devTableName");
            string sql       = string.Format("select DoorID,dev_addr,DoorName from {0} ", tableName);

            FileWorker.LogHelper.WriteLog("定时查询设备信息");
            try
            {
                DataSet ds = null;
                using (SqlDataAdapter da = new SqlDataAdapter(sql, strConn))
                {
                    ds = new DataSet();
                    da.Fill(ds);
                }
                foreach (DataRow item in ds.Tables[0].Rows)
                {
                    List <string> devList = new List <string>();
                    devList.Add(item.ItemArray[0].ToString());
                    devList.Add(item.ItemArray[1].ToString());
                    devList.Add(item.ItemArray[2].ToString());
                    ResourStateEntity accessEnt = StateParseTool.parseState(devList);
                    string            jsonMess  = accessEnt.toJson();
                    KafkaWorker.sendDeviceMessage(jsonMess);
                }
            }
            catch (Exception e)
            {
                FileWorker.LogHelper.WriteLog("解析设备信息表失败:" + e.Message);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 命令接收、执行
 /// </summary>
 /// <param name="message"></param>
 private void KafkaWorker_OnGetMessage(string message)
 {
     if (message.Contains("FIRST_CARD_DATA_REQ"))
     {
         var persons = SqlServerHelper.getPersons();
         foreach (PersonEntity person in persons)
         {
             string personMsg = person.toJson().Replace(@"\\", @"\");
             KafkaWorker.sendPersonMessage(personMsg);
         }
     }
 }
Ejemplo n.º 6
0
 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);
         }
     }
 }
Ejemplo n.º 7
0
        public static IntPtr NvrStatusCallback(IntPtr nPDLLHandle,
                                               [MarshalAs(UnmanagedType.LPStr)] StringBuilder szChnlId,
                                               IntPtr nStatus,
                                               IntPtr pUserParam)
        {
            String status = "未知";

            if (nStatus == (IntPtr)1)
            {
                status = "上线";
            }
            else
            {
                status = "离线";
            }
            string            str      = "NvrStatusCallback ChannelId:" + szChnlId.ToString() + "  nStatus:" + status;
            DeviceStateEntity devEnt   = DeviceStateParseTool.parseDeviceState(szChnlId.ToString(), status);
            string            jsonMess = devEnt.toJson();

            KafkaWorker.sendDeviceMessage(jsonMess, "状态");
            return((IntPtr)0);
        }
Ejemplo n.º 8
0
        protected override void DefWndProc(ref System.Windows.Forms.Message m)
        {
            switch (m.Msg)
            {
            case WM_COPYDATA:
                COPYDATASTRUCT mystr  = new COPYDATASTRUCT();
                Type           mytype = mystr.GetType();
                mystr = (COPYDATASTRUCT)m.GetLParam(mytype);
                string[] messColl = mystr.lpData.Split(new char[] { '=' });
                if (messColl[0] == "D00")
                {
                    //MessageBox.Show(mystr.lpData);
                    FileWorker.LogHelper.WriteLog("接受车底信息记录D00:" + mystr.lpData);
                    MessCommand messComm = Utils.ParseCarScanMess(messColl);

                    string jsonMess = messComm.toJson();
                    KafkaWorker.sendCarRecordMessage(jsonMess);
                    Task.Run(() => {
                        //在上传图片之前先进行压缩,保存到本地上,然后拿到压缩后的路径,进行FTP的上传
                        //string path = string.Format("/{0}/{1}", DateTime.Now.ToString("yyyy.MM.dd"), Path.GetFileName(messComm.body.vechicleInUvssPicpath));
                        FtpStatus ftpStatus = FtpHelper.upload(messColl[4], messComm.body.vechicleInUvssPicpath);
                        if (ftpStatus == FtpStatus.Success)
                        {
                            FileWorker.LogHelper.WriteLog("上传文件" + messColl[4] + "成功");
                        }
                        else if (ftpStatus == FtpStatus.Skipped)
                        {
                            FileWorker.LogHelper.WriteLog("上传文件" + messColl[4] + "在服务端已存在,跳过传输");
                        }
                        else
                        {
                            FileWorker.LogHelper.WriteLog("上传文件" + messColl[4] + "失败");
                            string txtPath = Application.StartupPath + "\\imageErrorMess.txt";
                            string txt     = string.Format("{0}|{1}", messColl[4], messComm.body.vechicleInUvssPicpath);
                            WriteLogFile(txtPath, txt);
                        }
                        //string txtPath = Application.StartupPath + "\\imageErrorMess.txt";
                        //string txt = string.Format("{0}|{1}", messComm.body.vechicleInUvssPicpath, path);
                        //WriteLogFile(txtPath, txt);
                    });
                }
                else if (messColl[0] == "D01")
                {
                    //FileWorker.LogHelper.WriteLog("基本工作状态D01:" + mystr.lpData);
                    //WorkingState work = Utils.ParseWorkMess(messColl);
                    //string jsonMess = work.toJson();
                    //KafkaTest.SendMessCommand(jsonMess);
                }
                else if (messColl[0] == "D02")
                {
                    FileWorker.LogHelper.WriteLog("第3方自定义功能D02:" + mystr.lpData);
                    if (messColl[1] == "0")
                    {
                        this.Close();
                    }
                    else if (messColl[1] == "1")
                    {
                        this.TopMost = true;
                    }
                    else if (messColl[1] == "2")    //D02 = 2 = N = EOF
                    {
                        //N 最大接入许可数量
                        //MessageOrder work = Utils.ParseMessOrder(messColl);
                        //上行,发送"U02=2=EOF"
                        SendResponOrder();
                    }
                    else
                    {
                    }
                }
                else
                {
                    FileWorker.LogHelper.WriteLog("未知命令:" + mystr.lpData);
                    //MessageBox.Show(mystr.lpData);
                }
                break;

            default:
                base.DefWndProc(ref m);
                break;
            }
        }
Ejemplo n.º 9
0
        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
        }
Ejemplo n.º 10
0
        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);
                }
            }
        }
Ejemplo n.º 11
0
        public void getDeviceInfo()
        {
            IntPtr result = DPSDK_LoadDGroupInfo(nPDLLHandle, ref nGroupLen, (IntPtr)60000);

            if (result == (IntPtr)0)
            {
                FileWorker.LogHelper.WriteLog("加载组织结构成功");
            }
            else
            {
                FileWorker.LogHelper.WriteLog("加载组织结构失败,错误码:" + result.ToString());
                //MessageBox.Show("加载组织结构失败,错误码:" + result.ToString());
            }
            byte[] szGroupStr = new byte[(int)nGroupLen + 1];
            result = DPSDK_GetDGroupStr(nPDLLHandle, szGroupStr, nGroupLen, (IntPtr)10000);
            if (result == IntPtr.Zero)
            {
                string strXML = System.Text.Encoding.UTF8.GetString(szGroupStr);
                //FileWorker.LogHelper.WriteLog(strXML);
                try
                {
                    var doc = new XmlDocument();
                    strXML = strXML.Trim('\0');
                    doc.LoadXml(strXML);
                    XmlNodeList   xmlNodeList = doc.GetElementsByTagName("Channel");//获取节点
                    List <String> channList   = new List <string>();
                    string        pattern     = "[\\[ \\] \\^ \\-_*×――(^)%~!@#…&%¥—+<>《》!!???::•`·、。,;,;\"‘’“”-]";
                    for (int i = 0; i < xmlNodeList.Count; i++)
                    {
                        string[] devArr  = Regex.Replace(xmlNodeList[i].OuterXml, pattern, "").Split(new char[] { '=' });
                        string   channID = devArr[1].Substring(0, 7);
                        if (xmlNodeList[i].OuterXml.Length > 40 && channID != "1000016" && channID != "1000017")
                        {
                            channList.Add(xmlNodeList[i].OuterXml);
                        }
                    }
                    for (int j = 0; j < channList.Count; j++)
                    {
                        string[] strArr     = channList[j].Split(new char[] { ' ' });
                        string   channType  = Regex.Replace(strArr[5], pattern, "").Split(new char[] { '=' })[1];
                        string   code       = Regex.Replace(strArr[8], pattern, "").Split(new char[] { '=' })[1];
                        int      cameraType = int.Parse(code);
                        if (channType == "1" && cameraType <= 4)
                        {
                            DeviceResourEntity devResEnt = DeviceResourceParseTool.parseDeviceRec(strArr);
                            string             jsonMess  = devResEnt.toJson();
                            KafkaWorker.sendDeviceMessage(jsonMess, "基本信息");
                        }
                        //DeviceStateEntity devEnt = DeviceStateParseTool.parseDeviceState(strArr);
                        //string jsonMess = devEnt.toJson();
                        //KafkaWorker.sendDeviceMessage(jsonMess);
                    }
                }
                catch (Exception ex)
                {
                    FileWorker.LogHelper.WriteLog("解析XML数据失败:" + ex.Message);
                }
            }
            else
            {
                FileWorker.LogHelper.WriteLog("获取组织树XML失败,错误码:" + result.ToString());
                //MessageBox.Show("获取组织树XML失败,错误码:" + result.ToString());
            }
        }