public static DeviceResourEntity parseDeviceRec(string[] devArr) { DeviceResourEntity devResEnt = null; try { devResEnt = new DeviceResourEntity(); devResEnt.meta.eventType = "SVMS_EQUINFO_UE"; devResEnt.meta.msgType = "EQU"; devResEnt.meta.receiver = ""; devResEnt.meta.recvSequence = ""; devResEnt.meta.recvTime = ""; devResEnt.meta.sender = "SXJ"; devResEnt.meta.sendTime = DateTime.Now.ToString("yyyyMMddHHmmss"); devResEnt.meta.sequence = ""; string pattern = "[\\[ \\] \\^ \\-_*×――(^)%~!@#…&%¥—+<>《》!!???::•`·、。,;,;\"‘’“”-]"; string channelID = Regex.Replace(devArr[1], pattern, "").Split(new char[] { '=' })[1]; devResEnt.body.equCode = channelID; devResEnt.body.equName = Regex.Replace(devArr[2], pattern, "").Split(new char[] { '=' })[1]; devResEnt.body.equTypeCode = Regex.Replace(devArr[8], pattern, "").Split(new char[] { '=' })[1]; if (devResEnt.body.equTypeCode == "1") { devResEnt.body.equTypeName = "枪机"; } else if (devResEnt.body.equTypeCode == "2") { devResEnt.body.equTypeName = "球机"; } else if (devResEnt.body.equTypeCode == "3") { devResEnt.body.equTypeName = "半球"; } else { devResEnt.body.equTypeName = "枪机"; } //devResEnt.body.operationType = "0"; } catch (Exception ex) { FileWorker.LogHelper.WriteLog("解析设备基本信息失败," + ex.Message); } return(devResEnt); }
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()); } }