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 | 628 +++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 475 insertions(+), 153 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/TemplateData/TemplateCommonLogic.cs b/ZigbeeApp/Shared/Phone/TemplateData/TemplateCommonLogic.cs index 4537e58..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); } } @@ -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) => { @@ -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#") @@ -192,6 +192,7 @@ { //鍙垵濮嬪寲涓�娆�,鏈夋埧闂存椂浠h〃宸茬粡涓嶆槸绗竴娆″姞杞戒簡 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; @@ -204,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) { @@ -260,11 +266,19 @@ 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(); + + //鏃犳ā鏉挎ā寮忔椂,鎭㈠澶囦唤鐨勬椂鍊�,鎶婂浠芥枃浠跺垹闄� + if (Common.Config.Instance.Home.TemplateMode != 2) + { + //瀛樻斁鐨勮矾寰� + string fullFile = System.IO.Path.Combine(HdlFileNameResourse.LocalTemplateDirectory, TemplateFileName); + HdlFileLogic.Current.DeleteFile(fullFile); + } } /// <summary> @@ -285,6 +299,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; } @@ -297,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; @@ -345,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; @@ -354,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) @@ -372,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; } @@ -406,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); @@ -498,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闈㈡澘闇囧姩鍔熻兘) { @@ -569,7 +601,7 @@ { fileName = model.FileName; //澶囦唤鏁版嵁宸茬粡瀛樺湪,鏄惁瑕嗙洊? - this.ShowMassage(ShowMsgType.Confirm, "澶囦唤鏁版嵁宸茬粡瀛樺湪,鏄惁瑕嗙洊?", () => + this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.BackUpDataIsEsixtAndPickUp), () => { //灏嗘ā鏉挎暟鎹繚瀛樺埌鍒版寚瀹氱殑鏂囦欢澶逛腑 this.SaveTemplateDataToLocation2(fileName, backupName); @@ -597,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, "淇濆瓨鍗囩骇鍥轰欢鏁版嵁澶辫触"); @@ -605,8 +637,9 @@ else { //鏈湴澶囦唤淇濆瓨鎴愬姛 - this.ShowMassage(ShowMsgType.Tip, "鏈湴澶囦唤淇濆瓨鎴愬姛"); + this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.SaveLocalBackDataSuccess)); } + ProgressFormBar.Current.Close(); }); } @@ -636,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> /// 鑾峰彇鏈湴鍏ㄩ儴鐨勬ā鏉垮垪琛ㄧ殑鍩烘湰淇℃伅 @@ -659,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) @@ -688,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; } } @@ -704,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 @@ -754,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); @@ -766,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; //鍔熻兘鏁� @@ -780,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; } } @@ -796,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"; @@ -812,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) { @@ -830,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"; @@ -846,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"; @@ -862,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) @@ -879,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(); @@ -897,7 +1242,7 @@ /// 鐢熸垚鍐欏叆鏂囦欢鐨勩�愭埧闂存ā鏉挎暟鎹�� /// </summary> /// <param name="writeText"></param> - private void CrearWriteRoomTemplateData(ref string writeText) + public void CrearWriteRoomTemplateData(ref string writeText) { //妤煎眰鏁版嵁 writeText += "#START#\r\n"; @@ -909,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"; @@ -999,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); @@ -1019,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); } @@ -1035,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> @@ -1164,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) //{ // //杩樺師鍦烘櫙鐨勬墽琛岀洰鏍� @@ -1175,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> @@ -1189,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> @@ -1216,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> @@ -1294,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 @@ -1384,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); } } @@ -1403,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) @@ -1458,7 +1790,7 @@ continue; } //鍙栨湰鍦癘ta璁惧瀵硅薄 - var localOta = Common.LocalDevice.Current.GetOTADevice(localMac); + var localOta = HdlDeviceCommonLogic.Current.GetOTADevice(localMac); if (localOta == null) { //搴旇涓嶄細杩涙潵,鍗充娇杩涙潵,鎴戜篃涓嶇煡閬撲负浠�涔� @@ -1471,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) @@ -1479,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; } @@ -1493,9 +1825,9 @@ /// 鑾峰彇闇�瑕佸崌绾х殑缃戝叧瀵硅薄(key:鏈湴缃戝叧鐨刬d 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,28 +1846,37 @@ } 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) { //Linux鍗囩骇鍥轰欢鏂囦欢鍏ㄨ矾寰� - string updateFile = HdlFirmwareUpdateLogic.GetGatewayLinuxFirmwareFile(tempGateway); + string updateFile = HdlFirmwareUpdateLogic.Current.GetGatewayLinuxFirmwareFile(tempGateway); 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; } } //鍗忚皟鍣ㄧ増鏈瘮杈� if (tempGateway.CoordinatorFirmwareVersion != localGateway.CoordinatorFirmwareVersion) { //鍗忚皟鍣ㄥ崌绾у浐浠舵枃浠跺叏璺緞 - string updateFile = HdlFirmwareUpdateLogic.GetGatewayCoordinatorFirmwareFile(tempGateway); + string updateFile = HdlFirmwareUpdateLogic.Current.GetGatewayCoordinatorFirmwareFile(tempGateway); 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,18 +1887,28 @@ 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); + string updateFile = HdlFirmwareUpdateLogic.Current.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; } } @@ -1652,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); } @@ -1669,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); } @@ -1682,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); @@ -1751,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) @@ -1763,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) @@ -1787,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); @@ -1809,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