| | |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关</param> |
| | | /// <param name="mode">是否显示错误</param> |
| | | public async Task<bool> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) |
| | | public bool AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) |
| | | {
|
| | | //设置网关的经纬度
|
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO); |
| | |
| | | return falge;
|
| | | } |
| | | //执行添加网关到内存 |
| | | var result = await this.DoAddGatewayToMemory(zbGateway, mode); |
| | | var result = this.DoAddGatewayToMemory(zbGateway, mode); |
| | | //前的网关绑定在了当前账号下的不同住宅里面
|
| | | if (result == 0)
|
| | | {
|
| | |
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="mode">是否显示错误</param>
|
| | | /// <returns></returns>
|
| | | private async Task<int> DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode)
|
| | | private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode)
|
| | | {
|
| | | if (zbGateway == null)
|
| | | {
|
| | |
| | | //设置住宅ID到网关
|
| | | if (result.HomeId != Common.Config.Instance.HomeId)
|
| | | {
|
| | | bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
|
| | | bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, mode);
|
| | | if (flage2 == false)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | |
| | | /// <param name="zbGateway"></param>
|
| | | /// <param name="HomeId"></param>
|
| | | /// <returns></returns> |
| | | public async Task<bool> SetHomeIdToGateway(ZbGateway zbGateway, string HomeId, ShowErrorMode mode)
|
| | | public bool SetHomeIdToGateway(ZbGateway zbGateway, string HomeId, ShowErrorMode mode)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, zbGateway) == false)
|
| | | //账号ID
|
| | | 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 } };
|
| | | jObject.Add("Data", data);
|
| | | //住宅ID的设置,固定使用局域网,不存在远程的说法
|
| | | var result = this.SendJobjectDataToGateway(zbGateway, "GwSetHomeId", jObject.ToString(), "GwSetHomeId_Respon", 5, true);
|
| | | if (result.ErrorMsgDiv == -1)
|
| | | {
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | |
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | var info = await realWay.GwSetHomeIdAsync(HomeId);
|
| | | if (info != null && info.gwSetHomeIdData != null)
|
| | | if (result.ErrorMsgDiv == 0)
|
| | | {
|
| | | return true;
|
| | | return false;
|
| | | }
|
| | | return false;
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken(); |
| | | |
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }); |
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false); |
| | | if (result == "Error")
|
| | | {
|
| | | return -1;
|
| | |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关</param> |
| | | /// <param name="btnMsg">消息控件</param> |
| | | public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) |
| | | public int ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) |
| | | {
|
| | | if (zbGateway == null)
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | //设置住宅ID到网关
|
| | | bool flage2 = await this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES);
|
| | | bool flage2 = this.SetHomeIdToGateway(zbGateway, Common.Config.Instance.HomeId, ShowErrorMode.YES);
|
| | | if (flage2 == false)
|
| | | {
|
| | | //向网关设置住宅ID失败
|
| | |
| | | btnMsg.TextID = R.MyInternationalizationString.uGatewayDataIsChangingPleaseWhait;
|
| | | });
|
| | | }
|
| | | await Task.Delay(8000);
|
| | | System.Threading.Thread.Sleep(8000);
|
| | |
|
| | | //获取网关的信息
|
| | | ZbGatewayData.GetGwData result = null;
|
| | |
| | | }
|
| | | count--;
|
| | | //最多再等20秒
|
| | | await Task.Delay(4000);
|
| | | System.Threading.Thread.Sleep(4000);
|
| | | }
|
| | | if (result == null)
|
| | | {
|
| | |
| | | /// 执行切换网关操作
|
| | | /// </summary>
|
| | | /// <param name="gatewayId"></param>
|
| | | public async Task<bool> DoSwitchGateway(string gatewayId)
|
| | | public bool DoSwitchGateway(string gatewayId)
|
| | | {
|
| | | var zbGateway = this.GetLocalGateway(gatewayId);
|
| | |
|
| | | //重新获取在线网关的信息
|
| | | var result = await this.GetOnlineGatewayInfo(gatewayId);
|
| | | var result = this.GetOnlineGatewayInfo(gatewayId);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | |
| | | /// </summary>
|
| | | /// <param name="gatewayId"></param>
|
| | | /// <returns></returns>
|
| | | private async Task<bool> GetOnlineGatewayInfo(string gatewayId)
|
| | | private bool GetOnlineGatewayInfo(string gatewayId)
|
| | | {
|
| | | //显示进度条
|
| | | ProgressBar.Show();
|
| | |
| | | //重新设置住宅ID(这个应该是不经过APP,直接把网关恢复了出厂设置)
|
| | | if (this.HomeIdIsEmpty(realWay.HomeId) == true)
|
| | | {
|
| | | int result2 = await this.ReBindNewGateway(realWay);
|
| | | int result2 = this.ReBindNewGateway(realWay);
|
| | | if (result2 == 0)
|
| | | {
|
| | | //出现未知错误,请稍后再试
|
| | |
| | | /// <summary> |
| | | /// 删除网关,包括云端和本地(失败时不会显示信息,并且会返回true) |
| | | /// </summary> |
| | | /// <param name="zbGateway"></param> |
| | | public async Task<bool> DeleteGateway(ZbGateway zbGateway) |
| | | { |
| | | //移除本地网关信息 |
| | | return await this.DeleteGateway(zbGateway.GwId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除网关,包括云端和本地(失败时不会显示信息,并且会返回true) |
| | | /// </summary> |
| | | /// <param name="zbGatewayID"></param> |
| | | public async Task<bool> DeleteGateway(string zbGatewayID) |
| | | public bool DeleteGateway(string zbGatewayID) |
| | | {
|
| | | ZbGateway realWay = null;
|
| | | this.GetRealGateway(ref realWay, zbGatewayID);
|
| | | //清空网关的住宅ID 网关解绑失败 不理它,因为网关可以按按键强制搜索得到
|
| | | if (realWay != null)
|
| | | {
|
| | | await this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO);
|
| | | this.SetHomeIdToGateway(realWay, string.Empty, ShowErrorMode.NO);
|
| | | }
|
| | |
|
| | | //删除云端的网关
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 清空真实网关列表___________________
|
| | | #region ■ 清空真实网关链接___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 清空全部的真实物理网关对象
|
| | | /// 清空全部的真实物理网关的链接
|
| | | /// </summary>
|
| | | public void ClearAllRealGateway()
|
| | | /// <param name="roadGateway">是否加载本地的网关对象到真实列表中</param>
|
| | | public void ClearAllRealGatewayConection(bool roadGateway)
|
| | | {
|
| | | //因为那一瞬间,有可能mqtt会加回来,所以先加缓存
|
| | | var list = new List<ZbGateway>();
|
| | | list.AddRange(ZbGateway.GateWayList);
|
| | | //然后清空掉
|
| | | ZbGateway.GateWayList.Clear();
|
| | | //最后再断开mqtt连接
|
| | | for (int i = 0; i < list.Count; i++)
|
| | | //断开mqtt连接(即使保存在内存当中也没问题,因为如果广播不到,则它不会建立链接)
|
| | | for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
|
| | | {
|
| | | list[i].DisConnectLocalMqttClient("G");
|
| | | ZbGateway.GateWayList[i].DisConnectLocalMqttClient("G");
|
| | | }
|
| | | list.Clear();
|
| | | //加载本地网关对象
|
| | | if (roadGateway == true)
|
| | | {
|
| | | List<string> listFile = this.GetAllGatewayFile();
|
| | | //反序列化添加到缓存
|
| | | foreach (string file in listFile)
|
| | | {
|
| | | //从文件中反序列化出网关对象
|
| | | var gateway = this.GetGatewayFromFile(file);
|
| | | if (gateway == null)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | var tempWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == gateway.GwId)); |
| | | if (tempWay == null) |
| | | { |
| | | ZbGateway.GateWayList.Add(tempWay); |
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <returns></returns>
|
| | | public int IsMainGateway(string waiID)
|
| | | {
|
| | | ZbGateway zbGateway = null;
|
| | | if (this.GetRealGateway(ref zbGateway, waiID) == false)
|
| | | var realWay = ZbGateway.GateWayList.Find((obj) =>
|
| | | {
|
| | | return obj.GwId == waiID;
|
| | | });
|
| | | //虚拟网关也返回 0
|
| | | if (realWay == null || realWay.IsVirtual == true)
|
| | | {
|
| | | return 0;
|
| | | }
|
| | | return zbGateway.IsMainGateWay == true ? 1 : 2;
|
| | | return realWay.IsMainGateWay == true ? 1 : 2;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | //获取控制主人账号的Token
|
| | | pra.ReqDto.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list);
|
| | | var result = UserCenterLogic.GetResponseDataByRequestHttps("App/GetSingleHomeGatewayPagger", true, pra, list, false);
|
| | | if (string.IsNullOrEmpty(result) == true)
|
| | | {
|
| | | canBreak = true;
|
| | |
| | |
|
| | | List<string> listNotShowError = new List<string>() { "NoExist", "NoBind", "NoRecord", "NotCheck" };
|
| | |
|
| | | bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError);
|
| | | bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/ReleaseGatewayToHome", true, Pra, listNotShowError, false);
|
| | | if (result == false)
|
| | | {
|
| | | return false;
|
| | |
| | | {
|
| | | bindGateway.BindGateways.Clear();
|
| | | bindGateway.BindGateways.Add(gwId);
|
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" });
|
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
|
| | | if (result == "Success")
|
| | | {
|
| | | this.listBackupGwId.Remove(gwId);
|