| | |
| | | continue;
|
| | | }
|
| | | //添加缓存
|
| | | string gwID = HdlGatewayLogic.Current.GetGatewayId(gateway);
|
| | | dicGateway[gwID] = gateway;
|
| | | dicGateway[gateway.GwId] = gateway;
|
| | | }
|
| | | }
|
| | | } |
| | |
| | | byte[] filebyte = Global.ReadFileByHomeId(file);
|
| | | string strvalue = System.Text.Encoding.UTF8.GetString(filebyte);
|
| | | var gateway = JsonConvert.DeserializeObject<ZbGateway>(strvalue);
|
| | | if (gateway.GwId == string.Empty)
|
| | | {
|
| | | //这是旧数据,需要特殊处理
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(strvalue);
|
| | | string gwInfo = jobject["getGwInfo"].ToString();
|
| | |
|
| | | var result = JsonConvert.DeserializeObject<ZbGatewayData.GetGwData>(gwInfo);
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(gateway, result);
|
| | | }
|
| | | return gateway;
|
| | | }
|
| | | catch (Exception ex)
|
| | |
| | | public void AddVirtualGateway(string gatewayId)
|
| | | {
|
| | | var gateWay = new ZbGateway { IsVirtual = true };
|
| | | gateWay.getGatewayBaseInfo.gwID = gatewayId;
|
| | | gateWay.getGatewayBaseInfo.HomeId = Shared.Common.Config.Instance.HomeId;
|
| | | gateWay.GwId = gatewayId;
|
| | | gateWay.HomeId = Shared.Common.Config.Instance.HomeId;
|
| | | gateWay.ReSave();
|
| | | this.dicGateway[gatewayId] = gateWay;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | //是否已经存在
|
| | | string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
|
| | | string gwID = zbGateway.GwId;
|
| | | bool isEsist = HdlGatewayLogic.Current.IsGatewayExist(zbGateway); |
| | | if (isEsist == false)
|
| | | {
|
| | |
| | |
|
| | | //刷新的是缓存,不刷新真实物理网关
|
| | | this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
|
| | | this.dicGateway[gwID].getGwInfo = result.getGwData;
|
| | | this.dicGateway[gwID].getGatewayBaseInfo.GwName = result.getGwData.GwName;
|
| | | this.dicGateway[gwID].getGatewayBaseInfo.IpAddress = result.getGwData.GwIP;
|
| | | this.dicGateway[gwID].getGatewayBaseInfo.HomeId = Common.Config.Instance.HomeId;
|
| | | this.dicGateway[gwID].ReSave();
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result.getGwData);
|
| | | //顺便这个变量也设置一下
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result.getGwData, false);
|
| | |
|
| | | if (isEsist == false)
|
| | | {
|
| | | //添加备份
|
| | |
| | | {
|
| | | //调用接口,绑定网关(即使失败,也返回true往下走)
|
| | | var bindGateway = new BindGatewayPra();
|
| | | string gwID = this.GetGatewayId(zbGateway); |
| | | bindGateway.BindGateways.Add(gwID);
|
| | | bindGateway.BindGateways.Add(zbGateway.GwId);
|
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); |
| | | |
| | |
| | | /// <returns></returns>
|
| | | public bool HomeIdIsEmpty(ZbGateway zbGateway)
|
| | | {
|
| | | return this.HomeIdIsEmpty(zbGateway.getGatewayBaseInfo.HomeId);
|
| | | return this.HomeIdIsEmpty(zbGateway.HomeId);
|
| | | } |
| | | |
| | | /// <summary>
|
| | |
| | | }
|
| | |
|
| | | //是否已经存在
|
| | | string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
|
| | | string gwID = zbGateway.GwId;
|
| | | bool isEsist = HdlGatewayLogic.Current.IsGatewayExist(zbGateway); |
| | | if (isEsist == false)
|
| | | {
|
| | |
| | |
|
| | | //刷新的是缓存,不刷新真实物理网关
|
| | | this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
|
| | | this.dicGateway[gwID].getGwInfo = result.getGwData;
|
| | | this.dicGateway[gwID].getGatewayBaseInfo.GwName = result.getGwData.GwName;
|
| | | this.dicGateway[gwID].getGatewayBaseInfo.IpAddress = result.getGwData.GwIP;
|
| | | this.dicGateway[gwID].getGatewayBaseInfo.HomeId = Common.Config.Instance.HomeId;
|
| | | this.dicGateway[gwID].ReSave();
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result.getGwData);
|
| | | //顺便这个变量也设置一下
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result.getGwData, false);
|
| | |
|
| | | if (isEsist == false)
|
| | | {
|
| | | //添加备份
|
| | |
| | | }
|
| | |
|
| | | //修改缓存
|
| | | string gwID = this.GetGatewayId(zbGateway); |
| | | this.dicGateway[gwID].getGatewayBaseInfo.GwName = gatewayName; |
| | | string gwID = zbGateway.GwId; |
| | | this.dicGateway[gwID].GwName = gatewayName; |
| | | this.dicGateway[gwID].ReSave();
|
| | |
|
| | | //添加自动备份
|
| | |
| | | if (this.GetRealGateway(ref realWay, gatewayId) == true)
|
| | | {
|
| | | //重新设置住宅ID(这个应该是不经过APP,直接把网关恢复了出厂设置)
|
| | | if (this.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true)
|
| | | if (this.HomeIdIsEmpty(realWay.HomeId) == true)
|
| | | {
|
| | | int result2 = await this.ReBindNewGateway(realWay);
|
| | | if (result2 == 0)
|
| | |
| | | /// <param name="zbGateway"></param> |
| | | public async Task<bool> DeleteGateway(ZbGateway zbGateway) |
| | | { |
| | | string gwID = this.GetGatewayId(zbGateway); |
| | | //移除本地网关信息 |
| | | return await this.DeleteGateway(gwID); |
| | | return await this.DeleteGateway(zbGateway.GwId); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | this.DeleteGatewayFile(zbGatewayID); |
| | | |
| | | //移除 |
| | | ZbGateway.GateWayList.RemoveAll((obj) => this.GetGatewayId(obj) == zbGatewayID); |
| | | ZbGateway.GateWayList.RemoveAll((obj) => obj.GwId == zbGatewayID); |
| | | //断开mqtt连接 |
| | | realWay.DisConnectLocalMqttClient("GD"); |
| | | |
| | |
| | | //刷新缓存的在线标识
|
| | | foreach (var zbway in listRealWay)
|
| | | {
|
| | | string gwID = this.GetGatewayId(zbway);
|
| | | string gwID = zbway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwID) == false)
|
| | | {
|
| | | continue;
|
| | |
| | | }
|
| | | foreach (var way in listGateway)
|
| | | {
|
| | | if (way == null || way.getGatewayBaseInfo == null)
|
| | | if (way == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | string strId = this.GetGatewayId(way);
|
| | | string strId = way.GwId;
|
| | | if (dicDbGateway.ContainsKey(strId) == true) //如果云端上面有这个网关
|
| | | {
|
| | | way.GatewayOnlineFlage = dicDbGateway[strId].MqttOnlineStatus;
|
| | |
| | | return false;
|
| | | }
|
| | | //使用缓存的,因为刷新在线状态的时候,刷新的就是缓存,而不是真实物理网关
|
| | | string gwID = this.GetGatewayId(zbGateway);
|
| | | string gwID = zbGateway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwID) == true)
|
| | | {
|
| | | return this.dicGateway[gwID].GatewayOnlineFlage;
|
| | |
| | | List<ZbGateway> newlist = new List<ZbGateway>();
|
| | | foreach (var way in list)
|
| | | {
|
| | | if (Config.Instance.HomeId != way.getGatewayBaseInfo.HomeId)
|
| | | if (Config.Instance.HomeId != way.HomeId)
|
| | | {
|
| | | //如果不是当前住宅
|
| | | continue;
|
| | | }
|
| | | string gwID = this.GetGatewayId(way);
|
| | | string gwID = way.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwID) == false)
|
| | | {
|
| | | //如果本地并没有这个网关
|
| | |
| | | /// <returns></returns> |
| | | public bool GetRealGateway(ref ZbGateway zbGateway, ZbGateway tagartWay)
|
| | | {
|
| | | if (tagartWay == null || tagartWay.getGatewayBaseInfo == null)
|
| | | if (tagartWay == null)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | return this.GetRealGateway(ref zbGateway, this.GetGatewayId(tagartWay));
|
| | | return this.GetRealGateway(ref zbGateway, tagartWay.GwId);
|
| | | } |
| | | |
| | | /// <summary>
|
| | |
| | | {
|
| | | var realWay = ZbGateway.GateWayList.Find((obj) =>
|
| | | {
|
| | | return this.GetGatewayId(obj) == gwId;
|
| | | return obj.GwId == gwId;
|
| | | });
|
| | | if (realWay == null)
|
| | | {
|
| | | //如果网关对象丢失了,则创建个新的
|
| | | realWay = new ZbGateway { IsVirtual = true, }; |
| | | realWay.getGatewayBaseInfo.gwID = gwId; |
| | | realWay.getGatewayBaseInfo.HomeId = Shared.Common.Config.Instance.HomeId; |
| | | realWay.GwId = gwId; |
| | | realWay.HomeId = Shared.Common.Config.Instance.HomeId; |
| | | ZbGateway.GateWayList.Add(realWay); |
| | | }
|
| | | zbGateway = realWay;
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取网关GwInfo里面的属性___________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关GwInfo里面的属性
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="attributeName">getGwInfo里面属性的名字</param>
|
| | | /// <param name="defult">如果获取不到时,设置的默认值</param>
|
| | | /// <returns></returns>
|
| | | public object GetGwInfoAttribute(ZbGateway zbGateway, string attributeName, string defult = "")
|
| | | {
|
| | | string gwID = this.GetGatewayId(zbGateway);
|
| | | var localWay = this.GetLocalGateway(gwID);
|
| | |
|
| | | object objValue = null;
|
| | | if (localWay == null || localWay.getGwInfo == null)
|
| | | {
|
| | | //本地没有记录有这个东西,则直接返回参数的数据
|
| | | if (zbGateway.getGwInfo != null)
|
| | | {
|
| | | objValue = zbGateway.getGwInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, zbGateway.getGwInfo, null);
|
| | | }
|
| | | else
|
| | | {
|
| | | return defult;
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | //获取本地的属性 |
| | | objValue = localWay.getGwInfo.GetType().InvokeMember(attributeName, System.Reflection.BindingFlags.GetField, null, localWay.getGwInfo, null);
|
| | | }
|
| | |
|
| | | if (objValue == null)
|
| | | {
|
| | | return defult;
|
| | | }
|
| | | return objValue;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取网关ID(有特殊意义)_____________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关对象里面的网关ID(封装这个方法有特殊意义)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <returns></returns>
|
| | | public string GetGatewayId(ZbGateway zbGateway)
|
| | | {
|
| | | //这个东西不会为空
|
| | | return zbGateway.getGatewayBaseInfo.gwID;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取名称___________________________
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <returns></returns>
|
| | | public string GetGatewayName(ZbGateway zbGateway, GetNameMode mode = GetNameMode.SpecialGateway)
|
| | | {
|
| | | string gwId = this.GetGatewayId(zbGateway);
|
| | | string gwId = zbGateway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwId) == false)
|
| | | {
|
| | | return zbGateway.getGatewayBaseInfo.GwName == null ? string.Empty : zbGateway.getGatewayBaseInfo.GwName;
|
| | | return zbGateway.GwName;
|
| | | }
|
| | | var localWay = this.dicGateway[gwId];
|
| | |
|
| | |
| | | return name;
|
| | | }
|
| | |
|
| | | if (mode == GetNameMode.SpecialGateway && localWay.getGwInfo != null)
|
| | | if (mode == GetNameMode.SpecialGateway)
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString();
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + localWay.LinuxImageType;
|
| | | if (LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //没有名称时,则使用R文件里面设置的默认设备名称
|
| | |
| | | {
|
| | | return string.Empty;
|
| | | }
|
| | | return zbGateway.getGatewayBaseInfo.GwName;
|
| | | return zbGateway.GwName;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | //初始值:无法识别的网关设备
|
| | | button.TextID = R.MyInternationalizationString.uUnDistinguishTheGatewayDevice;
|
| | |
|
| | | string gwId = this.GetGatewayId(zbGateway);
|
| | | if (this.dicGateway.ContainsKey(gwId) == false || this.dicGateway[gwId].getGwInfo == null)
|
| | | string gwId = zbGateway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwId) == false)
|
| | | {
|
| | | //如果这个网关没有信息,则从新获取
|
| | | if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
|
| | | if (zbGateway.LinuxImageType != -1)
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | |
| | | var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | zbGateway.getGwInfo = result;
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
|
| | |
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].getGwInfo.LinuxImageType;
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | string gwID = this.GetGatewayId(zbGateway);
|
| | | string gwID = zbGateway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwID) == true)
|
| | | {
|
| | | //刷新缓存
|
| | | ZbGateway localWay = this.dicGateway[gwID];
|
| | | localWay.getGwInfo = imageTypeResult.getGwData;
|
| | | localWay.getGatewayBaseInfo.GwName = imageTypeResult.getGwData.GwName;
|
| | | localWay.getGatewayBaseInfo.IpAddress = imageTypeResult.getGwData.GwIP;
|
| | |
|
| | | localWay.ReSave();
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(localWay, imageTypeResult.getGwData);
|
| | | }
|
| | | //顺便这个变量也设置一下
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, imageTypeResult.getGwData, false);
|
| | |
|
| | | return imageTypeResult.getGwData;
|
| | | }
|
| | |
| | | return result;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将网关的数据设置到本地缓存中
|
| | | /// </summary>
|
| | | /// <param name="localWay">本地网关</param>
|
| | | /// <param name="data">网关数据</param>
|
| | | /// <param name="saveFile">是否保存文件</param>
|
| | | private void SetGatewayDataToLocalMemmory(ZbGateway localWay, ZbGatewayData.GetGwData data, bool saveFile = true)
|
| | | {
|
| | | localWay.GwId = data.GwId;
|
| | | localWay.GwName = data.GwName;
|
| | | localWay.GwSerialNum = data.GWSN;
|
| | | localWay.IsMainGateWay = data.IsDominant == 1 ? true : false;
|
| | | localWay.GwIP = data.GwIP;
|
| | | localWay.LinuxImageType = data.LinuxImageType;
|
| | | localWay.LinuxHardVersion = data.LinuxHWVersion;
|
| | | localWay.LinuxFirmwareVersion = data.LinuxFWVersion;
|
| | | localWay.CoordinatorHardVersion = data.ZbHWVersion;
|
| | | localWay.CoordinatorFirmwareVersion = data.ZbFWVersion;
|
| | | localWay.CoordinatorImageId = data.ZbImageType;
|
| | | localWay.DriveCodeList = data.DriveCodeList;
|
| | | if (saveFile == true)
|
| | | {
|
| | | localWay.ReSave();
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 网关房间相关_______________________
|
| | |
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(ZbGateway zbGateway)
|
| | | {
|
| | | var gatewayId = this.GetGatewayId(zbGateway);
|
| | | return this.GetRoomByGateway(gatewayId);
|
| | | return this.GetRoomByGateway(zbGateway.GwId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="roomId">房间ID</param>
|
| | | public void ChangedGatewayRoom(ZbGateway zbGateway, string roomId)
|
| | | {
|
| | | var gatewayId = this.GetGatewayId(zbGateway);
|
| | | var localGateway = this.GetLocalGateway(gatewayId);
|
| | | var localGateway = this.GetLocalGateway(zbGateway.GwId);
|
| | | if (localGateway != null)
|
| | | {
|
| | | localGateway.RoomId = roomId;
|
| | |
| | | return null;
|
| | | }
|
| | | //使用本地缓存对象
|
| | | string gwID = this.GetGatewayId(zbGateway);
|
| | | var localWay = this.GetLocalGateway(gwID);
|
| | | var localWay = this.GetLocalGateway(zbGateway.GwId);
|
| | | if (localWay == null)
|
| | | {
|
| | | return null;
|
| | | } |
| | | |
| | | //添加网关的升级固件(成不成功都无所谓) |
| | | var flage = await HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.Linux,
|
| | | this.GetGwInfoAttribute(localWay, "LinuxHWVersion").ToString(),
|
| | | this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString());
|
| | | var flage = HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.Linux,
|
| | | localWay.LinuxHardVersion.ToString(),
|
| | | localWay.LinuxImageType.ToString());
|
| | |
|
| | | //添加协调器的升级固件(成不成功都无所谓)
|
| | | flage = await HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.Coordinator,
|
| | | this.GetGwInfoAttribute(localWay, "ZbHWVersion").ToString(),
|
| | | this.GetGwInfoAttribute(localWay, "ZbImageType").ToString());
|
| | | flage = HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.Coordinator,
|
| | | localWay.CoordinatorHardVersion.ToString(),
|
| | | localWay.CoordinatorImageId.ToString());
|
| | |
|
| | | //网关的版本
|
| | | var gatewayFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.Linux,
|
| | | this.GetGwInfoAttribute(localWay, "LinuxHWVersion").ToString(),
|
| | | this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString(),
|
| | | Convert.ToInt32(this.GetGwInfoAttribute(localWay, "LinuxFWVersion")));
|
| | | localWay.LinuxHardVersion.ToString(),
|
| | | localWay.LinuxImageType.ToString(),
|
| | | localWay.LinuxFirmwareVersion);
|
| | |
|
| | | //协调器版本
|
| | | var coordinatorFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.Coordinator,
|
| | | this.GetGwInfoAttribute(localWay, "ZbHWVersion").ToString(),
|
| | | this.GetGwInfoAttribute(localWay, "ZbImageType").ToString(),
|
| | | Convert.ToInt32(this.GetGwInfoAttribute(localWay, "ZbFWVersion")));
|
| | | localWay.CoordinatorHardVersion.ToString(),
|
| | | localWay.CoordinatorImageId.ToString(),
|
| | | localWay.CoordinatorFirmwareVersion);
|
| | |
|
| | | var list = new List<FirmwareVersionInfo>();
|
| | | list.Add(gatewayFirmware);
|
| | | list.Add(coordinatorFirmware);
|
| | |
|
| | | //这个网关需要有虚拟驱动这个东西才行
|
| | | string linImage = this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString();
|
| | | if (linImage != "6")
|
| | | if (localWay.LinuxImageType != 6)
|
| | | {
|
| | | //虚拟驱动号
|
| | | var listvVode = await HdlGatewayLogic.Current.GetListVDDriveCode(localWay);
|
| | | if (listvVode != null && listvVode.Count > 0)
|
| | | foreach (var data in localWay.DriveCodeList)
|
| | | {
|
| | | foreach (var data in listvVode)
|
| | | //添加虚拟驱动的升级固件(成不成功都无所谓)
|
| | | flage = HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString());
|
| | |
|
| | | //虚拟驱动
|
| | | var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString(),
|
| | | data.DriveFwVersion);
|
| | |
|
| | | if (virtualFirmware != null)
|
| | | {
|
| | | //添加虚拟驱动的升级固件(成不成功都无所谓)
|
| | | flage = await HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString());
|
| | |
|
| | | //虚拟驱动
|
| | | var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString(),
|
| | | data.DriveFwVersion);
|
| | |
|
| | | if (virtualFirmware != null)
|
| | | {
|
| | | virtualFirmware.VirtualCode = data.DriveCode;
|
| | | list.Add(virtualFirmware);
|
| | | }
|
| | | virtualFirmware.VirtualCode = data.DriveCode;
|
| | | list.Add(virtualFirmware);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <returns></returns>
|
| | | public async Task<List<ZbGatewayData.DriveCodeObj>> GetListVDDriveCode(ZbGateway zbGateway)
|
| | | public List<ZbGatewayData.DriveCodeObj> GetListVDDriveCode(ZbGateway zbGateway)
|
| | | {
|
| | | ZbGateway zbTemp = null;
|
| | | if (this.GetRealGateway(ref zbTemp, zbGateway) == false)
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 505 } };
|
| | | var result = this.SendJobjectDataToGateway(zbGateway, "VirtualDrive/CatDriveCode", jObject.ToString(), "VirtualDrive/CatDriveCode_Respon");
|
| | | if (result.ErrorMsg != null)
|
| | | {
|
| | | this.ShowTipMsg(result.ErrorMsg);
|
| | | }
|
| | | if (result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | var result = await zbTemp.CheckVDDriveCodeAsync();
|
| | | //检测网关返回的共通错误状态码
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowTipMsg(error);
|
| | | return null;
|
| | | }
|
| | |
|
| | | if (result == null || result.vDriveDriveCodeResponData == null || result.vDriveDriveCodeResponData.DriveCodeList == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | if (result.vDriveDriveCodeResponData.DriveCodeList.Count > 0)
|
| | | {
|
| | | return result.vDriveDriveCodeResponData.DriveCodeList;
|
| | | }
|
| | | return null;
|
| | | var dataInfo = JsonConvert.DeserializeObject<ZbGatewayData.VDriveDriveCodeResponData>(result.ReceiptData);
|
| | | return dataInfo.DriveCodeList;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <returns></returns>
|
| | | public int IsMainGateway(ZbGateway zbGateway)
|
| | | {
|
| | | string gwID = this.GetGatewayId(zbGateway);
|
| | | return this.IsMainGateway(gwID);
|
| | | return this.IsMainGateway(zbGateway.GwId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="zbGateway"></param>
|
| | | public void SetRealGatewayPictrue(Button button, ZbGateway zbGateway)
|
| | | {
|
| | | string gwID = this.GetGatewayId(zbGateway);
|
| | | var localWay = this.GetLocalGateway(gwID);
|
| | | if (localWay == null || localWay.getGwInfo == null)
|
| | | var localWay = this.GetLocalGateway(zbGateway.GwId);
|
| | | if (localWay == null)
|
| | | {
|
| | | if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
|
| | | if (zbGateway.LinuxImageType != -1)
|
| | | {
|
| | | button.UnSelectedImagePath = "Gateway/RealGateway" + zbGateway.getGwInfo.LinuxImageType + ".png";
|
| | | button.UnSelectedImagePath = "Gateway/RealGateway" + zbGateway.LinuxImageType + ".png";
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | zbGateway.getGwInfo = result;
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | button.UnSelectedImagePath = "Gateway/RealGateway" + result.LinuxImageType + ".png";
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | button.UnSelectedImagePath = "Gateway/RealGateway" + localWay.getGwInfo.LinuxImageType + ".png";
|
| | | button.UnSelectedImagePath = "Gateway/RealGateway" + localWay.LinuxImageType + ".png";
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | /// <param name="zbGateway"></param>
|
| | | public void SetGatewayIcon(Button button, ZbGateway zbGateway)
|
| | | {
|
| | | string gwID = this.GetGatewayId(zbGateway);
|
| | | var localWay = this.GetLocalGateway(gwID);
|
| | | if (localWay == null || localWay.getGwInfo == null)
|
| | | var localWay = this.GetLocalGateway(zbGateway.GwId);
|
| | | if (localWay == null)
|
| | | {
|
| | | if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
|
| | | if (zbGateway.LinuxImageType != -1)
|
| | | {
|
| | | button.UnSelectedImagePath = "Gateway/GatewayIcon" + zbGateway.getGwInfo.LinuxImageType + ".png";
|
| | | button.UnSelectedImagePath = "Gateway/GatewayIcon" + zbGateway.LinuxImageType + ".png";
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | var result = await this.GetGatewayNewInfoAsync(zbGateway, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | zbGateway.getGwInfo = result;
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | button.UnSelectedImagePath = "Gateway/GatewayIcon" + result.LinuxImageType + ".png";
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | button.UnSelectedImagePath = "Gateway/GatewayIcon" + localWay.getGwInfo.LinuxImageType + ".png";
|
| | | button.UnSelectedImagePath = "Gateway/GatewayIcon" + localWay.LinuxImageType + ".png";
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | /// <returns></returns>
|
| | | public bool IsGatewayExist(ZbGateway zbGateway)
|
| | | {
|
| | | string gwID = this.GetGatewayId(zbGateway);
|
| | | return this.IsGatewayExist(gwID);
|
| | | return this.IsGatewayExist(zbGateway.GwId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="zbGateway"></param>
|
| | | public void BackupGatewayIdOnNotNetwork(ZbGateway zbGateway)
|
| | | {
|
| | | var strId = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
|
| | | var strId = zbGateway.GwId;
|
| | | if (listBackupGwId.Contains(strId) == false)
|
| | | {
|
| | | listBackupGwId.Add(strId);
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 上传设备备份到网关_________________
|
| | | #region ■ 发送网关命令给网关_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 上传设备备份到网关(废弃)
|
| | | /// 发送数据到网关,并接受网关返回的数据(ReceiptData为返回值)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="backupEnum">备份类型</param>
|
| | | /// <param name="upLaodData">备份的数据</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> UpLoadDeviceBackupDataToGateway(CommonDevice device, object upLaodData)
|
| | | /// <param name="gateway">网关对象</param>
|
| | | /// <param name="sendTopic">发送的主题</param>
|
| | | /// <param name="sendData">需要发送的数据 JObject.ToString()的东西</param>
|
| | | /// <param name="receiptTopic">指定接收哪个主题</param>
|
| | | /// <param name="waitTime">超时时间(秒)</param>
|
| | | /// <returns>网关返回的数据</returns>
|
| | | public ReceiptGatewayResult SendJobjectDataToGateway(ZbGateway gateway, string sendTopic, string sendData, string receiptTopic, int waitTime = 5)
|
| | | {
|
| | | //ZbGateway realWay = null;
|
| | | //if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false)
|
| | | //{
|
| | | // //没有找到真实物理网关
|
| | | // return false;
|
| | | //}
|
| | | //string fileName = device.FilePath + ((int)backupEnum).ToString().PadLeft(5, '0');
|
| | | ////创建文件对象
|
| | | //var result = await realWay.CreateFileAsync(fileName);
|
| | | //if (result == null || result.Result != 0)
|
| | | //{
|
| | | // return false;
|
| | | //}
|
| | | ////发送数据流
|
| | | //var data = Newtonsoft.Json.JsonConvert.SerializeObject(upLaodData);
|
| | | //var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | | //var result2 = await realWay.SendFileAsync(byteData);
|
| | | //if (result2 == null || result2.Result != 0)
|
| | | //{
|
| | | // return false;
|
| | | //}
|
| | | return true;
|
| | | var reResult = new ReceiptGatewayResult();
|
| | |
|
| | | ZbGateway myGateway = null;
|
| | | if (this.GetRealGateway(ref myGateway, gateway) == false)
|
| | | {
|
| | | //获取网关对象失败
|
| | | reResult.ErrorMsg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail);
|
| | | reResult.ErrorMsgDiv = -1;
|
| | | return reResult;
|
| | | }
|
| | | //网关ID
|
| | | string gatewayID = gateway.GwId;
|
| | | //错误主题
|
| | | string errorTopic = gatewayID + "/" + "Error_Respon";
|
| | | //检测对象的主题
|
| | | string checkTopic = gatewayID + "/" + receiptTopic;
|
| | |
|
| | | Action<string, string> receiptAction = (topic, message) =>
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | |
|
| | | //网关回复错误
|
| | | if (topic == errorTopic)
|
| | | {
|
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
| | | reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
|
| | | }
|
| | | //如果是指定的主题
|
| | | if (topic == checkTopic)
|
| | | {
|
| | | reResult.ReceiptData = jobject["Data"].ToString();
|
| | | }
|
| | | };
|
| | | myGateway.Actions += receiptAction;
|
| | | //发送数据
|
| | | myGateway.Send(sendTopic, sendData);
|
| | |
|
| | | //超时时间
|
| | | int TimeOut = 0;
|
| | | waitTime = 20 * waitTime;
|
| | | while (reResult.ReceiptData == null && TimeOut < waitTime)
|
| | | {
|
| | | //全部接收才退出
|
| | | System.Threading.Thread.Sleep(50);
|
| | | TimeOut++;
|
| | | }
|
| | | myGateway.Actions -= receiptAction;
|
| | | receiptAction = null;
|
| | | if (reResult.ReceiptData == null)
|
| | | {
|
| | | reResult.ErrorMsgDiv = 0;
|
| | | }
|
| | |
|
| | | return reResult;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | {
|
| | | int waitCount = 0;
|
| | | //如果住宅ID变更了,则不再处理
|
| | | while (frameLayout.Parent != null)
|
| | | while (frameLayout.Parent != null && Config.Instance.HomeId != string.Empty)
|
| | | {
|
| | | System.Threading.Thread.Sleep(1000);
|
| | | if (this.hadGatewayUpdate == true)
|
| | |
| | | //等个2秒
|
| | | System.Threading.Thread.Sleep(2000);
|
| | |
|
| | | //2020.05.25追加:此住宅是否拥有网关在线
|
| | | var hadGwOnline = false;
|
| | | foreach (var way in list)
|
| | | {
|
| | | string gwId = this.GetGatewayId(way);
|
| | | if (dicOldOnline.ContainsKey(way.GwId) == true)
|
| | | {
|
| | | if (way.GatewayOnlineFlage == true)
|
| | | {
|
| | | //有一个网关在线,即在线
|
| | | hadGwOnline = true;
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | foreach (var way in list)
|
| | | {
|
| | | string gwId = way.GwId;
|
| | | if (dicOldOnline.ContainsKey(gwId) == true)
|
| | | {
|
| | | //网关也不多,直接推送吧
|
| | | this.PushGatewayOnlineStatuToForm(gwId, way.GatewayOnlineFlage);
|
| | | this.PushGatewayOnlineStatuToForm(gwId, way.GatewayOnlineFlage, hadGwOnline);
|
| | | }
|
| | | else
|
| | | {
|
| | | //没有包含,默认为false
|
| | | this.PushGatewayOnlineStatuToForm(gwId, false);
|
| | | this.PushGatewayOnlineStatuToForm(gwId, false, hadGwOnline);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | dicDbGateway = new Dictionary<string, GatewayResult>();
|
| | | }
|
| | |
|
| | | //2020.05.25追加:此住宅是否拥有网关在线
|
| | | var hadGwOnline = false;
|
| | | foreach (var gwId in dicOldOnline.Keys)
|
| | | {
|
| | | //如果云端上面有这个网关
|
| | | if (dicDbGateway.ContainsKey(gwId) == true
|
| | | && dicDbGateway[gwId].MqttOnlineStatus == true)
|
| | | {
|
| | | //有一个网关在线,即在线
|
| | | hadGwOnline = true;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | foreach (var gwId in dicOldOnline.Keys)
|
| | | {
|
| | | //如果云端上面有这个网关
|
| | | if (dicDbGateway.ContainsKey(gwId) == true)
|
| | | {
|
| | | //网关也不多,直接推送
|
| | | this.PushGatewayOnlineStatuToForm(gwId, dicDbGateway[gwId].MqttOnlineStatus);
|
| | | this.PushGatewayOnlineStatuToForm(gwId, dicDbGateway[gwId].MqttOnlineStatus, hadGwOnline);
|
| | | }
|
| | | else
|
| | | {
|
| | | //云端不包含的,当不在线处理
|
| | | this.PushGatewayOnlineStatuToForm(gwId, false);
|
| | | this.PushGatewayOnlineStatuToForm(gwId, false, hadGwOnline);
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | foreach (var zbway in this.dicGateway.Values)
|
| | | {
|
| | | //获取前回的在线状态
|
| | | string gwId = this.GetGatewayId(zbway);
|
| | | dicOldOnline[gwId] = zbway.GatewayOnlineFlage;
|
| | | dicOldOnline[zbway.GwId] = zbway.GatewayOnlineFlage;
|
| | | }
|
| | | return dicOldOnline;
|
| | | }
|
| | |
| | | /// </summary>
|
| | | /// <param name="gwId"></param>
|
| | | /// <param name="online"></param>
|
| | | private void PushGatewayOnlineStatuToForm(string gwId, bool online)
|
| | | /// <param name="hadGwOnline">2020.05.25追加:此住宅是否拥有网关在线</param>
|
| | | private void PushGatewayOnlineStatuToForm(string gwId, bool online, bool hadGwOnline)
|
| | | {
|
| | | try
|
| | | {
|
| | |
| | | }
|
| | | //网关在线推送
|
| | | var zbway = this.GetLocalGateway(gwId);
|
| | | zbway.GatewayOnlineFlage = online;
|
| | |
|
| | | UserCenterResourse.DicActionForm[formId]?.GatewayOnlinePush(zbway, online);
|
| | | if (zbway != null)
|
| | | {
|
| | | //切换住宅时,这个东西有可能是null
|
| | | zbway.GatewayOnlineFlage = online;
|
| | | UserCenterResourse.DicActionForm[formId]?.GatewayOnlinePush(zbway, online, hadGwOnline);
|
| | | }
|
| | | }
|
| | | }
|
| | | catch { }
|