public void LoadStaticPage() { string[] type_names = { "433Changer" /*433转换器*/, "LoRaDoorLock" /*LoRa门锁*/, "MPM4780_Transmitters" /*MPM4780智能变送器*/, "YBL-SingleFireThreeKeySwitch" /*单火三路开关控制器*/, "ThreeWayLoraSwitch" /*智能三路触控开关*/, "BODY_SENSOR" /*智能三鉴探测器*/, "OneWayLoraSwitch" /*智能单路触控开关*/, "TwoWayLoraSwitch" /*智能双路触控开关*/, "LoRaPlug" /*智能插座*/, "Liquid_Transmitters" /*智能液位变送器*/, "LoRaTempHumid" /*温湿度传感器*/, "temperature-sensor" /*温湿度传感器-XW-TH-B/BO-485*/, "fluid-leakage-controller" /*漏液不定位传感器*/, "positioning-fluid-leakage-controller" /*漏液定位传感器*/, "SmokeSensor" /*烟雾传感器*/, "LoRaAirPanel" /*空调面板*/, "human-detection" /*红外人体检测传感器*/ }; //1、token accessTokenJo = GetAccessToken(api_token); if (accessTokenJo.Value <int>("expiresIn") <= 100) { //超时 } string accessToken = accessTokenJo["accessToken"].ToString(); //3、applist所有应用 appListJo = GetAppList(accessToken); List <App> applist = new List <App>(); IEnumerable <JToken> jAppProperties = deiveListJo["data"]["apps"].Ancestors(); foreach (JToken jt in jAppProperties) { App app = new App() { appID = jt.Value <int>("appID"), appName = jt.Value <string>("appName"), deiveList = new List <Deive>() }; //4、当前应用下的所有设备 deiveListJo = GetDeiveList(accessToken, app.appID, type_names); IEnumerable <JProperty> jDevProperties = (deiveListJo["data"]["children"] as JObject).Properties();//设备集合 foreach (JProperty jp in jDevProperties) { deiveJo = JObject.Parse(jp.Value.ToString()); Deive deive = new Deive() { deviceId = deiveJo.Value <string>("deviceId"), deviceName = deiveJo.Value <string>("deviceName"), typeName = deiveJo.Value <string>("typeName"), }; app.deiveList.Add(deive); } applist.Add(app); } }
/// <summary> /// 加载概览 /// </summary> /// <returns></returns> public string LoadOverView() { #region 真实数据 accessTokenJo = GetAccessToken(api_token); if (accessTokenJo.Value <int>("expiresIn") <= 100) { //超时 return(""); } accessToken = accessTokenJo["accessToken"].ToString(); //2、查询所有设备状态 所有应用,所有设备 JObject requestJo = new JObject(); foreach (string typeName in type_names) { requestJo.Add( new JProperty(typeName, new JObject( new JProperty("all", true), new JProperty("group_ids", new JArray()), new JProperty("device_ids", new JArray()) ))); } allJo = GetState(accessToken, requestJo);//所有类型,所有设备 IEnumerable <JProperty> jTypeProperties = allJo.Properties(); appList = new List <App>(); foreach (JProperty jp in jTypeProperties) { if (jp.Value.Count() != 0) { IEnumerable <JProperty> jDevProperties = (jp.Value as JObject).Properties(); //获取该类型所有设备 foreach (JProperty jdp in jDevProperties) { IEnumerable <App> querylist = appList.Where(j => j.appID == jdp.Value.Value <int>("app_id")); Deive deive = new Deive() { deviceId = jdp.Path.Split('.')[1], deviceName = jdp.Value.Value <string>("name"), typeName = jp.Path, }; string state = jdp.Value.Value <string>("states"); App app = null; if (querylist != null && querylist.Count() > 0) { app = querylist.FirstOrDefault(); app.all++; if (state == "offline") { deive.state = "离线"; } else if (state == "online") { deive.state = "在线"; app.online++; } app.deiveList.Add(deive); } else { app = new App() { appID = jdp.Value.Value <int>("app_id"), appName = jdp.Value.Value <string>("app_name"), date = DateTime.Now.ToString("yyyy:mm:dd:hh:ss"), all = 1, deiveList = new List <Deive>() }; if (state == "offline") { deive.state = "离线"; app.online = 0; } else if (state == "online") { deive.state = "在线"; app.online = 1; } app.deiveList.Add(deive); appList.Add(app); } } } } string jsonStr = JsonConvert.SerializeObject(appList); return(jsonStr); #endregion #region 测试数据 //return "[{\"appID\":2,\"appName\":\"奥拓电子\",\"date\":\"2019:28:11:04:06\",\"online\":10,\"all\":30,\"deiveList\":[{\"deviceId\":\"GIK8330011\",\"deviceName\":\"空调面板\",\"state\":\"离线\",\"typeName\":\"LoRaAirPanel\"},{\"deviceId\":\"GEK9320663\",\"deviceName\":\"智能排插\",\"state\":\"在线\",\"typeName\":\"LoRaPlug\"},{\"deviceId\":\"GEK9320715\",\"deviceName\":\"智能排插2\",\"state\":\"在线\",\"typeName\":\"LoRaPlug\"},{\"deviceId\":\"GMK8501686\",\"deviceName\":\"智能插座\",\"state\":\"离线\",\"typeName\":\"LoRaPlug\"},{\"deviceId\":\"GMK8502203\",\"deviceName\":\"智能插座2\",\"state\":\"离线\",\"typeName\":\"LoRaPlug\"},{\"deviceId\":\"GJK9291964\",\"deviceName\":\"温湿度传感器\",\"state\":\"离线\",\"typeName\":\"LoRaTempHumid\"},{\"deviceId\":\"GQK9320712-3-1\",\"deviceName\":\"烟雾传感器\",\"state\":\"离线\",\"typeName\":\"SmokeSensor\"},{\"deviceId\":\"ybl_DD3A0300\",\"deviceName\":\"单火三路\",\"state\":\"在线\",\"typeName\":\"YBL - SingleFireThreeKeySwitch\"},{\"deviceId\":\"GLK8500117\",\"deviceName\":\"红外人体感应\",\"state\":\"离线\",\"typeName\":\"human-detection\"},{\"deviceId\":\"GLK8500320\",\"deviceName\":\"红外人体感应2\",\"state\":\"离线\",\"typeName\":\"human-detection\"}]},{\"appID\":3,\"appName\":\"奥拓电子11\",\"date\":\"2019:28:11:04:06\",\"online\":10,\"all\":30,\"deiveList\":[{\"deviceId\":\"GIK8330011\",\"deviceName\":\"空调面板1\",\"state\":\"离线\",\"typeName\":\"LoRaAirPanel\"},{\"deviceId\":\"GEK9320663\",\"deviceName\":\"智能排插1\",\"state\":\"在线\",\"typeName\":\"LoRaPlug\"},{\"deviceId\":\"GEK9320715\",\"deviceName\":\"智能排插2\",\"state\":\"在线\",\"typeName\":\"LoRaPlug\"},{\"deviceId\":\"GMK8501686\",\"deviceName\":\"智能插座23\",\"state\":\"离线\",\"typeName\":\"LoRaPlug\"},{\"deviceId\":\"GMK8502203\",\"deviceName\":\"智能插座2\",\"state\":\"离线\",\"typeName\":\"LoRaPlug\"},{\"deviceId\":\"GJK9291964\",\"deviceName\":\"温湿度传感器\",\"state\":\"离线\",\"typeName\":\"LoRaTempHumid\"},{\"deviceId\":\"GQK9320712-3-1\",\"deviceName\":\"烟雾传感器\",\"state\":\"离线\",\"typeName\":\"SmokeSensor\"},{\"deviceId\":\"ybl_DD3A0300\",\"deviceName\":\"单火三路\",\"state\":\"在线\",\"typeName\":\"YBL - SingleFireThreeKeySwitch\"},{\"deviceId\":\"GLK8500117\",\"deviceName\":\"红外人体感应\",\"state\":\"离线\",\"typeName\":\"human-detection\"},{\"deviceId\":\"GLK8500320\",\"deviceName\":\"红外人体感应2\",\"state\":\"离线\",\"typeName\":\"human-detection\"}]}]"; #endregion }