/// <summary> /// 分析从控制中心获取的数据 /// </summary> /// <param name="json_str"></param> public void Fengxi_shuju(string json_str, Fuwuqi_ip fuwuqi_Ip) { try { Shuju_chuang shuju_Chuang = null; Kongzhi kongzhi = null; using (TextReader str = new StringReader(json_str)) { JsonSerializer serializer = new JsonSerializer(); shuju_Chuang = (Shuju_chuang)serializer.Deserialize(str, typeof(Shuju_chuang)); } if (shuju_Chuang != null) { //查找是否存在控制中心 foreach (var item in Kongzhis) { if (item.Shuju.Weiyi_shibie == shuju_Chuang.Kongzhi.Weiyi_shibie) { kongzhi = item; } } if (kongzhi == null) { kongzhi = new Kongzhi(); kongzhi.chushihua(shuju_Chuang.Kongzhi, fuwuqi_Ip); Kongzhis.Add(kongzhi); } //调用控制中心更新 kongzhi.Gengxin(shuju_Chuang); } } catch (Exception exc) { } }
/// <summary> /// 更新设备数据 /// </summary> /// <param name="json_str">包含所有设备数据的外层JSON</param> public void Gengxin(Shuju_chuang shuju_Chuang) { //更新控制中心数据 Shuju.Zhujiming = shuju_Chuang.Kongzhi.Zhujiming; //更新设备数据 for (int i = 0; i < shuju_Chuang.shuju_Shebei_PCs.Count; i++) { Shebei_PC shebei_PC = null; //根据唯一识别号匹配设备 foreach (var item in Shebei_Fus) { if (item.Shuju.Weiyi_shibie == shuju_Chuang.shuju_Shebei_PCs[i].Weiyi_shibie) { shebei_PC = item as Shebei_PC; shebei_PC.Gengxin(shuju_Chuang.shuju_Shebei_PCs[i]); } } //未匹配到设备 if (shebei_PC == null) { shebei_PC = new Shebei_PC(); shebei_PC.Chushihua(shuju_Chuang.shuju_Shebei_PCs[i].Weiyi_shibie); Shebei_Fus.Add(shebei_PC); } shebei_PC.Gengxin(shuju_Chuang.shuju_Shebei_PCs[i]); } //更新设备数据 for (int i = 0; i < shuju_Chuang.shuju_Shebei_ADs.Count; i++) { Shebei_AD shebei_AD = null; //根据唯一识别号匹配设备 foreach (var item in Shebei_Fus) { if (item.Shuju.Weiyi_shibie == shuju_Chuang.shuju_Shebei_ADs[i].Weiyi_shibie) { shebei_AD = item as Shebei_AD; shebei_AD.Gengxin(shuju_Chuang.shuju_Shebei_ADs[i]); } } //未匹配到设备 if (shebei_AD == null) { shebei_AD = new Shebei_AD(); shebei_AD.Chushihua(shuju_Chuang.shuju_Shebei_PCs[i].Weiyi_shibie); Shebei_Fus.Add(shebei_AD); } shebei_AD.Gengxin(shuju_Chuang.shuju_Shebei_ADs[i]); } //删除已经断开连接设备 for (int k = 0; k < Shebei_Fus.Count; k++) { bool shifou_cunzai = false; //根据唯一识别号匹配设备 for (int i = 0; i < shuju_Chuang.shuju_Shebei_PCs.Count; i++) { if (Shebei_Fus[k].Shuju.Weiyi_shibie == shuju_Chuang.shuju_Shebei_PCs[i].Weiyi_shibie) { shifou_cunzai = true; break; } } for (int i = 0; i < shuju_Chuang.shuju_Shebei_ADs.Count; i++) { if (Shebei_Fus[k].Shuju.Weiyi_shibie == shuju_Chuang.shuju_Shebei_ADs[i].Weiyi_shibie) { shifou_cunzai = true; break; } } //未匹配到设备 if (shifou_cunzai == false) { Shebei_Fus.RemoveAt(k); } } }