| | |
| | | #region ■ 上传设备备份到网关_________________
|
| | |
|
| | | /// <summary>
|
| | | /// 上传设备备份到网关(最好不要去理它的返回结果)
|
| | | /// 上传设备备份到网关(废弃)
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="backupEnum">备份类型</param>
|
| | | /// <param name="upLaodData">备份的数据</param>
|
| | | /// <returns></returns>
|
| | | public async Task<bool> UpLoadDeviceBackupDataToGateway(CommonDevice device, GatewayBackupEnum backupEnum, object upLaodData)
|
| | | public async Task<bool> UpLoadDeviceBackupDataToGateway(CommonDevice device, object upLaodData)
|
| | | {
|
| | | 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;
|
| | | }
|
| | | //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;
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | 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)
|
| | |
| | | waitCount++;
|
| | | if (this.nowGwConnectMode == GatewayConnectMode.Remote)
|
| | | {
|
| | | //远程每10秒检测一次
|
| | | if (waitCount < 10) { continue; }
|
| | | //远程每20秒检测一次
|
| | | if (waitCount < 20) { continue; }
|
| | | }
|
| | | else if (this.nowGwConnectMode == GatewayConnectMode.WIFI)
|
| | | {
|
| | | //局域网每3秒检测一次
|
| | | if (waitCount < 3) { continue; }
|
| | | //局域网每5秒检测一次
|
| | | if (waitCount < 5) { continue; }
|
| | | }
|
| | | waitCount = 0;
|
| | |
|
| | |
| | | //等个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(gwId) == true)
|
| | | {
|
| | | if (way.GatewayOnlineFlage == true)
|
| | | {
|
| | | //有一个网关在线,即在线
|
| | | hadGwOnline = true;
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | foreach (var way in list)
|
| | | {
|
| | | string gwId = this.GetGatewayId(way);
|
| | | 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>
|
| | |
| | | /// </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);
|
| | | UserCenterResourse.DicActionForm[formId]?.GatewayOnlinePush(zbway, online, hadGwOnline);
|
| | | }
|
| | | }
|
| | | catch { }
|