From 99253403b560f761d5f9af8b4f5140496996433a Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期五, 20 十一月 2020 16:49:50 +0800
Subject: [PATCH] 新云端的代码Ver1.0

---
 ZigbeeApp/Shared/Phone/TemplateData/TemplateCommonLogic.cs |  587 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 439 insertions(+), 148 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/TemplateData/TemplateCommonLogic.cs b/ZigbeeApp/Shared/Phone/TemplateData/TemplateCommonLogic.cs
index 6c72608..7456753 100755
--- a/ZigbeeApp/Shared/Phone/TemplateData/TemplateCommonLogic.cs
+++ b/ZigbeeApp/Shared/Phone/TemplateData/TemplateCommonLogic.cs
@@ -55,7 +55,7 @@
         {
             this.modelData = new TemplateMemoryData();
             //淇濆瓨鐨勮矾寰�
-            string saveFile = DirNameResourse.LocalTemplateDirectory;
+            string saveFile = HdlFileNameResourse.LocalTemplateDirectory;
 
             //濡傛灉褰撳墠浣忓畢鎷ユ湁閫夋嫨鐨勬ā鏉�
             if (Common.Config.Instance.Home.SelectTemplate != string.Empty)
@@ -107,7 +107,7 @@
                             //鍙嶅簭鍒楀寲璁惧鐨勪繚瀛樻枃浠跺唴瀹�
                             var tempData = this.DeserializeDeviceDataByDiv(saveDiv, deviceData);
                             //灏嗚澶囨ā鏉挎暟鎹坊鍔犲叆缂撳瓨
-                            string mainKey = Common.LocalDevice.Current.GetDeviceMainKeys(tempData.DeviceMac, tempData.DeviceEpoint);
+                            string mainKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(tempData.DeviceMac, tempData.DeviceEpoint);
                             this.SetTemplateDeviceDataToMemmory(tempData, deviceData, mainKey, true);
                         }
                         //娓呯┖
@@ -122,7 +122,7 @@
                     //鍙嶅簭鍒楀寲璁惧鐨勪繚瀛樻枃浠跺唴瀹�
                     var tempData = this.DeserializeDeviceDataByDiv(saveDiv, deviceData);
                     //灏嗚澶囨ā鏉挎暟鎹坊鍔犲叆缂撳瓨
-                    string mainKey = Common.LocalDevice.Current.GetDeviceMainKeys(tempData.DeviceMac, tempData.DeviceEpoint);
+                    string mainKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(tempData.DeviceMac, tempData.DeviceEpoint);
                     this.SetTemplateDeviceDataToMemmory(tempData, deviceData, mainKey, true);
                 }
             }
@@ -152,13 +152,13 @@
             this.modelData.dicDeviceTemplateSelect = new Dictionary<string, string>();
             this.modelData.dicGatewayTemplateSelect = new Dictionary<string, string>();
 
-            string fileData2 = HdlFileLogic.Current.ReadFileTextContent(DirNameResourse.DeviceTemplateSelectFile);
+            string fileData2 = HdlFileLogic.Current.ReadFileTextContent(HdlFileNameResourse.DeviceTemplateSelectFile);
             if (fileData2 != null)
             {
                 //璁惧閫夋嫨鐨勬ā鏉垮璞�(keys:鏈湴璁惧鐨凪ac value:妯℃澘涓殑Mac)
                 this.modelData.dicDeviceTemplateSelect = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(fileData2);
             }
