| | |
| | | GatewayResourse.AppOldSelectGatewayId = string.Empty;
|
| | |
|
| | | //从文件中获取上一次选择的网关id
|
| | | byte[] data = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AppOldSelectGatewayFile);
|
| | | byte[] data = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.AppOldSelectGatewayFile);
|
| | | if (data != null)
|
| | | {
|
| | | string strvalue = System.Text.Encoding.UTF8.GetString(data);
|
| | |
| | | }
|
| | |
|
| | | List<string> listBackupGwId = new List<string>();
|
| | | var fileData = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile);
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
|
| | | if (fileData != null)
|
| | | {
|
| | | //新增:虽然概率低,但是确实发生了。如果有网络时,App重新绑定记录的网关失败的话
|
| | |
| | | //删除网关文件
|
| | | this.DeleteGatewayFile(gatewayId);
|
| | | }
|
| | | //LOG输出
|
| | | if (listDelete.Count > 0)
|
| | | //如果网关都没了的话,把场景全部删了
|
| | | if (listDelete.Count > 0 && this.GetAllLocalGateway().Count == 0)
|
| | | {
|
| | | string msg = "本地拥有的网关:";
|
| | | foreach (var gatewayId in this.dicGateway.Keys)
|
| | | {
|
| | | msg += gatewayId + ",";
|
| | | }
|
| | | msg += "\r\n被删除的网关:";
|
| | | foreach (var gatewayId in listDelete)
|
| | | {
|
| | | msg += gatewayId + ",";
|
| | | }
|
| | | msg += "\r\n此时云端返回当前账号所绑定有的网关:";
|
| | | foreach (var gatewayId in result.Keys)
|
| | | {
|
| | | msg += gatewayId + ",";
|
| | | }
|
| | | var bytes = System.Text.Encoding.UTF8.GetBytes(msg);
|
| | | Common.Global.WriteFileByBytesByHomeId("GatewayDeleteLog.txt", bytes);
|
| | | HdlSceneLogic.Current.DeleteAllLocalScene();
|
| | | }
|
| | | } |
| | | |
| | |
| | | return false;
|
| | | } |
| | | //添加网关的话,强制主页刷新 |
| | | UserView.UserPage.Instance.RefreshForm = true; |
| | | UserView.UserPage.Instance.RefreshAllForm = true; |
| | | |
| | | return true; |
| | | }
|
| | |
| | | return -1;
|
| | | }
|
| | | //获取网关的信息
|
| | | var result = await zbGateway.GetZbGwInfoAsync();
|
| | | //检测网关返回的共通错误状态码
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | this.ShowTipMsg(error);
|
| | | }
|
| | | return -1;
|
| | | }
|
| | |
|
| | | var result = this.GetGatewayInfo(zbGateway, true, mode);
|
| | | if (result == null)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | |
| | | return -1;
|
| | | }
|
| | |
|
| | | if (result.getGwData == null)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | //获取网关信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return -1;
|
| | | }
|
| | |
|
| | | //设置住宅ID到网关
|
| | | bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
|
| | | if (flage2 == false)
|
| | | if (result.HomeId != Common.Config.Instance.HomeId)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | | bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
|
| | | if (flage2 == false)
|
| | | {
|
| | | //向网关设置住宅ID失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
|
| | | this.ShowTipMsg(msg);
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | //向网关设置住宅ID失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return -1;
|
| | | }
|
| | | return -1;
|
| | | }
|
| | |
|
| | | //更新云端数据库
|
| | |
| | | //刷新的是缓存,不刷新真实物理网关
|
| | | this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result.getGwData);
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
|
| | | //顺便这个变量也设置一下
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result.getGwData, false);
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
|
| | |
|
| | | if (isEsist == false)
|
| | | {
|
| | |
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); |
| | | |
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway); |
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }); |
| | | if (result == "Error")
|
| | | {
|
| | | return -1;
|
| | |
| | | await Task.Delay(8000);
|
| | |
|
| | | //获取网关的信息
|
| | | ZbGatewayData.GetGwAllData result = null;
|
| | | ZbGatewayData.GetGwData result = null;
|
| | | int count = 5;
|
| | | while (count >= 0)
|
| | | {
|
| | | result = await zbGateway.GetZbGwInfoAsync();
|
| | | if (result != null && result.getGwData != null)
|
| | | result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | break;
|
| | | }
|
| | |
| | | //最多再等20秒
|
| | | await Task.Delay(4000);
|
| | | }
|
| | | //检测网关返回的共通错误状态码
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowTipMsg(error);
|
| | | return -1;
|
| | | }
|
| | |
|
| | | if (result == null || result.getGwData == null)
|
| | | if (result == null)
|
| | | {
|
| | | //获取网关信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
|
| | |
| | | //刷新的是缓存,不刷新真实物理网关
|
| | | this.dicGateway[gwID].GatewayOnlineFlage = zbGateway.GatewayOnlineFlage;
|
| | | //将网关的数据设置到本地缓存中
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result.getGwData);
|
| | | this.SetGatewayDataToLocalMemmory(this.dicGateway[gwID], result);
|
| | | //顺便这个变量也设置一下
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result.getGwData, false);
|
| | | this.SetGatewayDataToLocalMemmory(zbGateway, result, false);
|
| | |
|
| | | if (isEsist == false)
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | //添加网关的话,强制主页刷新
|
| | | UserView.UserPage.Instance.RefreshForm = true;
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | |
|
| | | return 1; |
| | | } |
| | |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关对象</param> |
| | | /// <param name="gatewayName">网关名</param> |
| | | public async Task<bool> ReName(ZbGateway zbGateway, string gatewayName) |
| | | public bool ReName(ZbGateway zbGateway, string gatewayName) |
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, zbGateway) == false)
|
| | | //只取32个byte
|
| | | var bytes = new byte[32];
|
| | | var reamarkGwBytes = System.Text.Encoding.UTF8.GetBytes(gatewayName);
|
| | | System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 32 < reamarkGwBytes.Length ? 32 : reamarkGwBytes.Length);
|
| | | gatewayName = System.Text.Encoding.UTF8.GetString(bytes);
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 91 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "GwName", gatewayName } };
|
| | | jObject.Add("Data", data);
|
| | | var result = this.SendJobjectDataToGateway(zbGateway, "GwReName", jObject.ToString(), "GwReName_Respon");
|
| | | if (result.ErrorMsg != null)
|
| | | {
|
| | | //获取网关对象失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail); |
| | | this.ShowErrorMsg(msg);
|
| | | this.ShowTipMsg(result.ErrorMsg);
|
| | | return false;
|
| | | }
|
| | |
|
| | | var result = await realWay.GwReNameAsync(gatewayName);
|
| | | //检测网关返回的共通错误状态码
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (result == null)
|
| | | if (result.ErrorMsgDiv == 0)
|
| | | {
|
| | | //网关名称修改失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGatewayReNameFail);
|
| | | |
| | | this.ShowErrorMsg(msg); |
| | | return false;
|
| | | } |
| | | |
| | | //网关修改失败 |
| | | if (result.gwReNameData == null) |
| | | { |
| | | //网关名称修改失败 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGatewayReNameFail);
|
| | | |
| | | this.ShowErrorMsg(msg); |
| | | //网关回复超时 |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | this.ShowTipMsg(msg); |
| | | return false; |
| | | }
|
| | |
|
| | |
| | | public async Task<bool> DoSwitchGateway(string gatewayId)
|
| | | {
|
| | | var zbGateway = this.GetLocalGateway(gatewayId);
|
| | | if (this.CheckGatewayOnlineByFlag(zbGateway) == true)
|
| | |
|
| | | //重新获取在线网关的信息
|
| | | var result = await this.GetOnlineGatewayInfo(gatewayId);
|
| | | if (result == false)
|
| | | {
|
| | | //重新获取在线网关的信息
|
| | | var result = await this.GetOnlineGatewayInfo(gatewayId);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | //切换网关,保存缓存
|
| | | this.SaveGatewayIdToLocation(gatewayId);
|
| | | //切换网关的话,主页需要重新刷新
|
| | | UserView.UserPage.Instance.RefreshForm = true;
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | |
|
| | | return true;
|
| | | }
|
| | |
| | | if (getGatewayInfo == true)
|
| | | {
|
| | | //获取网关信息
|
| | | var info = this.GetGatewayInfo(realWay);
|
| | | var info = this.GetGatewayInfo(realWay, false);
|
| | | if (info == null)
|
| | | {
|
| | | //关闭进度条
|
| | |
| | | }
|
| | |
|
| | | //获取全部设备
|
| | | int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
|
| | | int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay, false);
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | if (result == -1)
|
| | |
| | | public void SaveGatewayIdToLocation(string gatewayId)
|
| | | {
|
| | | GatewayResourse.AppOldSelectGatewayId = gatewayId;
|
| | | byte[] data = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(GatewayResourse.AppOldSelectGatewayId));
|
| | | Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AppOldSelectGatewayFile, data);
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.AppOldSelectGatewayFile, GatewayResourse.AppOldSelectGatewayId);
|
| | | }
|
| | |
|
| | | #endregion |
| | |
| | | public async Task<bool> DeleteGateway(string zbGatewayID) |
| | | {
|
| | | ZbGateway realWay = null;
|
| | | bool hadReal = this.GetRealGateway(ref realWay, zbGatewayID);
|
| | |
|
| | | //暂不支持分享
|
| | | if (hadReal == true && realWay.GatewayOnlineFlage == true)
|
| | | this.GetRealGateway(ref realWay, zbGatewayID);
|
| | | //清空网关的住宅ID 网关解绑失败 不理它,因为网关可以按按键强制搜索得到
|
| | | if (realWay != null)
|
| | | {
|
| | | //清空网关的住宅ID
|
| | | bool result = await this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.YES);
|
| | | if (result == false)
|
| | | {
|
| | | //网关解绑失败 不理它,因为网关可以按按键强制搜索得到
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGatewayUnBindFail);
|
| | | //this.ShowErrorMsg(msg);
|
| | | //return false;
|
| | | }
|
| | | await this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO);
|
| | | }
|
| | |
|
| | | //删除云端的网关
|
| | |
| | | //移除 |
| | | ZbGateway.GateWayList.RemoveAll((obj) => obj.GwId == zbGatewayID); |
| | | //断开mqtt连接 |
| | | realWay.DisConnectLocalMqttClient("GD"); |
| | | if (realWay != null)
|
| | | {
|
| | | realWay.DisConnectLocalMqttClient("GD");
|
| | | } |
| | | |
| | | return true; |
| | | }
|
| | |
| | | public List<string> GetAllGatewayFile()
|
| | | {
|
| | | List<string> list = new List<string>();
|
| | | List<string> listFile = Global.FileListByHomeId();
|
| | | List<string> listFile = HdlFileLogic.Current.GetRootPathListFile();
|
| | | foreach (string file in listFile)
|
| | | {
|
| | | //只获取网关设备
|
| | |
| | | /// 获取网关加特效的名称
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <param name="mode"></param>
|
| | | /// <returns></returns>
|
| | | public string GetGatewayName(ZbGateway zbGateway, GetNameMode mode = GetNameMode.SpecialGateway)
|
| | | public string GetGatewayName(ZbGateway zbGateway)
|
| | | {
|
| | | if (zbGateway == null) { return string.Empty; }
|
| | |
|
| | | string gwId = zbGateway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwId) == false)
|
| | | {
|
| | |
| | | return name;
|
| | | }
|
| | |
|
| | | if (mode == GetNameMode.SpecialGateway)
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(localWay.LinuxImageType.ToString());
|
| | | if (nameContent != null)
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + localWay.LinuxImageType;
|
| | | if (LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //没有名称时,则使用R文件里面设置的默认设备名称
|
| | | return Language.StringByID(LocalDevice.Current.dicDeviceAllNameID[keyName] + 20000);
|
| | | }
|
| | | return nameContent.A备注名字;
|
| | | }
|
| | |
|
| | | return string.Empty;
|
| | |
| | | //如果这个网关没有信息,则从新获取
|
| | | if (zbGateway.LinuxImageType != -1)
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
|
| | | if (nameContent != null)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
|
| | | button.Text = nameContent.A官方名字;
|
| | | }
|
| | | }
|
| | | else
|
| | |
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | var result = this.GetGatewayInfo(zbGateway, ShowErrorMode.NO);
|
| | | var result = this.GetGatewayInfo(zbGateway, false, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | //将网关的数据设置到本地缓存中
|
| | |
| | |
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
|
| | | if (nameContent != null)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
|
| | | button.Text = nameContent.A官方名字;
|
| | | }
|
| | | });
|
| | | }
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
|
| | | if (nameContent != null)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = Common.LocalDevice.Current.dicDeviceAllNameID[keyName];
|
| | | button.Text = nameContent.A官方名字;
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | /// 获取网关信息(版本信息,镜像类型,基本信息等。只刷新本地网关的缓存)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <param name="useLocalConnect">是否强制使用本地连接发送</param>
|
| | | /// <param name="mode"></param>
|
| | | /// <returns></returns>
|
| | | public ZbGatewayData.GetGwData GetGatewayInfo(ZbGateway zbGateway, ShowErrorMode mode = ShowErrorMode.YES)
|
| | | public ZbGatewayData.GetGwData GetGatewayInfo(ZbGateway zbGateway, bool useLocalConnect, ShowErrorMode mode = ShowErrorMode.YES)
|
| | | {
|
| | | //获取网关版本信息
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 95 } };
|
| | | var result = this.SendJobjectDataToGateway(zbGateway, "GetZbGwInfo", jObject.ToString(), "GetZbGwInfo_Respon");
|
| | | var result = this.SendJobjectDataToGateway(zbGateway, "GetZbGwInfo", jObject.ToString(), "GetZbGwInfo_Respon", 5, useLocalConnect);
|
| | |
|
| | | if (result.ErrorMsgDiv != 1)
|
| | | {
|
| | |
| | | localWay.CoordinatorFirmwareVersion = data.ZbFWVersion;
|
| | | localWay.CoordinatorImageId = data.ZbImageType;
|
| | | localWay.DriveCodeList = data.DriveCodeList;
|
| | | localWay.GwVersionDate = data.AppVersion;
|
| | | if (saveFile == true)
|
| | | {
|
| | | localWay.ReSave();
|
| | |
| | | /// <summary>
|
| | | /// 变更网关房间
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="gwId">网关Id</param>
|
| | | /// <param name="roomId">房间ID</param>
|
| | | public void ChangedGatewayRoom(ZbGateway zbGateway, string roomId)
|
| | | public void ChangedGatewayRoom(string gwId, string roomId)
|
| | | {
|
| | | var localGateway = this.GetLocalGateway(zbGateway.GwId);
|
| | | var localGateway = this.GetLocalGateway(gwId);
|
| | | if (localGateway != null)
|
| | | {
|
| | | localGateway.RoomId = roomId;
|
| | |
| | | public List<FirmwareVersionInfo> GetGatewayAllNewVersion(ZbGateway zbGateway, ShowErrorMode mode = ShowErrorMode.YES)
|
| | | {
|
| | | //获取网关版本信息
|
| | | var result = this.GetGatewayInfo(zbGateway, mode);
|
| | | var result = this.GetGatewayInfo(zbGateway, false, mode);
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | |
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | var result = this.GetGatewayInfo(zbGateway, ShowErrorMode.NO);
|
| | | var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | //将网关的数据设置到本地缓存中
|
| | |
| | | //给一个线程去获取它的镜像类型
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | var result = this.GetGatewayInfo(zbGateway, ShowErrorMode.NO);
|
| | | var result = this.GetGatewayInfo(zbGateway, true, ShowErrorMode.NO);
|
| | | if (result != null)
|
| | | {
|
| | | //将网关的数据设置到本地缓存中
|
| | |
| | | //获取控制主人账号的Token
|
| | | Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord" };
|
| | | List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotCheck" };
|
| | |
|
| | | bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError);
|
| | | if (result == false)
|
| | |
| | | listBackupGwId.Add(strId);
|
| | |
|
| | | //备份
|
| | | var strData = Newtonsoft.Json.JsonConvert.SerializeObject(listBackupGwId);
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(strData);
|
| | | Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile, byteData);
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | var fileData = Global.ReadFileByDirectory(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile);
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
|
| | | if (fileData == null)
|
| | | {
|
| | | return;
|
| | |
| | | {
|
| | | bindGateway.BindGateways.Clear();
|
| | | bindGateway.BindGateways.Add(gwId);
|
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway);
|
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" });
|
| | | if (result == "Success")
|
| | | {
|
| | | this.listBackupGwId.Remove(gwId);
|
| | |
| | | if (this.listBackupGwId.Count == 0)
|
| | | {
|
| | | //如果没有了内容,则删除文件
|
| | | string file = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile);
|
| | | string file = DirNameResourse.BackupGatewayIdFile;
|
| | | if (System.IO.File.Exists(file) == true)
|
| | | {
|
| | | System.IO.File.Delete(file);
|
| | |
| | | else
|
| | | {
|
| | | //备份
|
| | | var strData = Newtonsoft.Json.JsonConvert.SerializeObject(listBackupGwId);
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(strData);
|
| | | Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.BackupGatewayIdFile, byteData);
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
|
| | | }
|
| | | });
|
| | | }
|
| | |
| | | /// <param name="sendData">需要发送的数据 JObject.ToString()的东西</param>
|
| | | /// <param name="receiptTopic">指定接收哪个主题</param>
|
| | | /// <param name="waitTime">超时时间(秒)</param>
|
| | | /// <param name="useLocalConnect">是否强制使用本地连接发送</param>
|
| | | /// <returns>网关返回的数据</returns>
|
| | | public ReceiptGatewayResult SendJobjectDataToGateway(ZbGateway gateway, string sendTopic, string sendData, string receiptTopic, int waitTime = 5)
|
| | | public ReceiptGatewayResult SendJobjectDataToGateway(ZbGateway gateway, string sendTopic, string sendData, string receiptTopic, int waitTime = 5, bool useLocalConnect = false)
|
| | | {
|
| | | var reResult = new ReceiptGatewayResult();
|
| | |
|
| | |
| | | };
|
| | | myGateway.Actions += receiptAction;
|
| | | //发送数据
|
| | | myGateway.Send(sendTopic, sendData);
|
| | | if (useLocalConnect == false)
|
| | | {
|
| | | myGateway.Send(sendTopic, sendData);
|
| | | }
|
| | | else
|
| | | {
|
| | | myGateway.SendLocation(sendTopic, System.Text.Encoding.UTF8.GetBytes(sendData));
|
| | | }
|
| | |
|
| | | //超时时间
|
| | | int TimeOut = 0;
|