| | |
| | | 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();
|
| | | }
|
| | | } |
| | | |
| | |
| | | //获取控制主人账号的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;
|
| | |
| | | /// </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 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 |
| | |
| | | /// 获取网关加特效的名称
|
| | | /// </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)
|
| | | {
|
| | | string gwId = zbGateway.GwId;
|
| | | if (this.dicGateway.ContainsKey(gwId) == false)
|
| | |
| | | return name;
|
| | | }
|
| | |
|
| | | if (mode == GetNameMode.SpecialGateway)
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + localWay.LinuxImageType;
|
| | | if (LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //没有名称时,则使用R文件里面设置的默认设备名称
|
| | | return Language.StringByID(LocalDevice.Current.dicDeviceAllNameID[keyName] + 20000);
|
| | | }
|
| | | }
|
| | |
|
| | | return string.Empty;
|
| | |
| | | /// <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;
|
| | |
| | | //获取控制主人账号的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);
|
| | | }
|
| | | });
|
| | | }
|