-            fileData2 = HdlFileLogic.Current.ReadFileTextContent(DirNameResourse.GatewayTemplateSelectFile);
+            fileData2 = HdlFileLogic.Current.ReadFileTextContent(HdlFileNameResourse.GatewayTemplateSelectFile);
             if (fileData2 != null)
             {
                 //缃戝叧瀵硅薄閫夋嫨鐨勬ā鏉垮璞�(keys:鏈湴缃戝叧ID,  value:妯℃澘涓殑缃戝叧ID)
@@ -171,7 +171,7 @@
         /// </summary>
         /// <param name="strData">妯℃澘鏂囦欢涓殑琛屾暟鎹�</param>
         /// <param name="hadRoom">鏄惁宸茬粡鏈変簡鎴块棿</param>
-        private bool AdjustTemplateBinFileContentOnLoadMemory(string strData,bool hadRoom)
+        private bool AdjustTemplateBinFileContentOnLoadMemory(string strData, bool hadRoom)
         {
             //鍦烘櫙瀵硅薄
             if (strData == "#SceneTemplate END#")
@@ -205,6 +205,11 @@
                 foreach (var deviceKey in room.ListDevice)
                 {
                     this.modelData.dicDeviceTemplateRoom[deviceKey] = room.Id;
+                }
+                foreach (var strMac in room.ListDeviceMac)
+                {
+                    //鐗╃悊璁惧鎵�鍦ㄧ殑鍖哄煙,鍦ㄨ繖涓嚱鏁板闈㈠凡缁忓垵濮嬪寲浜嗚繖涓彉閲�
+                    this.modelData.dicDeviceTemplateRealRoom[strMac] = room.Id;
                 }
                 if (hadRoom == false)
                 {
@@ -261,8 +266,8 @@
             this.strTempContentData = string.Empty;
 
             //鍒犳帀杩欎袱涓繚瀛橀�夋嫨妯℃澘鐨勬枃浠�(杩欎袱涓笢瑗垮彲鑳借繕瀛樺湪)
-            HdlFileLogic.Current.DeleteFile(DirNameResourse.DeviceTemplateSelectFile);
-            HdlFileLogic.Current.DeleteFile(DirNameResourse.GatewayTemplateSelectFile);
+            HdlFileLogic.Current.DeleteFile(HdlFileNameResourse.DeviceTemplateSelectFile);
+            HdlFileLogic.Current.DeleteFile(HdlFileNameResourse.GatewayTemplateSelectFile);
 
             //鍐嶆鍒濆鍖栨埧闂�
             HdlRoomLogic.Current.InitAllRoom();
@@ -271,11 +276,9 @@
             if (Common.Config.Instance.Home.TemplateMode != 2)
             {
                 //瀛樻斁鐨勮矾寰�
-                string fullFile = System.IO.Path.Combine(DirNameResourse.LocalTemplateDirectory, TemplateFileName);
+                string fullFile = System.IO.Path.Combine(HdlFileNameResourse.LocalTemplateDirectory, TemplateFileName);
                 HdlFileLogic.Current.DeleteFile(fullFile);
             }
-            //瑕嗙洊鐗╃悊璁惧鎵�鍦ㄧ殑鎴块棿鏁版嵁
-            HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.modelData.dicDeviceTemplateRealRoom);
         }
 
         /// <summary>
@@ -309,6 +312,11 @@
                 foreach (var deviceKey in room.ListDevice)
                 {
                     this.modelData.dicDeviceTemplateRoom[deviceKey] = room.Id;
+                }
+                foreach (var strMac in room.ListDeviceMac)
+                {
+                    //鐗╃悊璁惧鎵�鍦ㄧ殑鍖哄煙,鍦ㄨ繖涓嚱鏁板闈㈠凡缁忓垵濮嬪寲浜嗚繖涓彉閲�
+                    this.modelData.dicDeviceTemplateRealRoom[strMac] = room.Id;
                 }
                 this.strTempContentData = string.Empty;
                 return true;
@@ -357,7 +365,7 @@
                 //鍙嶅簭鍒楀寲璁惧鐨勪繚瀛樻枃浠跺唴瀹�
                 var tempData = this.DeserializeDeviceDataByDiv(saveDiv, this.strTempContentData);
                 //灏嗚澶囨ā鏉挎暟鎹坊鍔犲叆缂撳瓨(姝ゅ鐗规畩,涓嶉渶瑕佸姞鍏ヨ澶囨ā鏉跨紦瀛樹腑)
-                string mainKey = Common.LocalDevice.Current.GetDeviceMainKeys(tempData.DeviceMac, tempData.DeviceEpoint);
+                string mainKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(tempData.DeviceMac, tempData.DeviceEpoint);
                 this.SetTemplateDeviceDataToMemmory(tempData, this.strTempContentData, mainKey, addToTemplate);
                 this.strTempContentData = string.Empty;
                 return;
@@ -366,7 +374,18 @@
             else if (strData == "#DeviceInfo END#")
             {
                 //鍙嶅簭鍒楀寲璁惧
-                var device = CommonDevice.CommonDeviceByByteString(deviceType, this.strTempContentData);
+                CommonDevice device = null;
+                if (HdlCheckLogic.Current.CheckIsNumber(deviceType) == true)
+                {
+                    //鏁板�煎瀷涓烘柊鏁版嵁,鐩存帴杞崲
+                    device = CommonDevice.CommonDeviceByByteString(Convert.ToInt32(deviceType), this.strTempContentData);
+                }
+                else
+                {
+                    //瀛楃涓插瀷涓烘棫鏁版嵁,闇�瑕佺壒娈婂鐞�
+                    var myType = (DeviceType)Enum.Parse(typeof(DeviceType), deviceType);
+                    device = CommonDevice.CommonDeviceByByteString((int)myType, this.strTempContentData);
+                }
                 if (device != null)
                 {
                     if (this.modelData.dicDeviceInfo.ContainsKey(device.DeviceAddr) == false)
@@ -384,13 +403,6 @@
                 //鍙嶅簭鍒楀寲璁惧
                 var gateway = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway>(this.strTempContentData);
                 this.modelData.dicGatewayInfo[gateway.GwId] = gateway;
-                this.strTempContentData = string.Empty;
-                return;
-            }
-            //鐗╃悊璁惧鐨勬埧闂�
-            else if (strData == "#DeviceTemplateRealRoom END#")
-            {
-                this.modelData.dicDeviceTemplateRealRoom = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(this.strTempContentData);
                 this.strTempContentData = string.Empty;
                 return;
             }
@@ -418,7 +430,7 @@
         private void ReadTemplateFileMethord(Action<string, ModelDeviceSaveEnum, string> AdjustAction)
         {
             //淇濆瓨鐨勮矾寰�
-            string saveFile = DirNameResourse.LocalTemplateDirectory;
+            string saveFile = HdlFileNameResourse.LocalTemplateDirectory;
             saveFile = System.IO.Path.Combine(saveFile, TemplateFileName);
 
             string fileData = HdlFileLogic.Current.ReadFileTextContent(saveFile);
@@ -510,9 +522,17 @@
             {
                 modelData = Newtonsoft.Json.JsonConvert.DeserializeObject<ModelDeviceBindData>(fileData);
             }
-            else if (saveDiv == ModelDeviceSaveEnum.A闈㈡澘鑳屽厜鐏�)
+            else if (saveDiv == ModelDeviceSaveEnum.A闈㈡澘浜害璋冭妭)
             {
-                modelData = Newtonsoft.Json.JsonConvert.DeserializeObject<ModelPanelBackLightInfo>(fileData);
+                modelData = Newtonsoft.Json.JsonConvert.DeserializeObject<ModelPanelBrightnessAdjustInfo>(fileData);
+            }
+            else if (saveDiv == ModelDeviceSaveEnum.A闈㈡澘鑺傝兘妯″紡)
+            {
+                modelData = Newtonsoft.Json.JsonConvert.DeserializeObject<ModelPanelEnergyModeInfo>(fileData);
+            }
+            else if (saveDiv == ModelDeviceSaveEnum.A闈㈡澘鎸囩ず鐏�)
+            {
+                modelData = Newtonsoft.Json.JsonConvert.DeserializeObject<ModelPanelIndicatorLightInfo>(fileData);
             }
             else if (saveDiv == ModelDeviceSaveEnum.A闈㈡澘闇囧姩鍔熻兘)
             {
@@ -581,7 +601,7 @@
                 {
                     fileName = model.FileName;
                     //澶囦唤鏁版嵁宸茬粡瀛樺湪,鏄惁瑕嗙洊?
-                    this.ShowMassage(ShowMsgType.Confirm, "澶囦唤鏁版嵁宸茬粡瀛樺湪,鏄惁瑕嗙洊?", () =>
+                    this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.BackUpDataIsEsixtAndPickUp), () =>
                     {
                         //灏嗘ā鏉挎暟鎹繚瀛樺埌鍒版寚瀹氱殑鏂囦欢澶逛腑
                         this.SaveTemplateDataToLocation2(fileName, backupName);
@@ -609,7 +629,7 @@
                 //灏嗘ā鏉挎暟鎹繚瀛樺埌鍒版寚瀹氱殑鏂囦欢澶逛腑
                 var fileFullName = this.SaveTemplateDataToFile(fileName, backupName);
                 //鑾峰彇鍗囩骇鍥轰欢鏂囦欢
-                var result = HdlFirmwareUpdateLogic.DownLoadTemplateDeviceFirmware(fileFullName, "姝e湪淇濆瓨鍗囩骇鍥轰欢鏁版嵁");
+                var result = HdlFirmwareUpdateLogic.Current.DownLoadTemplateDeviceFirmware(fileFullName, "姝e湪淇濆瓨鍗囩骇鍥轰欢鏁版嵁");
                 if (result == -1)
                 {
                     this.ShowMassage(ShowMsgType.Tip, "淇濆瓨鍗囩骇鍥轰欢鏁版嵁澶辫触");
@@ -617,8 +637,9 @@
                 else
                 {
                     //鏈湴澶囦唤淇濆瓨鎴愬姛
-                    this.ShowMassage(ShowMsgType.Tip, "鏈湴澶囦唤淇濆瓨鎴愬姛");
+                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.SaveLocalBackDataSuccess));
                 }
+                ProgressFormBar.Current.Close();
             });
         }
 
@@ -648,19 +669,22 @@
                     }
                 }
             }
-            var listDevice = Common.LocalDevice.Current.listAllDevice;
+            var listDevice = HdlDeviceCommonLogic.Current.listAllDevice;
             foreach (var device in listDevice)
             {
                 if (listMac.Contains(device.DeviceAddr) == false)
                 {
                     listMac.Add(device.DeviceAddr);
                     //閲嶆柊娣诲姞Mac鍚嶅瓧缂撳瓨
-                    TemplateDeviceDataLogic.Current.ReDeviceMacName(device, Common.LocalDevice.Current.GetDeviceMacName(device));
+                    TemplateDeviceDataLogic.Current.ReDeviceMacName(device, HdlDeviceCommonLogic.Current.GetDeviceMacName(device));
                 }
                 //閲嶆柊娣诲姞绔偣鍚嶅瓧缂撳瓨
-                TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, Common.LocalDevice.Current.GetDeviceEpointName(device));
+                TemplateDeviceDataLogic.Current.ReDeviceEpointName(device, HdlDeviceCommonLogic.Current.GetDeviceEpointName(device));
             }
         }
