黄学彪
2020-08-21 9cc8fd11b13813adbdd3c6c31554e5c0bebf4026
ZigbeeApp/Shared/Phone/TemplateData/TemplateCommonLogic.cs
@@ -130,7 +130,7 @@
            //读取模板Bin文件
            if (templateBinFile != string.Empty)
            {
                bool hadRoom = HdlRoomLogic.Current.GetAllListRooms().Count > 1;
                bool hadRoom = HdlRoomLogic.Current.GetAllListRooms().Count > 1 && Common.Config.Instance.Home.FloorDics.Count == 0;
                //开始读取文件内容
                this.ReadTemplateFileMethord((strData, saveDiv, deviceType) =>
                {
@@ -192,6 +192,7 @@
                {
                    //只初始化一次,有房间时代表已经不是第一次加载了
                    Common.Config.Instance.Home.FloorDics = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(this.strTempContentData);
                    Common.Config.Instance.Home.Save(false);
                }
                this.strTempContentData = string.Empty;
                return true;
@@ -265,6 +266,16 @@
            //再次初始化房间
            HdlRoomLogic.Current.InitAllRoom();
            //无模板模式时,恢复备份的时候,把备份文件删除
            if (Common.Config.Instance.Home.TemplateMode != 2)
            {
                //存放的路径
                string fullFile = System.IO.Path.Combine(DirNameResourse.LocalTemplateDirectory, TemplateFileName);
                HdlFileLogic.Current.DeleteFile(fullFile);
            }
            //覆盖物理设备所在的房间数据
            HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.modelData.dicDeviceTemplateRealRoom);
        }
        /// <summary>
@@ -285,6 +296,7 @@
            else if (strData == "#FloorInfo END#")
            {
                Common.Config.Instance.Home.FloorDics = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(this.strTempContentData);
                Common.Config.Instance.Home.Save(false);
                this.strTempContentData = string.Empty;
                return true;
            }
@@ -1493,9 +1505,9 @@
        /// 获取需要升级的网关对象(key:本地网关的id value:升级固件地址,第一位是Linux,第二位是协调器,之后都是虚拟驱动)
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, List<string>> GetNeedToUpdateGateway()
        public Dictionary<string, List<GatewayNeedUpdateInfo>> GetNeedToUpdateGateway()
        {
            var dicGateway = new Dictionary<string, List<string>>();
            var dicGateway = new Dictionary<string, List<GatewayNeedUpdateInfo>>();
            //循环网关匹配的模板
            foreach (var localId in this.modelData.dicGatewayTemplateSelect.Keys)
            {
@@ -1514,8 +1526,9 @@
                }
                var tempGateway = this.modelData.dicGatewayInfo[tempId];
                //初始化容器
                dicGateway[localId] = new List<string>() { null, null };
                var listUpdateInfo = new List<GatewayNeedUpdateInfo>() { null, null };
                bool needUpdate = false;
                //Linux版本比较
                if (tempGateway.LinuxFirmwareVersion != localGateway.LinuxFirmwareVersion)
                {
@@ -1524,7 +1537,11 @@
                    if (System.IO.File.Exists(updateFile) == true)
                    {
                        //如果存在的话
                        dicGateway[localId][0] = updateFile;
                        var info = new GatewayNeedUpdateInfo();
                        info.Div = 1;
                        info.FullFileName = updateFile;
                        listUpdateInfo[0] = info;
                        needUpdate = true;
                    }
                }
                //协调器版本比较
@@ -1535,7 +1552,11 @@
                    if (System.IO.File.Exists(updateFile) == true)
                    {
                        //如果存在的话
                        dicGateway[localId][1] = updateFile;
                        var info = new GatewayNeedUpdateInfo();
                        info.Div = 2;
                        info.FullFileName = updateFile;
                        listUpdateInfo[1] = info;
                        needUpdate = true;
                    }
                }
                //虚拟驱动比较
@@ -1546,19 +1567,29 @@
                        foreach (var tempCode in tempGateway.DriveCodeList)
                        {
                            //防止它放的顺序不样
                            if (localCode.DriveId == tempCode.DriveId && localCode.DriveFwVersion != tempCode.DriveFwVersion)
                            if (localCode.DriveCode == tempCode.DriveCode && localCode.DriveFwVersion != tempCode.DriveFwVersion)
                            {
                                //虚拟驱动升级固件文件全路径
                                string updateFile = HdlFirmwareUpdateLogic.GetGatewayDriveCodeFirmwareFile(tempCode);
                                if (System.IO.File.Exists(updateFile) == true)
                                {
                                    //如果存在的话
                                    dicGateway[localId].Add(updateFile);
                                    var info = new GatewayNeedUpdateInfo();
                                    info.Div = 3;
                                    info.DriveCode = tempCode.DriveCode;
                                    info.FullFileName = updateFile;
                                    listUpdateInfo.Add(info);
                                    needUpdate = true;
                                }
                            }
                        }
                    }
                }
                //添加目标缓存
                if (needUpdate == true)
                {
                    dicGateway[localId] = listUpdateInfo;
                }
            }
            return dicGateway;