public string AnalysisTopic(string topic, byte[] bytes) { //工具类 ToolHelper tl = new ToolHelper(); //Dictionary<int, string> dc = new Dictionary<int, string>(); string json = ""; //行为分析盒子报警信息处理 AlarmInfoHandle handle = new AlarmInfoHandle(); if (topic == "Device/GuangXian") { json = tl.CondingHelp(bytes, 2); JObject jsonObj = (JObject)JsonConvert.DeserializeObject(json); //增加处置ID string ts = Guid.NewGuid().ToString(); jsonObj.Add("Guid", ts); var AreaID = Convert.ToInt32(jsonObj["AreaID"]); var AlarmID = ""; jsonObj.Add("AlarmID", AlarmID); json = jsonObj.ToString(); //dc.Add(0,json); return(json); } else if (topic == "Device/ShaoWeiAlarm") { json = tl.CondingHelp(bytes, 2); JObject jsonObj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(json); string ts = Guid.NewGuid().ToString(); jsonObj.Add("Guid", ts); string businessID = ""; if (businessID == "") { } json = jsonObj.ToString(); //dc.Add(0, json); return(json); } else if (topic == "Device/VideoAnalysis/YFT") { json = tl.CondingHelp(bytes, 2); json = handle.ParsingActionJson(json); JObject jsonObj = (JObject)JsonConvert.DeserializeObject(json); string ts = Guid.NewGuid().ToString(); jsonObj.Add("Guid", ts); json = jsonObj.ToString(); //dc.Add(0, json); return(json); } else if (topic == "Device/RenLian/YFT") { json = tl.CondingHelp(bytes, 2); json = handle.ParsingFaceJson(json); if (json != "") { JObject jsonObj = (JObject)JsonConvert.DeserializeObject(json); string ts = Guid.NewGuid().ToString(); jsonObj.Add("Guid", ts); json = jsonObj.ToString(); } //dc.Add(0, json); return(json); } else if (topic == "Device/CheLiang/YFT") { json = tl.CondingHelp(bytes, 2); json = handle.ParsingTeZhenJson(json); JObject jsonObj = (JObject)JsonConvert.DeserializeObject(json); string ts = Guid.NewGuid().ToString(); jsonObj.Add("Guid", ts); json = jsonObj.ToString(); //dc.Add(0, json); return(json); } else if (topic == "Device/ShaoWeiBox") { return(""); } else if (topic == "Device/ShaoWeiZhiWen") { } else if (topic == "Device/RenLian/HK") { return(""); } else if (topic == "Device/VideoAnalysis/HK") { json = tl.CondingHelp(bytes, 2); JObject jsonObj = (JObject)JsonConvert.DeserializeObject(json); //增加处置ID string ts = Guid.NewGuid().ToString(); jsonObj.Add("Guid", ts); try { string[] arr = tl.GetImgIp(); string url = arr[0]; string port = arr[1]; jsonObj["ImageUrl"] = string.Format("http://{0}:{1}/{2}", url, port, jsonObj["ImageUrl"].ToString()); json = jsonObj.ToString(); } catch (Exception ex) { json = ""; } //dc.Add(0,json); return(json); } else if (topic == "Device/CheLiang/HK") { json = tl.CondingHelp(bytes, 2); JObject jsonObj = (JObject)JsonConvert.DeserializeObject(json); //增加处置ID string ts = Guid.NewGuid().ToString(); jsonObj.Add("Guid", ts); json = jsonObj.ToString(); //dc.Add(0,json); try { string[] arr = tl.GetImgIp(); string url = arr[0]; string port = arr[1]; jsonObj["ImageUrl"] = string.Format("http://{0}:{1}/{2}", url, port, jsonObj["ImageUrl"].ToString()); json = jsonObj.ToString(); } catch (Exception ex) { json = ""; } return(json); } return(json); }
public string ParsingActionJson(string jsonstr) { ActionAlarmMessage info = new ActionAlarmMessage(); string jsonData = ""; try { //jsonstr = System.Web.HttpUtility.UrlDecode(jsonstr, Encoding.UTF8); JObject json = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonstr); info.DeviceId = json["DeviceId"].ToString(); string imageUrl = json["ImageUrl"].ToString(); string[] arr = tl.GetImgIp(); string url = arr[0]; string port = arr[1]; info.ImageUrl = string.Format("http://{0}:{1}/{2}", url, port, imageUrl); var obj = json["peopleInfo"]; var obj1 = json["carInfo"]; var obj2 = json["NonVehiclesInfo"]; var obj3 = json["faceInfo"]; if (obj.ToArray().Length > 0) { info.Type = "人"; string EventType = obj[0]["eventType"].ToString(); if (EventType == "intrusion") { EventType = "区域入侵"; } else if (EventType == "wireCross") { EventType = "越线"; } else if (EventType == "loitering") { EventType = "徘徊检测"; } info.EventType = EventType; } else if (obj1.ToArray().Length > 0) { info.Type = "机动车"; string EventType = obj1[0]["eventType"].ToString(); if (EventType == "intrusion") { EventType = "区域入侵"; } else if (EventType == "wireCross") { EventType = "越线"; } else if (EventType == "loitering") { EventType = "徘徊检测"; } info.EventType = EventType; } else if (obj2.ToArray().Length > 0) { info.Type = "非机动车"; string EventType = obj2[0]["eventType"].ToString(); if (EventType == "intrusion") { EventType = "区域入侵"; } else if (EventType == "wireCross") { EventType = "越线"; } else if (EventType == "loitering") { EventType = "徘徊检测"; } info.EventType = EventType; } var time = Convert.ToDouble(json["time"]); DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); // 当地时区 DateTime dt = startTime.AddMilliseconds(time); info.time = dt.ToString("yyyy-MM-dd HH:mm:ss"); jsonData = JsonConvert.SerializeObject(info); } catch (Exception ex) { Console.WriteLine("json解析失败:" + ex.Message); Trace.WriteLine("json转换数据失败!" + ex.Message + Environment.NewLine, "JsonStatus"); } return(jsonData); }