+        #endregion
+
+        #region 鈻� 鑾峰彇妯℃澘瀵硅薄鐩稿叧___________________
 
         /// <summary>
         /// 鑾峰彇鏈湴鍏ㄩ儴鐨勬ā鏉垮垪琛ㄧ殑鍩烘湰淇℃伅
@@ -671,7 +695,7 @@
             var dicData = new Dictionary<string, List<LocalModelBaseInfo>>();
             var listTime = new List<string>();
 
-            var strPath = DirNameResourse.AllResidenceTemplateDirectory;
+            var strPath = HdlFileNameResourse.AllResidenceTemplateDirectory;
             //鑾峰彇鍏ㄩ儴鏂囦欢
             var arryFile = System.IO.Directory.GetFiles(strPath, "ModelData_*");
             foreach (string modelFile in arryFile)
@@ -700,6 +724,7 @@
                     {
                         var homeInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<TemplateHomeInfo>(homeData);
                         myModel.ListUintContent.AddRange(homeInfo.ListUintContent);
+                        myModel.ListUintName.AddRange(homeInfo.ListUintName);
                         myModel.ResidenceAddressName = homeInfo.ResidenceAddressName;
                     }
                 }
@@ -716,12 +741,320 @@
         }
 
         /// <summary>
+        /// 鑾峰彇浜戠鍏ㄩ儴鐨勬ā鏉垮垪琛ㄧ殑鍩烘湰淇℃伅
+        /// </summary>
+        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+        /// <returns></returns>
+        public List<CloundModelBaseInfo> GetCloundAllModelList(ShowNetCodeMode mode= ShowNetCodeMode.YES)
+        {
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("api/HomebackupCluster/V1/template/info/findAll", RestSharp.Method.GET, null);
+            //妫�娴嬬姸鎬佺爜
+            if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
+            {
+                return new List<CloundModelBaseInfo>();
+            }
+
+            var dicData = new Dictionary<string, List<CloundModelBaseInfo>>();
+            var listTime = new List<string>();
+
+            var listCloundData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<CloundModelBaseInfo>>(result.Data.ToString());
+            foreach (var data in listCloundData)
+            {
+                //鍙樻洿鏃堕棿鏍煎紡
+                data.CreateUtcTime = HdlCommonLogic.Current.ConvertUtcTimeToLocalTime(data.CreateUtcTime).ToString("yyyy.MM.dd HH:mm");
+                if (dicData.ContainsKey(data.CreateUtcTime) == false)
+                {
+                    dicData[data.CreateUtcTime] = new List<CloundModelBaseInfo>();
+                    listTime.Add(data.CreateUtcTime);
+                }
+                dicData[data.CreateUtcTime].Add(data);
+            }
+
+            //鎸夋椂闂存帓搴�
+            listTime.Sort();
+
+            var listData = new List<CloundModelBaseInfo>();
+            for (int i = listTime.Count - 1; i >= 0; i--)
+            {
+                listData.AddRange(dicData[listTime[i]]);
+            }
+            return listData;
+        }
+
+        /// <summary>
         /// 鑾峰彇涓�涓柊鐨勬ā鏉夸繚瀛樻枃浠跺悕
         /// </summary>
         /// <returns></returns>
         public string GetNewTemplateFileName()
         {
-            return "ModelData_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".bin";
+            return "ModelData_Local_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".bin";
+        }
+
+        /// <summary>
+        /// 鑾峰彇涓�涓柊鐨勬ā鏉夸繚瀛樻枃浠跺悕
+        /// </summary>
+        /// <returns></returns>
+        public string GetNewTemplateFileName(DateTime dateTime)
+        {
+            return "ModelData_Local_" + dateTime.ToString("yyyyMMdd_HHmmss") + ".bin";
+        }
+
+        #endregion
+
+        #region 鈻� 涓婁紶妯℃澘澶囦唤_______________________
+
+        /// <summary>
+        /// 涓婁紶妯℃澘澶囦唤(鍐呴儴浣跨敤绾跨▼鏉ユ墽琛�,鏈夎浆鍦堢殑鐣岄潰)
+        /// </summary>
+        /// <param name="i_localTemplate">鏈湴妯℃澘淇℃伅</param>
+        /// <param name="i_saveName">澶囦唤鍚嶅瓧</param>
+        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+        public void UpLoadTemplateData(LocalModelBaseInfo i_localTemplate, string i_saveName, ShowNetCodeMode mode = ShowNetCodeMode.YES)
+        {
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                ProgressBar.Show();
+
+                //鑾峰彇浜戠鐨勬ā鏉垮垪琛�
+                var listTemplate = this.GetCloundAllModelList();
+                foreach (var data in listTemplate)
+                {
+                    if (data.TemplateName == i_saveName)
+                    {
+                        //妯℃澘鍚嶅瓧宸茬粡瀛樺湪
+                        this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.TheTemplateNameIsEsixt));
+                        ProgressBar.Close();
+                        return;
+                    }
+                }
+                //鍒涘缓鏂扮殑妯℃澘澶囦唤
+                var templateId = this.CreatNewTemplateNameToDB(i_saveName, mode);
+                if (templateId == null)
+                {
+                    ProgressBar.Close();
+                    return;
+                }
+
+                //杩欓噷淇敼鎺夋ā鏉挎枃浠堕噷闈㈣杞界殑妯℃澘鍚嶇О
+                string templateFile = System.IO.Path.Combine(HdlFileNameResourse.AllResidenceTemplateDirectory, i_localTemplate.FileName);
+                string binFileData = HdlFileLogic.Current.ReadFileTextContent(templateFile);
+                var arryBinFile = binFileData.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
+                //鏇挎崲鐩爣 杩欓噷鏄ā鏉垮熀鏈俊鎭殑json鏁版嵁
+                string strFileData = arryBinFile[1];
+                var templateBaseInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<LocalModelBaseInfo>(strFileData);
+                templateBaseInfo.ModelName = i_saveName;//鏇存敼鎺夊悕瀛�
+                templateBaseInfo.EditorTime = DateTime.Now.ToString("yyyy.MM.dd HH:mm");//鏇存敼鎺夋椂闂�
+                //鏇挎崲瀵硅薄
+                string replaceDta = Newtonsoft.Json.JsonConvert.SerializeObject(templateBaseInfo);
+                binFileData = binFileData.Replace(strFileData, replaceDta);
+
+                var dicQuery = new Dictionary<string, object>();
+                dicQuery["templateId"] = templateId;
+                dicQuery["fileName"] = "ModelData_Cloud_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".bin";
+
+                //涓婁紶鏂囦欢
+                var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("api/HomebackupCluster/V1/template/file/add", RestSharp.Method.POST,
+                    Encoding.UTF8.GetBytes(binFileData), dicQuery, null, CheckMode.A涓嶆娴�, true);
+
+                //娓呮帀杩欎釜瀛楃涓茬紦瀛�
+                binFileData = null;
+
+                //妫�娴嬬姸鎬佺爜
+                if (HdlCheckLogic.Current.CheckNetCode(result, mode) == true)
+                {
+                    //涓婁紶妯℃澘鎴愬姛
+                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.UploadTemplateSuccess));
+                }
+
+                ProgressBar.Close();
+            });
+        }
+
+        /// <summary>
+        /// 鍦ㄤ簯绔垱寤烘柊鐨勬ā鏉垮悕绉�
+        /// </summary>
+        /// <param name="i_saveName">鏂板悕瀛�</param>
+        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+        /// <returns></returns>
+        private string CreatNewTemplateNameToDB(string i_saveName, ShowNetCodeMode mode = ShowNetCodeMode.YES)
+        {
+            var dicQuery = new Dictionary<string, object>();
+            dicQuery["templateName"] = i_saveName;
+
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("api/HomebackupCluster/V1/template/info/add", RestSharp.Method.POST, null, dicQuery);
+            //妫�娴嬬姸鎬佺爜
+            if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
+            {
+                return null;
+            }
+            var idData = Newtonsoft.Json.JsonConvert.DeserializeObject<IdInfoClass>(result.Data.ToString());
+            return idData.Id;
+        }
+
+        /// <summary>
+        /// 涓婁紶妯℃澘鏂囦欢鐨勪俊鎭�
+        /// </summary>
+        private class TemplateDetailsInfo
+        {
+            /// <summary>
+            /// 鏂囦欢鍚嶅瓧
+            /// </summary>
+            public string DetailName = string.Empty;
+            /// <summary>
+            /// 妯℃澘鍐呭
+            /// </summary>
+            public byte[] DetailContent = null;
+        }
+
+        #endregion
+
+        #region 鈻� 涓嬭浇妯℃澘澶囦唤_______________________
+
+        /// <summary>
+        /// 涓嬭浇妯℃澘澶囦唤(鍐呴儴鏄娇鐢ㄧ嚎绋嬫墽琛�,鏈夌晫闈㈠瀷杩涘害鏉�)
+        /// </summary>
+        /// <param name="i_templateId">鏁版嵁搴撲富閿�</param>
+        /// <param name="i_SuccessAction">涓嬭浇瀹屽叏鎴愬姛涔嬪悗鐨勫洖璋冧簨浠�,鍙傛暟涓轰繚瀛樻ā鏉跨殑鍏ㄨ矾寰�(鍙傛暟null浠h〃澶辫触)</param>
+        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+        public void DownLoadTemplate(string i_templateId, Action<string> i_SuccessAction = null,ShowNetCodeMode mode= ShowNetCodeMode.YES)
+        {
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                ProgressFormBar.Current.Start();
+                ProgressFormBar.Current.SetMsg("姝e湪涓嬭浇妯℃澘鏁版嵁");
+                System.Threading.Thread.Sleep(1500);
+
+                var dicQuery = new Dictionary<string, object>();
+                dicQuery["templateId"] = i_templateId;
+
+                //鑾峰彇鎸囧畾妯℃澘鐨勫垪琛ㄦ枃浠�
+                var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("api/HomebackupCluster/V1/template/file/findAll", RestSharp.Method.GET, null, dicQuery);
+                //妫�娴嬬姸鎬佺爜
+                if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
+                {
+                    //涓嬭浇妯℃澘澶辫触
+                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.DownloadTemplateFail));
+                    ProgressFormBar.Current.Close();
+                    i_SuccessAction?.Invoke(null);
+                    return;
+                }
+                var listFileData = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DownloadTemplateData>>(result.Data.ToString());
+                if (listFileData.Count == 0)
+                {
+                    //涓嬭浇妯℃澘澶辫触
+                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.DownloadTemplateFail));
+                    ProgressFormBar.Current.Close();
+                    i_SuccessAction?.Invoke(null);
+                    return;
+                }
+
+                //涓嬭浇妯℃澘鐨勫唴瀹�
+                var dicQuery2 = new Dictionary<string, object>();
+                dicQuery2["templateId"] = i_templateId;
+                dicQuery2["templateFileId"] = listFileData[0].Id;
+                var byteContent = HdlHttpLogic.Current.RequestByteFromZigbeeHttps("api/HomebackupCluster/V1/template/file/downOne", RestSharp.Method.GET, null, dicQuery2, null, CheckMode.A涓嶆娴�, true, 10);
+                if (byteContent == null || byteContent.Length == 0)
+                {
+                    //涓嬭浇妯℃澘澶辫触
+                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.DownloadTemplateFail));
+                    ProgressFormBar.Current.Close();
+                    i_SuccessAction?.Invoke(null);
+                    return;
+                }
+
+                //瑙f瀽杩欎釜妯℃澘鐨勫悕瀛�
+                var strFileData = this.GetDataFromFileContent(Encoding.UTF8.GetString(byteContent), "#START#", "#TemplateData END#");
+                var templateBaseInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<LocalModelBaseInfo>(strFileData);
+
+                //妫�娴嬫湰鍦扮殑妯℃澘鏄惁鏈夊悓鍚嶇殑
+                var listLocal = this.GetLocalAllModelList();
+                string fileName = listFileData[0].FileName;
+                foreach (var localData in listLocal)
+                {
+                    if (localData.ModelName == templateBaseInfo.ModelName)
+                    {
+                        //鏇挎崲,鐩存帴浣跨敤鏈湴鐨勬ā鏉挎枃浠跺悕瀛�
+                        fileName = localData.FileName;
+                        break;
+                    }
+                }
+
+                //瀛樻垚鏂囦欢
+                string fileFullName = System.IO.Path.Combine(HdlFileNameResourse.AllResidenceTemplateDirectory, fileName);
+                HdlFileLogic.Current.SaveByteToFile(fileFullName, byteContent);
+                byteContent = null;
+
+                //鑾峰彇鍗囩骇鍥轰欢鏂囦欢
+                var result2 = HdlFirmwareUpdateLogic.Current.DownLoadTemplateDeviceFirmware(fileFullName, "姝e湪鑾峰彇鍗囩骇鍥轰欢鏁版嵁");
+                if (result2 == -1)
+                {
+                    this.ShowMassage(ShowMsgType.Tip, "鑾峰彇鍗囩骇鍥轰欢鏁版嵁澶辫触");
+                    ProgressFormBar.Current.Close();
+                    i_SuccessAction?.Invoke(null);
+                    return;
+                }
+                ProgressFormBar.Current.Close();
+                i_SuccessAction?.Invoke(fileFullName);
+            });
+        }
+
+        /// <summary>
+        /// 涓嬭浇妯℃澘
+        /// </summary>
+        private class DownloadTemplateData
+        {
+            /// <summary>
+            /// 鍒涘缓鏃堕棿
+            /// </summary>
+            public string CreateUtcTime = string.Empty;
+            /// <summary>
+            /// 妯℃澘鏂囦欢鍚嶅瓧
+            /// </summary>
+            public string FileName = string.Empty;
+            /// <summary>
+            /// 涓婚敭
+            /// </summary>
+            public string Id = string.Empty;
+        }
+
+        #endregion
+
+        #region 鈻� 鍒犻櫎妯℃澘澶囦唤_______________________
+
+        /// <summary>
+        /// 鍒犻櫎浜戠妯℃澘澶囦唤
+        /// </summary>
+        /// <param name="i_templateId">妯℃澘涓婚敭</param>
+        /// <param name="mode">澶辫触鏃舵槸鍚︽樉绀簍ip娑堟伅</param>
+        /// <returns></returns>
+        public bool DeleteTemplateFromDb(string i_templateId, ShowNetCodeMode mode = ShowNetCodeMode.YES)
+        {
+            var dicQuery = new Dictionary<string, object>();
+            dicQuery["templateId"] = i_templateId;
+
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("api/HomebackupCluster/V1/template/info/delete", RestSharp.Method.DELETE, null, dicQuery);
+            if (result != null && result.Code == HttpMessageEnum.A10605)
+            {
+                //妯℃澘瀵硅薄涓嶅瓨鍦�,褰撳仛鎴愬姛
+                return true;
+            }
+            //妫�娴嬬姸鎬佺爜
+            if (HdlCheckLogic.Current.CheckNetCode(result, mode) == false)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 鍒犻櫎鏈湴妯℃澘澶囦唤
+        /// </summary>
+        /// <param name="i_baseInfo">鏈湴妯℃澘鐨勫熀鏈俊鎭�</param>
+        /// <returns></returns>
+        public void DeleteLocalTemplate(LocalModelBaseInfo i_baseInfo)
+        {
+            var fullFile = System.IO.Path.Combine(HdlFileNameResourse.AllResidenceTemplateDirectory, i_baseInfo.FileName);
+            HdlFileLogic.Current.DeleteFile(fullFile);
         }
 
         #endregion
@@ -766,7 +1099,7 @@
             this.CrearWriteDeviceSelectTemplateData(ref writeText);
 
             //鍐欏叆鍐呭
-            string saveFile = DirNameResourse.AllResidenceTemplateDirectory;
+            string saveFile = HdlFileNameResourse.AllResidenceTemplateDirectory;
             saveFile = System.IO.Path.Combine(saveFile, fileName);
 
             HdlFileLogic.Current.SaveTextToFile(saveFile, writeText);
@@ -778,12 +1111,11 @@
         /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愭ā鏉垮熀鏈暟鎹��
         /// </summary>
         /// <param name="writeText"></param>
-        private void CreatWriteTemplateBaseData(ref string writeText, string backUpName)
+        public void CreatWriteTemplateBaseData(ref string writeText, string backUpName)
         {
             var modelData = new LocalModelBaseInfo();
             modelData.EditorTime = DateTime.Now.ToString("yyyy.MM.dd HH:mm");
             modelData.ModelName = backUpName;
-            modelData.ListUintContent.AddRange(Common.Config.Instance.Home.ListUintContent);
             modelData.FloorCount = Common.Config.Instance.Home.FloorDics.Count;
             modelData.DeviceCount = this.modelData.dicDeviceTemplateData.Count;
             //鍔熻兘鏁�
@@ -792,7 +1124,7 @@
             {
                 if (listData.Count > 0)
                 {
-                    var listDevice = Common.LocalDevice.Current.GetDevicesByMac(listData[0].DeviceMac, false);
+                    var listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(listData[0].DeviceMac, false);
                     funcCount += listDevice.Count;
                 }
             }
@@ -808,10 +1140,11 @@
         /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愭ā鏉夸綇瀹呬俊鎭暟鎹��
         /// </summary>
         /// <param name="writeText"></param>
-        private void CreatWriteTemplateHomeData(ref string writeText)
+        public void CreatWriteTemplateHomeData(ref string writeText)
         {
             var homeData = new TemplateHomeInfo();
             homeData.ResidenceAddressName = Common.Config.Instance.Home.ResidenceAddressName;
+            homeData.ListUintName.AddRange(Common.Config.Instance.Home.ListUintName);
             homeData.ListUintContent.AddRange(Common.Config.Instance.Home.ListUintContent);
 
             writeText += "#START#\r\n";
@@ -824,7 +1157,7 @@
         /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愯澶囨ā鏉挎暟鎹��
         /// </summary>
         /// <param name="writeText"></param>
-        private void CreatWriteDeviceTemplateData(ref string writeText)
+        public void CreatWriteDeviceTemplateData(ref string writeText)
         {
             foreach (var list in this.modelData.dicDeviceTemplateData.Values)
             {
@@ -842,14 +1175,14 @@
         /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愯澶囧璞℃暟鎹��
         /// </summary>
         /// <param name="writeText"></param>
-        private void CreatWriteCommonDeviceData(ref string writeText)
+        public void CreatWriteCommonDeviceData(ref string writeText)
         {
-            var listDevice = Common.LocalDevice.Current.listAllDevice;
+            var listDevice = HdlDeviceCommonLogic.Current.listAllDevice;
             var listCheck = new HashSet<string>();
             foreach (var device in listDevice)
             {
                 //璁惧绔偣
-                writeText += "#DeviceInfo START#" + device.Type.ToString() + "\r\n";
+                writeText += "#DeviceInfo START#" + (int)device.Type + "\r\n";
                 string dataInfo = Newtonsoft.Json.JsonConvert.SerializeObject(device);
                 writeText += dataInfo + "\r\n";
                 writeText += "#DeviceInfo END#\r\n\r\n";
@@ -858,10 +1191,10 @@
                 if (listCheck.Contains(device.DeviceAddr) == false)
                 {
                     listCheck.Add(device.DeviceAddr);
-                    var otaDevice = Common.LocalDevice.Current.GetOTADevice(device.DeviceAddr);
+                    var otaDevice = HdlDeviceCommonLogic.Current.GetOTADevice(device.DeviceAddr);
                     if (otaDevice != null)
                     {
-                        writeText += "#DeviceInfo START#" + otaDevice.Type.ToString() + "\r\n";
+                        writeText += "#DeviceInfo START#" + (int)otaDevice.Type + "\r\n";
                         string dataInfo2 = Newtonsoft.Json.JsonConvert.SerializeObject(otaDevice);
                         writeText += dataInfo2 + "\r\n";
                         writeText += "#DeviceInfo END#\r\n\r\n";
@@ -874,7 +1207,7 @@
         /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愮綉鍏冲璞℃暟鎹��
         /// </summary>
         /// <param name="writeText"></param>
-        private void CreatWriteGatewayData(ref string writeText)
+        public void CreatWriteGatewayData(ref string writeText)
         {
             var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
             foreach (var gateway in listGateway)
@@ -891,7 +1224,7 @@
         /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愬満鏅暟鎹��
         /// </summary>
         /// <param name="writeText"></param>
-        private void CreatWriteSceneData(ref string writeText)
+        public void CreatWriteSceneData(ref string writeText)
         {
             //鍏ㄩ儴鐨勫満鏅�
             var listScene = HdlSceneLogic.Current.GetAllLocalScene();
@@ -909,7 +1242,7 @@
         /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愭埧闂存ā鏉挎暟鎹��
         /// </summary>
         /// <param name="writeText"></param>
-        private void CrearWriteRoomTemplateData(ref string writeText)
+        public void CrearWriteRoomTemplateData(ref string writeText)
         {
             //妤煎眰鏁版嵁
             writeText += "#START#\r\n";
@@ -921,39 +1254,18 @@
             var listRoom = HdlRoomLogic.Current.GetAllListRooms();
             foreach (var room in listRoom)
             {
-                if (room.IsLove == false)
-                {
-                    writeText += "#START#\r\n";
-                    string dataInfo2 = Newtonsoft.Json.JsonConvert.SerializeObject(room);
-                    writeText += dataInfo2 + "\r\n";
-                    writeText += "#RoomInfo END#\r\n\r\n";
-                }
+                writeText += "#START#\r\n";
+                string dataInfo2 = Newtonsoft.Json.JsonConvert.SerializeObject(room);
+                writeText += dataInfo2 + "\r\n";
+                writeText += "#RoomInfo END#\r\n\r\n";
             }
-            //鐗╃悊缃戝叧鎵�鍦ㄧ殑鎴块棿
-            var dicRealRoom = new Dictionary<string, string>();
-            var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
-            foreach (var gateway in listGateway)
-            {
-                dicRealRoom[gateway.GwId] = gateway.RoomId;
-            }
-            //鑾峰彇鍏ㄩ儴鐗╃悊璁惧鎵�灞炴埧闂寸殑璁板綍
-            var dicDeviceRoom = Common.LocalDevice.Current.GetAllRealDeviceRoomData();
-            foreach (var strMac in dicDeviceRoom.Keys)
-            {
-                dicRealRoom[strMac] = dicDeviceRoom[strMac];
-            }
-
-            writeText += "#START#\r\n";
-            string dataInfo = Newtonsoft.Json.JsonConvert.SerializeObject(dicRealRoom);
-            writeText += dataInfo + "\r\n";
-            writeText += "#DeviceTemplateRealRoom END#\r\n\r\n";
         }
 
         /// <summary>
         /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愯澶囧拰缃戝叧閫夋嫨鐨勬ā鏉跨殑鏁版嵁銆�
         /// </summary>
         /// <param name="writeText"></param>
-        private void CrearWriteDeviceSelectTemplateData(ref string writeText)
+        public void CrearWriteDeviceSelectTemplateData(ref string writeText)
         {
             //璁惧閫夋嫨妯℃澘鐨勬暟鎹�
             writeText += "#START#\r\n";
@@ -1011,15 +1323,22 @@
         public void AddDeviceTemplateSelect(string sourceMac, string targetMac)
         {
             //鑾峰彇鏈湴鎸囧畾鐨凪ac鐨勫叏閮ㄨ澶�
-            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(sourceMac, false);
+            var listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(sourceMac, false);
+            var otaDevice = HdlDeviceCommonLogic.Current.GetOTADevice(sourceMac);
+            if (otaDevice != null)
+            {
+                //杩欓噷ota璁惧涔熻鍔犺繘鍘�,閲嶄腑涔嬮噸
+                listDevice.Add(otaDevice);
+            }
 
             foreach (var device in listDevice)
             {
                 //妯℃澘閫夋嫨鐨勬椂鍊�,浠栦滑鐨勭鐐规槸涓�鑷寸殑
-                string localDeviceKey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
-                string templateDeviceKey = Common.LocalDevice.Current.GetDeviceMainKeys(targetMac, device.DeviceEpoint);
+                string localDeviceKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device);
+                string templateDeviceKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(targetMac, device.DeviceEpoint);
 
-                if (this.modelData.dicDeviceTemplateRoom.ContainsKey(templateDeviceKey) == true)
+                if (this.modelData.dicDeviceTemplateRoom.ContainsKey(templateDeviceKey) == true
+                    && (device is OTADevice) == false)
                 {
                     //濡傛灉妯℃澘閲岄潰,杩欎釜绔偣璁剧疆鏈夋埧闂寸殑璇�
                     HdlRoomLogic.Current.ChangedRoom(device, this.modelData.dicDeviceTemplateRoom[templateDeviceKey], false);
@@ -1031,7 +1350,7 @@
                     if (this.modelData.dicDeviceTemplateData.ContainsKey(localDeviceKey) == true)
                     {
                         //鍒犻櫎杩欎釜璁惧鐨勬ā鏉夸繚瀛樻枃浠�
-                        HdlFileLogic.Current.DeleteFile(System.IO.Path.Combine(DirNameResourse.LocalTemplateDirectory, device.FilePath));
+                        HdlFileLogic.Current.DeleteFile(System.IO.Path.Combine(HdlFileNameResourse.LocalTemplateDirectory, device.FilePath));
                         //绉婚櫎褰撳墠绔偣淇濆瓨鐨勬ā鏉挎暟鎹�
                         this.modelData.dicDeviceTemplateData.Remove(localDeviceKey);
                     }
@@ -1047,30 +1366,30 @@
                         //淇敼绔偣缂撳瓨鍚嶅瓧
                         if (tempData.DataSaveDiv == ModelDeviceSaveEnum.A绔偣鍚嶇О)
                         {
-                            Common.LocalDevice.Current.SetEpointName(device, ((ModelDeviceEpointNameInfo)tempData).deviceEpointName);
+                            HdlDeviceCommonLogic.Current.SetEpointName(device, ((ModelDeviceEpointNameInfo)tempData).deviceEpointName);
                         }
                         else if (tempData.DataSaveDiv == ModelDeviceSaveEnum.A璁惧鍚嶇О)
                         {
-                            Common.LocalDevice.Current.SetMacName(device, ((ModelDeviceMacNameInfo)tempData).deviceMacName);
+                            HdlDeviceCommonLogic.Current.SetMacName(device, ((ModelDeviceMacNameInfo)tempData).deviceMacName);
                         }
                     }
                 }
                 //涓嶇濡備綍,閮介渶瑕佸垯閲嶆柊淇濆瓨鎴愭枃浠�
-                this.SaveDeviceMemmoryData(device);
+                this.SaveDeviceMemmoryData(device.DeviceAddr, device.DeviceEpoint);
                 //杩樺師鍙婂彉鏇村満鏅殑鎵ц鐩爣
                 //this.RecoverAndChangedSceneAdjustTarget(device, targetMac);
             }
             //鏇存敼鐗╃悊璁惧鎵�鍦ㄧ殑鎴块棿
             if (this.modelData.dicDeviceTemplateRealRoom.ContainsKey(targetMac) == true)
             {
-                Common.LocalDevice.Current.SaveRealDeviceRoomId(listDevice, this.modelData.dicDeviceTemplateRealRoom[targetMac], false);
+                HdlRoomLogic.Current.SaveRealDeviceRoomId(listDevice, this.modelData.dicDeviceTemplateRealRoom[targetMac], false);
             }
 
             //璁板綍缂撳瓨
             this.modelData.dicDeviceTemplateSelect[sourceMac] = targetMac;
             //淇濆瓨鐨勮矾寰�
             string fileData = Newtonsoft.Json.JsonConvert.SerializeObject(this.modelData.dicDeviceTemplateSelect);
-            HdlFileLogic.Current.SaveTextToFile(DirNameResourse.DeviceTemplateSelectFile, fileData);
+            HdlFileLogic.Current.SaveTextToFile(HdlFileNameResourse.DeviceTemplateSelectFile, fileData);
         }
 
         /// <summary>
@@ -1176,7 +1495,7 @@
         public void RemoveDeviceTemplateSelect(string sourceMac)
         {
             ////鑾峰彇鏈湴鎸囧畾鐨凪ac鐨勫叏閮ㄨ澶�
-            //var listDevice = Common.LocalDevice.Current.GetDevicesByMac(sourceMac, false);
+            //var listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(sourceMac, false);
             //foreach (var device in listDevice)
             //{
             //    //杩樺師鍦烘櫙鐨勬墽琛岀洰鏍�
@@ -1187,7 +1506,7 @@
             this.modelData.dicDeviceTemplateSelect.Remove(sourceMac);
             //淇濆瓨鐨勮矾寰�
             string fileData = Newtonsoft.Json.JsonConvert.SerializeObject(this.modelData.dicDeviceTemplateSelect);
-            HdlFileLogic.Current.SaveTextToFile(DirNameResourse.DeviceTemplateSelectFile, fileData);
+            HdlFileLogic.Current.SaveTextToFile(HdlFileNameResourse.DeviceTemplateSelectFile, fileData);
         }
 
         /// <summary>
@@ -1201,20 +1520,20 @@
             this.modelData.dicGatewayTemplateSelect[sourceGwid] = targetGwid;
             //淇濆瓨鐨勮矾寰�
             string fileData = Newtonsoft.Json.JsonConvert.SerializeObject(this.modelData.dicGatewayTemplateSelect);
-            HdlFileLogic.Current.SaveTextToFile(DirNameResourse.GatewayTemplateSelectFile, fileData);
+            HdlFileLogic.Current.SaveTextToFile(HdlFileNameResourse.GatewayTemplateSelectFile, fileData);
 
             //鍙樻洿缃戝叧鎴块棿
             if (this.modelData.dicDeviceTemplateRealRoom.ContainsKey(targetGwid) == true)
             {
-                HdlGatewayLogic.Current.ChangedGatewayRoom(sourceGwid, this.modelData.dicDeviceTemplateRealRoom[targetGwid]);
+                HdlRoomLogic.Current.ChangedGatewayRoom(sourceGwid, this.modelData.dicDeviceTemplateRealRoom[targetGwid]);
             }
             //鍙樻洿缃戝叧鍚嶅瓧
-            if (this.modelData.dicGatewayInfo.ContainsKey(targetGwid) == true)
-            {
-                var localGateway = HdlGatewayLogic.Current.GetLocalGateway(sourceGwid);
-                string gwName = HdlGatewayLogic.Current.GetGatewayName(this.modelData.dicGatewayInfo[targetGwid]);
-                HdlGatewayLogic.Current.ReName(localGateway, gwName);
-            }
+            //if (this.modelData.dicGatewayInfo.ContainsKey(targetGwid) == true)
+            //{
+            //    var localGateway = HdlGatewayLogic.Current.GetLocalGateway(sourceGwid);
+            //    string gwName = HdlGatewayLogic.Current.GetGatewayName(this.modelData.dicGatewayInfo[targetGwid]);
+            //    HdlGatewayLogic.Current.ReName(localGateway, gwName);
+            //}
         }
 
         /// <summary>
@@ -1228,7 +1547,7 @@
             this.modelData.dicGatewayTemplateSelect.Remove(sourceGwid);
             //淇濆瓨鐨勮矾寰�
             string fileData = Newtonsoft.Json.JsonConvert.SerializeObject(this.modelData.dicGatewayTemplateSelect);
-            HdlFileLogic.Current.SaveTextToFile(DirNameResourse.GatewayTemplateSelectFile, fileData);
+            HdlFileLogic.Current.SaveTextToFile(HdlFileNameResourse.GatewayTemplateSelectFile, fileData);
         }
 
         /// <summary>
@@ -1306,8 +1625,8 @@
             this.modelData.dicDeviceTemplateSelect = new Dictionary<string, string>();
             this.modelData.dicGatewayTemplateSelect = new Dictionary<string, string>();
             //鍒犳帀杩欎袱涓繚瀛橀�夋嫨妯℃澘鐨勬枃浠�
-            HdlFileLogic.Current.DeleteFile(DirNameResourse.DeviceTemplateSelectFile);
-            HdlFileLogic.Current.DeleteFile(DirNameResourse.GatewayTemplateSelectFile);
+            HdlFileLogic.Current.DeleteFile(HdlFileNameResourse.DeviceTemplateSelectFile);
+            HdlFileLogic.Current.DeleteFile(HdlFileNameResourse.GatewayTemplateSelectFile);
         }
 
         #endregion
@@ -1396,17 +1715,17 @@
         public void DeleteDevice(CommonDevice device)
         {
             //鍒犻櫎淇濆瓨鏂囦欢
-            string saveFile = DirNameResourse.LocalTemplateDirectory;
+            string saveFile = HdlFileNameResourse.LocalTemplateDirectory;
             saveFile = System.IO.Path.Combine(saveFile, device.FilePath);
             HdlFileLogic.Current.DeleteFile(saveFile);
 
             //绉婚櫎妯℃澘缂撳瓨
-            this.modelData.dicDeviceTemplateData.Remove(Common.LocalDevice.Current.GetDeviceMainKeys(device));
+            this.modelData.dicDeviceTemplateData.Remove(HdlDeviceCommonLogic.Current.GetDeviceMainKeys(device));
             //绉婚櫎璁惧閫夋嫨缂撳瓨
             if (this.modelData.dicDeviceTemplateSelect.ContainsKey(device.DeviceAddr) == true)
             {
                 this.modelData.dicDeviceTemplateSelect.Remove(device.DeviceAddr);
-                HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceTemplateSelectFile, this.modelData.dicDeviceTemplateSelect);
+                HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.DeviceTemplateSelectFile, this.modelData.dicDeviceTemplateSelect);
             }
         }
 
@@ -1415,20 +1734,21 @@
         #region 鈻� 淇濆瓨璁惧缂撳瓨_______________________
 
         /// <summary>
-        /// 淇濆瓨璁惧缂撳瓨
+        /// 淇濆瓨璁惧缂撳瓨(鑰冭檻鏈夌殑璁惧鐢ㄧ殑鏄�200绔偣,鎵�浠ヨ繖閲屾渶濂戒笉鐢ㄨ澶囧璞′綔涓哄弬鏁�)
         /// </summary>
-        /// <param name="device">璁惧瀵硅薄</param>
-        public void SaveDeviceMemmoryData(CommonDevice device)
+        /// <param name="deviceMac">璁惧mac</param>
+        /// <param name="deviceEpoint">璁惧Epoint</param>
+        public void SaveDeviceMemmoryData(string deviceMac, int deviceEpoint)
         {
-            string mainkey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+            string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(deviceMac, deviceEpoint);
             if (this.modelData.dicDeviceTemplateData.ContainsKey(mainkey) == false)
             {
                 return;
             }
 
             //淇濆瓨璺緞
-            string saveFile = DirNameResourse.LocalTemplateDirectory;
-            saveFile = System.IO.Path.Combine(saveFile, device.FilePath);
+            string saveFile = HdlFileNameResourse.LocalTemplateDirectory;
+            saveFile = System.IO.Path.Combine(saveFile, "Device_" + mainkey);
 
             var listData = this.modelData.dicDeviceTemplateData[mainkey];
             if (listData.Count == 0)
@@ -1470,7 +1790,7 @@
                     continue;
                 }
                 //鍙栨湰鍦癘ta璁惧瀵硅薄
-                var localOta = Common.LocalDevice.Current.GetOTADevice(localMac);
+                var localOta = HdlDeviceCommonLogic.Current.GetOTADevice(localMac);
                 if (localOta == null)
                 {
                     //搴旇涓嶄細杩涙潵,鍗充娇杩涙潵,鎴戜篃涓嶇煡閬撲负浠�涔�
@@ -1483,7 +1803,7 @@
                     {
                         //鍙涓よ�呯殑鍥轰欢鐗堟湰涓嶄竴鏍�,骞朵笖鏈湴鏈夎繖涓崌绾у浐浠�,鍒欓兘闇�瑕佸崌绾�
                         if (localOta.ImgVersion != tempDevice.ImgVersion
-                            && HdlFirmwareUpdateLogic.IsEsixtDeviceFirmwareFile((OTADevice)tempDevice) == true)
+                            && HdlFirmwareUpdateLogic.Current.IsEsixtDeviceFirmwareFile((OTADevice)tempDevice) == true)
                         {
                             //鎸夌綉鍏冲垎缁�
                             if (dicGatewayDevice.ContainsKey(localOta.CurrentGateWayId) == false)
@@ -1491,7 +1811,7 @@
                                 dicGatewayDevice[localOta.CurrentGateWayId] = new Dictionary<string, string>();
                             }
                             var dicDevice = dicGatewayDevice[localOta.CurrentGateWayId];
-                            dicDevice[localMac] = HdlFirmwareUpdateLogic.GetDeviceFirmwareFile((OTADevice)tempDevice);
+                            dicDevice[localMac] = HdlFirmwareUpdateLogic.Current.GetDeviceFirmwareFile((OTADevice)tempDevice);
                         }
                         break;
                     }
@@ -1533,7 +1853,7 @@
                 if (tempGateway.LinuxFirmwareVersion != localGateway.LinuxFirmwareVersion)
                 {
                     //Linux鍗囩骇鍥轰欢鏂囦欢鍏ㄨ矾寰�
-                    string updateFile = HdlFirmwareUpdateLogic.GetGatewayLinuxFirmwareFile(tempGateway);
+                    string updateFile = HdlFirmwareUpdateLogic.Current.GetGatewayLinuxFirmwareFile(tempGateway);
                     if (System.IO.File.Exists(updateFile) == true)
                     {
                         //濡傛灉瀛樺湪鐨勮瘽
@@ -1548,7 +1868,7 @@
                 if (tempGateway.CoordinatorFirmwareVersion != localGateway.CoordinatorFirmwareVersion)
                 {
                     //鍗忚皟鍣ㄥ崌绾у浐浠舵枃浠跺叏璺緞
-                    string updateFile = HdlFirmwareUpdateLogic.GetGatewayCoordinatorFirmwareFile(tempGateway);
+                    string updateFile = HdlFirmwareUpdateLogic.Current.GetGatewayCoordinatorFirmwareFile(tempGateway);
                     if (System.IO.File.Exists(updateFile) == true)
                     {
                         //濡傛灉瀛樺湪鐨勮瘽
@@ -1570,7 +1890,7 @@
                             if (localCode.DriveCode == tempCode.DriveCode && localCode.DriveFwVersion != tempCode.DriveFwVersion)
                             {
                                 //铏氭嫙椹卞姩鍗囩骇鍥轰欢鏂囦欢鍏ㄨ矾寰�
-                                string updateFile = HdlFirmwareUpdateLogic.GetGatewayDriveCodeFirmwareFile(tempCode);
+                                string updateFile = HdlFirmwareUpdateLogic.Current.GetGatewayDriveCodeFirmwareFile(tempCode);
                                 if (System.IO.File.Exists(updateFile) == true)
                                 {
                                     //濡傛灉瀛樺湪鐨勮瘽
@@ -1683,7 +2003,7 @@
         /// <param name="templateFileName">妯℃澘鏂囦欢鐨勫悕瀛�(鍏ㄤ綇瀹呭瓨鏀剧殑妯℃澘)</param>
         public void CopyTemplateFileToLocalDirectory(string templateFileName)
         {
-            string sourceFile = System.IO.Path.Combine(DirNameResourse.AllResidenceTemplateDirectory, templateFileName);
+            string sourceFile = System.IO.Path.Combine(HdlFileNameResourse.AllResidenceTemplateDirectory, templateFileName);
 
             this.CopyTemplateFileToLocalDirectory2(sourceFile);
         }
@@ -1700,7 +2020,7 @@
             }
 
             //淇濆瓨鐨勮矾寰�
-            string targetFile = DirNameResourse.LocalTemplateDirectory;
+            string targetFile = HdlFileNameResourse.LocalTemplateDirectory;
             targetFile = System.IO.Path.Combine(targetFile, TemplateFileName);
 
             try { System.IO.File.Copy(fullTemplateName, targetFile, true); }
@@ -1713,7 +2033,7 @@
         public void DeleteAllLocalFile()
         {
             //鑾峰彇杩欎釜璺緞涓嬮潰鍏ㄩ儴鐨勬枃浠�
-            var listFile = HdlFileLogic.Current.GetFileFromDirectory(DirNameResourse.LocalTemplateDirectory, false); ;
+            var listFile = HdlFileLogic.Current.GetFileFromDirectory(HdlFileNameResourse.LocalTemplateDirectory, false); ;
             foreach (var file in listFile)
             {
                 HdlFileLogic.Current.DeleteFile(file);
@@ -1782,7 +2102,7 @@
         /// <returns></returns>
         private string GetDeviceModelId(string deviceMac)
         {
-            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceMac);
+            var listDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(deviceMac);
             foreach (var device in listDevice)
             {
                 if (device.ModelIdentifier != string.Empty)
@@ -1794,14 +2114,14 @@
         }
 
         /// <summary>
-        /// 鑾峰彇璁惧淇濆瓨鐨勬ā鏉垮璞�
+        /// 鑾峰彇璁惧淇濆瓨鐨勬ā鏉垮璞�(鑰冭檻鏈夌殑璁惧鐢ㄧ殑鏄�200绔偣,鎵�浠ヨ繖閲屾渶濂戒笉鐢ㄨ澶囧璞′綔涓哄弬鏁�)
         /// </summary>
         /// <param name="device"></param>
         /// <param name="saveEnum"></param>
         /// <returns></returns>
-        public TemplateDeviceDataCommon GetDeviceModelDataClass(CommonDevice device, ModelDeviceSaveEnum saveEnum, TemplateDeviceDataCommon newClass)
+        public TemplateDeviceDataCommon GetDeviceModelDataClass(string deviceMac, int deviceEpoint, ModelDeviceSaveEnum saveEnum, TemplateDeviceDataCommon newClass)
         {
-            string mainkey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
+            string mainkey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(deviceMac, deviceEpoint);
 
             //鍒涘缓瀛樺偍绌洪棿
             if (this.modelData.dicDeviceTemplateData.ContainsKey(mainkey) == false)
@@ -1818,8 +2138,8 @@
             }
             //鏂板缓涓�涓柊鐨勫璞�
             newClass.DataSaveDiv = saveEnum;
-            newClass.DeviceEpoint = device.DeviceEpoint;
-            newClass.DeviceMac = device.DeviceAddr;
+            newClass.DeviceEpoint = deviceEpoint;
+            newClass.DeviceMac = deviceMac;
 
             //榛樿鍒涘缓涓�涓储寮曚綅
             newClass.ListReceiveResult.Add(string.Empty);
@@ -1840,36 +2160,7 @@
         /// <param name="buttonText">鎸夐挳鐨勬枃鏈�</param>
         private void ShowMassage(ShowMsgType msgType, string msg, Action action = null, string buttonText = null)
         {
-            //绌哄璞℃椂锛屼笉鏄剧ず
-            if (string.IsNullOrEmpty(msg))
-            {
-                return;
-            }
-            Application.RunOnMainThread(() =>
-            {
-                var alert = new ShowMsgControl(msgType, msg, buttonText);
-                if (action != null)
-                {
-                    alert.ConfirmClickEvent += () =>
-                    {
-                        try
-                        {
-                            //鍥炶皟鍑芥暟
-                            action?.Invoke();
-                        }
-                        catch (Exception ex)
-                        {
-                            //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け
-                            this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
-
-                            //Log鍑哄姏
-                            HdlLogLogic.Current.WriteLog(ex);
-                        }
-                        action = null;
-                    };
-                }
-                alert.Show();
-            });
+            HdlMessageLogic.Current.ShowMassage(msgType, msg, action, buttonText);
         }
 
         #endregion

--
Gitblit v1.8.0