old mode 100755
new mode 100644
File was renamed from ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayLogic.cs |
| | |
| | | using System.Threading.Tasks;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter
|
| | | namespace Shared.Phone |
| | | {
|
| | | /// <summary>
|
| | | /// 网关业务的逻辑类
|
| | |
| | | /// </summary> |
| | | public void RefreshAppOldSelectGatewayId()
|
| | | {
|
| | | GatewayResourse.AppOldSelectGatewayId = string.Empty;
|
| | | HdlGatewayResourse.AppOldSelectGatewayId = string.Empty; |
| | |
|
| | | //从文件中获取上一次选择的网关id
|
| | | byte[] data = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.AppOldSelectGatewayFile);
|
| | | byte[] data = HdlFileLogic.Current.ReadFileByteContent(HdlFileNameResourse.AppOldSelectGatewayFile); |
| | | if (data != null)
|
| | | {
|
| | | string strvalue = System.Text.Encoding.UTF8.GetString(data);
|
| | | GatewayResourse.AppOldSelectGatewayId = JsonConvert.DeserializeObject<string>(strvalue);
|
| | | HdlGatewayResourse.AppOldSelectGatewayId = JsonConvert.DeserializeObject<string>(strvalue); |
| | | }
|
| | | //如果本地没有这个网关的话
|
| | | if (this.IsGatewayExist(GatewayResourse.AppOldSelectGatewayId) == false)
|
| | | if (this.IsGatewayExist(HdlGatewayResourse.AppOldSelectGatewayId) == false) |
| | | {
|
| | | GatewayResourse.AppOldSelectGatewayId = string.Empty;
|
| | | HdlGatewayResourse.AppOldSelectGatewayId = string.Empty; |
| | | lock (dicGateway)
|
| | | {
|
| | | //随便选一个网关
|
| | | foreach (string wayId in this.dicGateway.Keys)
|
| | | {
|
| | | GatewayResourse.AppOldSelectGatewayId = wayId;
|
| | | HdlGatewayResourse.AppOldSelectGatewayId = wayId; |
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | public void SynchronizeDbGateway()
|
| | | {
|
| | | //从云端获取网列表ID
|
| | | Dictionary<string, GatewayResult> result = HdlGatewayLogic.Current.GetGateWayListFromDataBase();
|
| | | Dictionary<string, GatewayResult> result = this.GetGateWayListFromDataBase(); |
| | | if (result == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | List<string> listBackupGwId = new List<string>();
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(HdlFileNameResourse.BackupGatewayIdFile); |
| | | if (fileData != null)
|
| | | {
|
| | | //新增:虽然概率低,但是确实发生了。如果有网络时,App重新绑定记录的网关失败的话
|
| | |
| | | foreach (var gatewayId in listDelete)
|
| | | {
|
| | | //删除本地这个网关所有的设备
|
| | | List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(gatewayId);
|
| | | List<CommonDevice> list = HdlDeviceCommonLogic.Current.GetDeviceByGatewayID(gatewayId); |
| | | foreach (var device in list)
|
| | | {
|
| | | //删除一般设备
|
| | | Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
|
| | | HdlDeviceCommonLogic.Current.DeleteMemmoryDevice(device, true); |
| | | //删除Ota设备
|
| | | Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
|
| | | HdlDeviceCommonLogic.Current.DeleteMemmoryOtaDevice(device.DeviceAddr); |
| | | }
|
| | | //删除网关文件
|
| | | this.DeleteGatewayFile(gatewayId);
|
| | |
| | | public bool AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode, WriteLogMode logMode = WriteLogMode.NO) |
| | | {
|
| | | //设置网关的经纬度
|
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO); |
| | | bool falge = this.SetGatewaySite(zbGateway.GwId, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO); |
| | | if (falge == false)
|
| | | {
|
| | | if (logMode == WriteLogMode.YES)
|
| | |
| | | }
|
| | |
|
| | | //更新云端数据库
|
| | | int flage1 = this.SetGatewayIdToDataBase(zbGateway);
|
| | | int flage1 = this.SetGatewayIdToDataBase(zbGateway.GwId); |
| | | //异常也不鸟它,0是特殊含义
|
| | | if (flage1 == 0)
|
| | | {
|
| | |
| | | string accountId = string.Empty;
|
| | | if (HomeId != string.Empty)
|
| | | {
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 1)
|
| | | {
|
| | | //主账号
|
| | | accountId = Config.Instance.Guid;
|
| | | }
|
| | | else
|
| | | {
|
| | | accountId = Config.Instance.Home.MainUserDistributedMark;
|
| | | }
|
| | | }
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 82 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "HomeId", HomeId }, { "AccountId", accountId } };
|
| | |
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 更新网关ID到云端数据库(1:正常 -1:异常 0:当前的网关绑定在了当前账号下的不同住宅里面)
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <returns></returns> |
| | | private int SetGatewayIdToDataBase(ZbGateway zbGateway) |
| | | {
|
| | | //调用接口,绑定网关(即使失败,也返回true往下走)
|
| | | var bindGateway = new BindGatewayPra();
|
| | | bindGateway.BindGateways.Add(zbGateway.GwId);
|
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); |
| | | |
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false); |
| | | if (result == "Error")
|
| | | {
|
| | | return -1;
|
| | | } |
| | | if (result == "BindGatewaysExists")
|
| | | {
|
| | | return 0;
|
| | | } |
| | | |
| | | return result == "Success" ? 1 : -1; |
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | return -1;
|
| | | }
|
| | | //设置网关的经纬度
|
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.YES); |
| | | bool falge = this.SetGatewaySite(zbGateway.GwId, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.YES); |
| | | if (falge == false)
|
| | | {
|
| | | return -1;
|
| | |
| | | }
|
| | |
|
| | | //更新云端数据库
|
| | | int flage1 = this.SetGatewayIdToDataBase(zbGateway);
|
| | | int flage1 = this.SetGatewayIdToDataBase(zbGateway.GwId); |
| | | //异常也不鸟它,0是特殊含义
|
| | | if (flage1 == 0)
|
| | | {
|
| | |
| | | if (flage1 == -1)
|
| | | {
|
| | | //备份失败的网关ID
|
| | | HdlGatewayLogic.Current.BackupGatewayIdOnNotNetwork(zbGateway);
|
| | | this.BackupGatewayIdOnNotNetwork(zbGateway); |
| | | }
|
| | |
|
| | | if (btnMsg == null)
|
| | |
| | | //网关名称修改失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGatewayReNameFail);
|
| | | //网关回复超时 |
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | this.ShowTipMsg(msg); |
| | | return false; |
| | | }
|
| | |
| | | }
|
| | |
|
| | | //获取全部设备
|
| | | int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay.GwId, false);
|
| | | int result = HdlDeviceCommonLogic.Current.SetDeviceToMemmoryByGateway(realWay.GwId, false); |
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | if (result == -1)
|
| | |
| | | /// <param name="gatewayId"></param>
|
| | | public void SaveGatewayIdToLocation(string gatewayId)
|
| | | {
|
| | | GatewayResourse.AppOldSelectGatewayId = gatewayId;
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.AppOldSelectGatewayFile, GatewayResourse.AppOldSelectGatewayId);
|
| | | HdlGatewayResourse.AppOldSelectGatewayId = gatewayId; |
| | | HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.AppOldSelectGatewayFile, HdlGatewayResourse.AppOldSelectGatewayId); |
| | | }
|
| | |
|
| | | #endregion |
| | |
| | | HdlAutoBackupLogic.DeleteFile(file);
|
| | |
|
| | | //删除设备文件
|
| | | List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(zbGatewayID);
|
| | | List<CommonDevice> list = HdlDeviceCommonLogic.Current.GetDeviceByGatewayID(zbGatewayID); |
| | | foreach (var device in list)
|
| | | {
|
| | | //删除设备文件
|
| | | Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
|
| | | HdlDeviceCommonLogic.Current.DeleteMemmoryDevice(device, true); |
| | | //删除Ota设备
|
| | | Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
|
| | | HdlDeviceCommonLogic.Current.DeleteMemmoryOtaDevice(device.DeviceAddr); |
| | | }
|
| | | //如果是主网关
|
| | | if (this.IsMainGateway(zbGatewayID) == 1)
|
| | | {
|
| | | var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
|
| | | var listAllRoom = HdlRoomLogic.Current.GetAllListRooms(); |
| | | foreach (var room in listAllRoom)
|
| | | {
|
| | | //删除场景文件
|
| | |
| | | {
|
| | | //获取协调器信道失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayChannelIdFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | //获取协调器Mac失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayCoordinatorMacFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | //获取协调器PanID失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayPanIDFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | //获取网关自动备份设置失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayAutoBackupStatuFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | //设置网关自动备份失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewayAutoBackupStatuFail);
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
| | | return name;
|
| | | }
|
| | |
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(localWay.LinuxImageType.ToString());
|
| | | var nameContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo(localWay.LinuxImageType.ToString()); |
| | | if (nameContent != null)
|
| | | {
|
| | | return nameContent.A备注名字;
|
| | |
| | | //如果这个网关没有信息,则从新获取
|
| | | if (zbGateway.LinuxImageType != -1)
|
| | | {
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
|
| | | var nameContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString()); |
| | | if (nameContent != null)
|
| | | {
|
| | | button.Text = nameContent.A官方名字;
|
| | |
| | |
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
|
| | | var nameContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString()); |
| | | if (nameContent != null)
|
| | | {
|
| | | button.Text = nameContent.A官方名字;
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | var nameContent = LocalDevice.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString());
|
| | | var nameContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo(zbGateway.LinuxImageType.ToString()); |
| | | if (nameContent != null)
|
| | | {
|
| | | button.Text = nameContent.A官方名字;
|
| | |
| | | //获取网关信息失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | this.ShowErrorMsg(msg);
|
| | | }
|
| | | return null;
|
| | |
| | | } |
| | | |
| | | //添加网关的升级固件(成不成功都无所谓) |
| | | var flage = HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.Linux,
|
| | | var flage = HdlFirmwareUpdateLogic.Current.AddFirmwareVersionInfo(FirmwareLevelType.Linux, |
| | | localWay.LinuxHardVersion.ToString(),
|
| | | localWay.LinuxImageType.ToString());
|
| | |
|
| | |
| | | if (flage == 1)
|
| | | {
|
| | | //没网的时候不再处理
|
| | | HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A协调器,
|
| | | HdlFirmwareUpdateLogic.Current.AddFirmwareVersionInfo(FirmwareLevelType.A协调器, |
| | | localWay.CoordinatorHardVersion.ToString(),
|
| | | localWay.CoordinatorImageId.ToString());
|
| | | }
|
| | |
|
| | | //网关的版本
|
| | | var gatewayFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.Linux,
|
| | | var gatewayFirmware = HdlFirmwareUpdateLogic.Current.GetFirmwareMostVersionInfo(FirmwareLevelType.Linux, |
| | | localWay.LinuxHardVersion.ToString(),
|
| | | localWay.LinuxImageType.ToString(),
|
| | | localWay.LinuxFirmwareVersion);
|
| | |
|
| | | //协调器版本
|
| | | var coordinatorFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A协调器,
|
| | | var coordinatorFirmware = HdlFirmwareUpdateLogic.Current.GetFirmwareMostVersionInfo(FirmwareLevelType.A协调器, |
| | | localWay.CoordinatorHardVersion.ToString(),
|
| | | localWay.CoordinatorImageId.ToString(),
|
| | | localWay.CoordinatorFirmwareVersion);
|
| | |
| | | //添加虚拟驱动的升级固件(成不成功都无所谓) 必须能够联网才行
|
| | | if (flage == 1)
|
| | | {
|
| | | HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.A虚拟驱动,
|
| | | HdlFirmwareUpdateLogic.Current.AddFirmwareVersionInfo(FirmwareLevelType.A虚拟驱动, |
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString());
|
| | | }
|
| | |
|
| | | //虚拟驱动
|
| | | var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.A虚拟驱动,
|
| | | var virtualFirmware = HdlFirmwareUpdateLogic.Current.GetFirmwareMostVersionInfo(FirmwareLevelType.A虚拟驱动, |
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString(),
|
| | | data.DriveFwVersion);
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 从云端获取全部网关列表ID___________
|
| | |
|
| | | /// <summary> |
| | | /// 从云端获取全部网关列表ID |
| | | /// </summary> |
| | | /// <returns>从云端获取全部网关列表ID</returns> |
| | | public Dictionary<string, GatewayResult> GetGateWayListFromDataBase() |
| | | {
|
| | | Dictionary<string, GatewayResult> dicDbGateway = null;
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3)
|
| | | {
|
| | | //成员
|
| | | return dicDbGateway;
|
| | | }
|
| | |
|
| | | bool canBreak = false;
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | List<string> list = new List<string>() { "NotCheck" };
|
| | |
|
| | | //设置访问接口的参数
|
| | | var pra = new GetGatewayPra();
|
| | | pra.ReqDto.PageSetting.Page = 1;
|
| | | pra.ReqDto.PageSetting.PageSize = 999;
|
| | | //获取控制主人账号的Token
|
| | | pra.ReqDto.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list, false);
|
| | | if (string.IsNullOrEmpty(result) == true)
|
| | | {
|
| | | canBreak = true;
|
| | | return;
|
| | | }
|
| | | var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject<GetGatewayResult>(result);
|
| | |
|
| | | Dictionary<string, GatewayResult> dic = new Dictionary<string, GatewayResult>();
|
| | | foreach (var data in infoResult.PageData)
|
| | | {
|
| | | dic[data.GatewayUniqueId] = data;
|
| | | }
|
| | | dicDbGateway = dic;
|
| | | canBreak = true;
|
| | | });
|
| | |
|
| | | int count = 0;
|
| | | while (canBreak == false)
|
| | | {
|
| | | System.Threading.Thread.Sleep(200);
|
| | | count++;
|
| | | if (count == 25)
|
| | | {
|
| | | //如果5秒还不能获取得到数据,则中断此次操作
|
| | | break;
|
| | | }
|
| | | } |
| | | |
| | | return dicDbGateway; |
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设置网关经纬度_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置网关经纬度
|
| | | /// </summary>
|
| | | /// <param name="gateway">网关对象</param>
|
| | | /// <param name="gatewayId">网关Id</param> |
| | | /// <param name="Longitude">经度</param>
|
| | | /// <param name="Latitude">维度</param>
|
| | | /// <param name="mode">显示错误</param>
|
| | | /// <returns></returns>
|
| | | public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude, ShowErrorMode mode)
|
| | | public bool SetGatewaySite(string gatewayId, double Longitude, double Latitude, ShowErrorMode mode) |
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, gateway) == false)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return false;
|
| | | }
|
| | | if (((decimal)Longitude) == 0 && ((decimal)Latitude) == 0)
|
| | | {
|
| | | //没有配置过经纬度
|
| | |
| | | }
|
| | |
|
| | | int result = -1;
|
| | | Action<string, string> action = (topic, message) =>
|
| | | HdlGatewayReceiveLogic.Current.AddGatewayReceiveEvent(gatewayId, (topic, message) => |
| | | {
|
| | | var gatewayID = topic.Split('/')[0];
|
| | | if (topic == gatewayID + "/" + "Logic/SetSite_Respon")
|
| | | if (topic == gatewayId + "/" + "Logic/SetSite_Respon") |
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | | result = Convert.ToInt32(jobject["Data"]["Result"].ToString());
|
| | | }
|
| | | };
|
| | | realWay.Actions += action;
|
| | | }); |
| | | //两位小数
|
| | | Longitude = Math.Round(Longitude, 2);
|
| | | Latitude = Math.Round(Latitude, 2);
|
| | |
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 2013 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "Longitude", intLongitude }, { "Latitude", intLatitude } };
|
| | | jObject.Add("Data", data);
|
| | | if (this.IsGatewayExist(gateway) == true)
|
| | | {
|
| | | realWay.Send("Logic/SetSite", jObject.ToString());
|
| | | }
|
| | | else
|
| | | {
|
| | | |
| | | //如果这个网关还没有绑定的话,则强制使用本地连接
|
| | | realWay.SendLocation("Logic/SetSite", System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
|
| | | }
|
| | | this.SendJobjectData(gatewayId, "Logic/SetSite", jObject.ToString(), this.IsGatewayExist(gatewayId) == false); |
| | |
|
| | | int TimeOut = 0;
|
| | | while (result == -1 && TimeOut < 30)
|
| | |
| | | TimeOut++;
|
| | | }
|
| | |
|
| | | realWay.Actions -= action;
|
| | | //移除监听事件 |
| | | HdlGatewayReceiveLogic.Current.RemoveGatewayReceiveEvent(); |
| | | if (result != 0)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
|
| | | if (result == -1)
|
| | | {
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | msg = HdlCommonLogic.Current.CombineGatewayTimeOutMsg(msg, null, "回复超时"); |
| | | }
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 解绑云端网关_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 解绑云端绑定的网关
|
| | | /// </summary>
|
| | | /// <param name="strWayId"></param> |
| | | public bool DeleteDataBaseGateway(string strWayId)
|
| | | {
|
| | | var Pra = new DeleteGatewayPra();
|
| | | Pra.BindGateways.Add(strWayId);
|
| | | //获取控制主人账号的Token
|
| | | Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotCheck" };
|
| | |
|
| | | bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError, false);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | |
| | | listBackupGwId.Add(strId);
|
| | |
|
| | | //备份
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
|
| | | HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.BackupGatewayIdFile, listBackupGwId); |
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 重新发送命令去绑定断网情况下备份的网关
|
| | | /// </summary>
|
| | | public bool ResetComandToBindBackupGateway()
|
| | | public void ResetComandToBindBackupGateway() |
| | | {
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(HdlFileNameResourse.BackupGatewayIdFile); |
| | | if (fileData == null)
|
| | | {
|
| | | return true;
|
| | | return; |
| | | }
|
| | | this.listBackupGwId = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
|
| | | this.listBackupGwId = JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData)); |
| | | var listTempId = new List<string>();
|
| | | listTempId.AddRange(this.listBackupGwId);
|
| | |
|
| | | //调用接口,绑定网关
|
| | | var bindGateway = new BindGatewayPra();
|
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | foreach (var gwId in listTempId)
|
| | | {
|
| | | bindGateway.BindGateways.Clear();
|
| | | bindGateway.BindGateways.Add(gwId);
|
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
|
| | | if (result == "Success")
|
| | | if (this.IsGatewayExist(gwId) == true) |
| | | {
|
| | | this.listBackupGwId.Remove(gwId);
|
| | | }
|
| | | if (result == "Error")
|
| | | //调用接口,绑定网关(即使失败,也返回true往下走) |
| | | var result = this.SetGatewayIdToDataBase(gwId); |
| | | if (result != 1) |
| | | {
|
| | | break;
|
| | | }
|
| | | } |
| | | this.listBackupGwId.Remove(gwId); |
| | | }
|
| | |
|
| | | if (this.listBackupGwId.Count == 0)
|
| | | {
|
| | | //如果没有了内容,则删除文件
|
| | | string file = DirNameResourse.BackupGatewayIdFile;
|
| | | string file = HdlFileNameResourse.BackupGatewayIdFile; |
| | | if (System.IO.File.Exists(file) == true)
|
| | | {
|
| | | System.IO.File.Delete(file);
|
| | | }
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | //备份
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
|
| | | return false;
|
| | | HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.BackupGatewayIdFile, listBackupGwId); |
| | | }
|
| | | }
|
| | |
|
| | |
| | | if (topic == errorTopic)
|
| | | {
|
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
| | | reResult.ErrorMsg = HdlCheckLogic.Current.CheckCommonErrorCode(temp.Error);
|
| | | reResult.ErrorMsg = HdlCheckLogic.Current.CheckGatewayErrorCode(temp.Error); |
| | | }
|
| | | //如果是指定的主题
|
| | | if (topic == checkTopic)
|
| | |
| | | {
|
| | | try
|
| | | {
|
| | | for (int i = 0; i < UserCenterResourse.listActionFormId.Count; i++)
|
| | | var listForm = HdlFormLogic.Current.GetAllOpenForm(); |
| | | for (int i = 0; i < listForm.Count; i++) |
| | | {
|
| | | string formId = UserCenterResourse.listActionFormId[i];
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | //网关在线推送
|
| | | var zbway = this.GetLocalGateway(gwId);
|
| | | if (zbway != null)
|
| | |
| | | {
|
| | | zbway.OnlineTime = DateTime.Now;
|
| | | }
|
| | | UserCenterResourse.DicActionForm[formId]?.GatewayOnlinePush(zbway, online, hadGwOnline);
|
| | | listForm[i]?.GatewayOnlinePush(zbway, online, hadGwOnline); |
| | | }
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 调用云端接口的方法_________________ |
| | | |
| | | /// <summary> |
| | | /// 更新网关ID到云端数据库(1:正常 -1:异常 0:当前的网关绑定在了当前账号下的不同住宅里面) |
| | | /// </summary> |
| | | /// <param name="i_gatewayIds">网关ID</param> |
| | | /// <returns></returns> |
| | | private int SetGatewayIdToDataBase(string i_gatewayId) |
| | | { |
| | | //调用接口,绑定网关(即使失败,也返回true往下走) |
| | | var pra = new { homeId = Config.Instance.Home.Id, mac = i_gatewayId, gatewayType = "ZIGBEEGATEWAY" }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/bindGateway", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | if (result == null || result.Code != HttpMessageEnum.A成功) |
| | | { |
| | | return -1; |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从云端获取全部网关列表ID |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Dictionary<string, GatewayResult> GetGateWayListFromDataBase() |
| | | { |
| | | //这个接口特殊,不需要检测权限 |
| | | var pra = new { homeId = Config.Instance.Home.Id }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/getGatewayList", RestSharp.Method.POST, pra); |
| | | if (result == null || result.Code != HttpMessageEnum.A成功) |
| | | { |
| | | return null; |
| | | } |
| | | var listData = JsonConvert.DeserializeObject<List<GatewayResult>>(result.Data.ToString()); |
| | | |
| | | var dicDbGateway = new Dictionary<string, GatewayResult>(); |
| | | foreach (var data in listData) |
| | | { |
| | | if (data.GatewayType == "ZIGBEEGATEWAY") |
| | | { |
| | | dicDbGateway[data.Mac] = data; |
| | | } |
| | | } |
| | | return dicDbGateway; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 解绑云端绑定的网关 |
| | | /// </summary> |
| | | /// <param name="strWayId"></param> |
| | | public bool DeleteDataBaseGateway(string strWayId) |
| | | { |
| | | var pra = new { homeId = Config.Instance.Home.Id, mac = strWayId }; |
| | | var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("home-wisdom/gateway/untieGateway", RestSharp.Method.POST, pra, null, null, CheckMode.A账号权限); |
| | | if (result == null || result.Code != HttpMessageEnum.A成功) |
| | | { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|