From 0d9f64668fd7350d6a21fd157e32009a96d98134 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期三, 16 十二月 2020 13:09:08 +0800 Subject: [PATCH] 新云端代码Ver1.2 --- ZigbeeApp/Shared/Phone/Common/Logic/HdlFirmwareUpdateLogic.cs | 191 ++++++++++++++++++++++++++++++++++------------- 1 files changed, 137 insertions(+), 54 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlFirmwareUpdateLogic.cs b/ZigbeeApp/Shared/Phone/Common/Logic/HdlFirmwareUpdateLogic.cs similarity index 75% rename from ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlFirmwareUpdateLogic.cs rename to ZigbeeApp/Shared/Phone/Common/Logic/HdlFirmwareUpdateLogic.cs index 17e781e..3afccae 100644 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlFirmwareUpdateLogic.cs +++ b/ZigbeeApp/Shared/Phone/Common/Logic/HdlFirmwareUpdateLogic.cs @@ -3,25 +3,48 @@ using System.Text; using ZigBee.Device; -namespace Shared.Phone.UserCenter +namespace Shared.Phone { /// <summary> /// 鍥轰欢鍗囩骇鐨勯�昏緫绫� /// </summary> public class HdlFirmwareUpdateLogic { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鍥轰欢鍗囩骇鐨勯�昏緫绫� + /// </summary> + private static HdlFirmwareUpdateLogic m_Current = null; + /// <summary> + /// 鍥轰欢鍗囩骇鐨勯�昏緫绫� + /// </summary> + public static HdlFirmwareUpdateLogic Current + { + get + { + if (m_Current == null) + { + m_Current = new HdlFirmwareUpdateLogic(); + } + return m_Current; + } + } + + #endregion + #region 鈻� 鎵ц鍥轰欢鏇存柊_______________________ /// <summary> /// 鎵ц涓嬩竴涓浐浠剁殑鏇存柊 /// </summary> - public static void DoUpdateNextFirmware() + public void DoUpdateNextFirmware() { //涓嬩竴涓鎵ц鏇存柊鐨勭綉鍏� - HdlDeviceUpdateCommonLogic gwControl = null; + DeviceUpdateCommon gwControl = null; //涓嬩竴涓鎵ц鏇存柊鐨勮澶� - HdlDeviceUpdateCommonLogic deviceControl = null; - foreach (var contr in FirmwareUpdateResourse.dicUpdateList.Values) + DeviceUpdateCommon deviceControl = null; + foreach (var contr in HdlFirmwareUpdateResourse.dicUpdateList.Values) { //濡傛灉鍒殑杩樺湪鍗囩骇涓�,鍒欎笉鍐嶅鐞� if (contr.IsFinishUpdate == false) @@ -72,7 +95,7 @@ /// <param name="HardwareVersion">纭欢鐗堟湰</param> /// <param name="imgType">闀滃儚绫诲瀷</param> /// <returns></returns> - public static int AddFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) + public int AddFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) { //妫�娴嬫湰鍦版槸鍚﹀凡缁忔湁杩欎釜缂撳瓨浜� if (IsEsixtFirmwareVersionInfo(levelType, HardwareVersion, imgType) == true) @@ -131,14 +154,21 @@ /// <param name="levelType"></param> /// <param name="pra"></param> /// <returns></returns> - private static int GetFirmwareVersionAndSetToMemmory(FirmwareLevelType levelType, GetFirmwareVersionPra pra) + private int GetFirmwareVersionAndSetToMemmory(FirmwareLevelType levelType, GetFirmwareVersionPra pra) { - var listCheck = new List<string> { "NotCheck" }; - string resultValue = UserCenterLogic.GetResponseDataByRequestHttps("FirmwareMana/DetectionPlatformUploadFirmware", false, pra, listCheck, false); - if (string.IsNullOrEmpty(resultValue) == true) + var result = this.RequestZigbeeHttps("FirmwareMana/DetectionPlatformUploadFirmware", pra, 4); + if (result == null || result.Length == 0) { return -1; } + var jobject = Newtonsoft.Json.Linq.JObject.Parse(Encoding.UTF8.GetString(result)); + if (jobject.Property("StateCode") == null || jobject["StateCode"].ToString().ToUpper() != "SUCCESS") + { + return -1; + } + + string resultValue = jobject["ResponseData"].ToString(); + var verResult = Newtonsoft.Json.JsonConvert.DeserializeObject<FirmwareVersionResult>(resultValue); if (verResult.PageData.Count == 0) { @@ -146,12 +176,11 @@ } //纭欢鐗堟湰 - Dictionary<string, FirmwareHardInfo> dicHardData = null; - if (FirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) + if (HdlFirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) { - FirmwareUpdateResourse.dicFirmwareInfo[levelType] = new Dictionary<string, FirmwareHardInfo>(); + HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType] = new Dictionary<string, FirmwareHardInfo>(); } - dicHardData = FirmwareUpdateResourse.dicFirmwareInfo[levelType]; + var dicHardData = HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType]; foreach (var data in verResult.PageData) { @@ -218,7 +247,7 @@ /// <param name="imgType">闀滃儚绫诲瀷</param> /// <param name="nowVersion">鐜板湪鐨勭増鏈�</param> /// <returns></returns> - public static FirmwareVersionInfo GetFirmwareMostVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType, int nowVersion) + public FirmwareVersionInfo GetFirmwareMostVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType, int nowVersion) { //闀滃儚绫诲瀷 var listdata = GetFirmwareVersionListInfo(levelType, HardwareVersion, imgType); @@ -254,14 +283,14 @@ /// <param name="HardwareVersion">纭欢鐗堟湰</param> /// <param name="imgType">闀滃儚绫诲瀷</param> /// <returns></returns> - public static List<FirmwareVersionInfo> GetFirmwareVersionListInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) + public List<FirmwareVersionInfo> GetFirmwareVersionListInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) { - if (FirmwareUpdateResourse.dicFirmwareInfo == null || FirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) + if (HdlFirmwareUpdateResourse.dicFirmwareInfo == null || HdlFirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) { return new List<FirmwareVersionInfo>(); } //纭欢鐗堟湰鍙风骇鍒� - var dicHard = FirmwareUpdateResourse.dicFirmwareInfo[levelType]; + var dicHard = HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType]; //纭欢鐗堟湰 if (dicHard.ContainsKey(HardwareVersion) == false) @@ -291,14 +320,14 @@ /// <param name="levelType">鍥轰欢闃剁骇鍒嗙被</param> /// <param name="HardwareVersion">纭欢鐗堟湰</param> /// <returns></returns> - public static Dictionary<string, FirmwareImgTypeInfo> GetImageVersionListInfo(FirmwareLevelType levelType, string HardwareVersion) + public Dictionary<string, FirmwareImgTypeInfo> GetImageVersionListInfo(FirmwareLevelType levelType, string HardwareVersion) { - if (FirmwareUpdateResourse.dicFirmwareInfo == null || FirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) + if (HdlFirmwareUpdateResourse.dicFirmwareInfo == null || HdlFirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) { return new Dictionary<string, FirmwareImgTypeInfo>(); } //纭欢鐗堟湰鍙风骇鍒� - var dicHard = FirmwareUpdateResourse.dicFirmwareInfo[levelType]; + var dicHard = HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType]; //纭欢鐗堟湰 if (dicHard.ContainsKey(HardwareVersion) == false) @@ -321,7 +350,7 @@ /// <param name="imgType">闀滃儚绫诲瀷</param> /// <param name="nowVersion">鐜板湪鐨勭増鏈�</param> /// <returns></returns> - public static FirmwareVersionInfo GetFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType, int nowVersion) + public FirmwareVersionInfo GetFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType, int nowVersion) { //闀滃儚绫诲瀷 var listdata = GetFirmwareVersionListInfo(levelType, HardwareVersion, imgType); @@ -351,20 +380,20 @@ /// <param name="HardwareVersion">纭欢鐗堟湰</param> /// <param name="imgType">闀滃儚绫诲瀷</param> /// <returns></returns> - private static bool IsEsixtFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) + private bool IsEsixtFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) { //绗竴澶х被 - if (FirmwareUpdateResourse.dicFirmwareInfo == null || FirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) + if (HdlFirmwareUpdateResourse.dicFirmwareInfo == null || HdlFirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) { return false; } //纭欢 - if (FirmwareUpdateResourse.dicFirmwareInfo[levelType].ContainsKey(HardwareVersion) == false) + if (HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType].ContainsKey(HardwareVersion) == false) { return false; } //闀滃儚 - if (FirmwareUpdateResourse.dicFirmwareInfo[levelType][HardwareVersion].dicImgType.ContainsKey(imgType) == false) + if (HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType][HardwareVersion].dicImgType.ContainsKey(imgType) == false) { return false; } @@ -376,7 +405,7 @@ /// </summary> /// <param name="device">璁惧瀵硅薄</param> /// <returns></returns> - public static bool IsEsixtDeviceFirmwareFile(OTADevice device) + public bool IsEsixtDeviceFirmwareFile(OTADevice device) { var fileFullName = GetDeviceFirmwareFile(device); return System.IO.File.Exists(fileFullName); @@ -387,11 +416,11 @@ /// </summary> /// <param name="device">璁惧瀵硅薄</param> /// <returns></returns> - public static string GetDeviceFirmwareFile(OTADevice device) + public string GetDeviceFirmwareFile(OTADevice device) { //纭欢鐗堟湰_闀滃儚ID_鍥轰欢鐗堟湰 string fileName = device.HwVersion + "_" + device.ImgTypeId + "_" + device.ImgVersion; - return System.IO.Path.Combine(DirNameResourse.FirmwareUpdateDirectory, "Device_" + fileName + ".ota"); + return System.IO.Path.Combine(HdlFileNameResourse.FirmwareUpdateDirectory, "Device_" + fileName + ".ota"); } /// <summary> @@ -399,10 +428,10 @@ /// </summary> /// <param name="zbGateway">缃戝叧瀵硅薄</param> /// <returns></returns> - public static string GetGatewayLinuxFirmwareFile(ZbGateway zbGateway) + public string GetGatewayLinuxFirmwareFile(ZbGateway zbGateway) { string fileName = zbGateway.LinuxHardVersion + "_" + zbGateway.LinuxImageType + "_" + zbGateway.LinuxFirmwareVersion; - return System.IO.Path.Combine(DirNameResourse.FirmwareUpdateDirectory, "Linux_" + fileName + ".ota"); + return System.IO.Path.Combine(HdlFileNameResourse.FirmwareUpdateDirectory, "Linux_" + fileName + ".ota"); } /// <summary> @@ -410,10 +439,10 @@ /// </summary> /// <param name="zbGateway">缃戝叧瀵硅薄</param> /// <returns></returns> - public static string GetGatewayCoordinatorFirmwareFile(ZbGateway zbGateway) + public string GetGatewayCoordinatorFirmwareFile(ZbGateway zbGateway) { string fileName = zbGateway.CoordinatorHardVersion + "_" + zbGateway.CoordinatorImageId + "_" + zbGateway.CoordinatorFirmwareVersion; - return System.IO.Path.Combine(DirNameResourse.FirmwareUpdateDirectory, "Coordinator_" + fileName + ".ota"); + return System.IO.Path.Combine(HdlFileNameResourse.FirmwareUpdateDirectory, "Coordinator_" + fileName + ".ota"); } /// <summary> @@ -421,10 +450,10 @@ /// </summary> /// <param name="codeObj">铏氭嫙椹卞姩鏁版嵁</param> /// <returns></returns> - public static string GetGatewayDriveCodeFirmwareFile(ZbGatewayData.DriveCodeObj codeObj) + public string GetGatewayDriveCodeFirmwareFile(ZbGatewayData.DriveCodeObj codeObj) { string fileName = codeObj.DriveHwVersion + "_" + codeObj.DriveImageType + "_" + codeObj.DriveFwVersion; - return System.IO.Path.Combine(DirNameResourse.FirmwareUpdateDirectory, "DriveCode_" + fileName + ".ota"); + return System.IO.Path.Combine(HdlFileNameResourse.FirmwareUpdateDirectory, "DriveCode_" + fileName + ".ota"); } #endregion @@ -436,12 +465,12 @@ /// </summary> /// <param name="fullFileName"></param> /// <param name="i_Msg"></param> - public static int DownLoadTemplateDeviceFirmware(string fullFileName, string i_Msg) + public int DownLoadTemplateDeviceFirmware(string fullFileName, string i_Msg) { //浠庢ā鏉垮綋涓幏鍙栬澶囧拰缃戝叧瀵硅薄 var listTempDevice = new List<OTADevice>(); var listTempGateway = new List<ZbGateway>(); - TemplateData.TemplateCommonLogic.Current.GetDeviceObjectFromTemplate(fullFileName, ref listTempDevice, ref listTempGateway); + HdlTemplateCommonLogic.Current.GetDeviceObjectFromTemplate(fullFileName, ref listTempDevice, ref listTempGateway); //鑾峰彇闇�瑕佷笅杞界殑鍥轰欢鏁版嵁 var listVersion = GetNeedToDownLoadVersionData(listTempDevice, listTempGateway); @@ -461,7 +490,7 @@ System.Threading.Thread.Sleep(1000); var dicFirmwareName = new Dictionary<string, string>(); - var fileData = HdlFileLogic.Current.ReadFileTextContent(DirNameResourse.FirmwareUpdateList); + var fileData = HdlFileLogic.Current.ReadFileTextContent(HdlFileNameResourse.FirmwareUpdateList); if (fileData != null) { //鏈湴瀛樻斁鐨勫浐浠跺師鏉ョ殑鍚嶅瓧(鍥犱负璁惧鍗囩骇鏃�,瀹冮渶瑕佽瘑鍒枃浠跺悕瀛楅噷闈㈠寘鍚殑鐗规畩瀛楃) @@ -470,7 +499,7 @@ } //鍥轰欢瀛樺偍璺緞 - string firmwareDir = DirNameResourse.FirmwareUpdateDirectory; + string firmwareDir = HdlFileNameResourse.FirmwareUpdateDirectory; int nowCount = 0; int macCount = listVersion.Count + listAcUpdate.Count; @@ -483,7 +512,7 @@ { ProgressFormBar.Current.Close(); //淇濆瓨鍒楄〃鍚嶅瓧 - HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName); + HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.FirmwareUpdateList, dicFirmwareName); return -1; } //鑾峰彇褰撳墠杩欎釜鐗堟湰鐨勫浐浠朵俊鎭� @@ -495,13 +524,12 @@ continue; } //鍘讳笅杞借繖涓浐浠� - var pra = new { RequestVersion = Common.CommonPage.RequestVersion, DistributedMark = versionFirmware.DistributedMark }; - var byteData = UserCenterLogic.GetByteResponseDataByRequestHttps("FirmwareMana/DownloadPlatformUploadFirmware", false, pra, new List<string> { "NotCheck" }, true); + var byteData = this.DowLoadFirmware(versionData.levelType, versionFirmware.DistributedMark); if (byteData == null) { ProgressFormBar.Current.Close(); //淇濆瓨鍒楄〃鍚嶅瓧 - HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName); + HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.FirmwareUpdateList, dicFirmwareName); return -1; } //淇濆瓨鍥轰欢 @@ -515,13 +543,12 @@ for (int i = 0; i < listAcUpdate.Count; i++) { //涓嬭浇绌鸿皟妯″潡 - var pra = new { RequestVersion = Common.CommonPage.RequestVersion, DistributedMark = listAcUpdate[i].DistributedMark }; - var deviceFirmwareByte = UserCenterLogic.GetByteResponseDataByRequestHttps("FirmwareMana/DownloadPlatformUploadFirmware", false, pra, new List<string> { "NotCheck" }, true); + var deviceFirmwareByte = this.DowLoadFirmware(FirmwareLevelType.A璁惧, listAcUpdate[i].DistributedMark); if (deviceFirmwareByte == null) { ProgressFormBar.Current.Close(); //淇濆瓨鍒楄〃鍚嶅瓧 - HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName); + HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.FirmwareUpdateList, dicFirmwareName); return -1; } //淇濆瓨鍥轰欢 @@ -534,7 +561,7 @@ } //淇濆瓨鍒楄〃鍚嶅瓧 - HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName); + HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.FirmwareUpdateList, dicFirmwareName); ProgressFormBar.Current.Close(); return 1; @@ -546,10 +573,10 @@ /// <param name="listDevice">璁惧鍒楄〃</param> /// <param name="listGateway">缃戝叧鍒楄〃</param> /// <returns></returns> - private static List<TemplateDeviceVersion> GetNeedToDownLoadVersionData(List<OTADevice> listDevice, List<ZbGateway> listGateway) + private List<TemplateDeviceVersion> GetNeedToDownLoadVersionData(List<OTADevice> listDevice, List<ZbGateway> listGateway) { //瀛樺偍璺緞 - string firmwareDir = DirNameResourse.FirmwareUpdateDirectory; + string firmwareDir = HdlFileNameResourse.FirmwareUpdateDirectory; HdlFileLogic.Current.CreateDirectory(firmwareDir); var listVersion = new List<TemplateDeviceVersion>(); @@ -636,16 +663,16 @@ /// </summary> /// <param name="listDevice">璁惧鍒楄〃</param> /// <param name="listTaget">涓庤繑鍥炲�煎搴旂殑涓滆タ</param> - private static List<FirmwareVersionInfo> GetNeedDownLoadAirConditionerModule(List<OTADevice> listDevice, ref List<OTADevice> listTaget) + private List<FirmwareVersionInfo> GetNeedDownLoadAirConditionerModule(List<OTADevice> listDevice, ref List<OTADevice> listTaget) { var listUpdate = new List<FirmwareVersionInfo>(); //鍥轰欢瀛樺偍璺緞 - string firmwareDir = DirNameResourse.FirmwareUpdateDirectory; + string firmwareDir = HdlFileNameResourse.FirmwareUpdateDirectory; foreach (var otaDevice in listDevice) { - var myType = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice> { otaDevice }); - if (myType.ConcreteType != Common.DeviceConcreteType.AirConditioner_ZbGateway) + var myType = HdlDeviceCommonLogic.Current.GetMyDeviceEnumInfo(new List<CommonDevice> { otaDevice }); + if (myType.ConcreteType != DeviceConcreteType.AirConditioner_ZbGateway) { //鍙鐞嗕腑澶┖璋� continue; @@ -662,6 +689,37 @@ } } return listUpdate; + } + + /// <summary> + /// 涓嬭浇鍥轰欢 + /// </summary> + /// <param name="levelType">涓嬭浇鐨勭被鍨�</param> + /// <param name="i_Mainkey">涓婚敭</param> + /// <returns></returns> + public byte[] DowLoadFirmware(FirmwareLevelType levelType, string i_Mainkey) + { + var pra = new { RequestVersion = Common.CommonPage.RequestVersion, DistributedMark = i_Mainkey }; + + //榛樿涓�10绉� + int waitTime = 10; + if (levelType != FirmwareLevelType.A璁惧) + { + //缃戝叧鐨勬瘮杈冨ぇ,缁欏涓�鐐规椂闂� + waitTime = 25; + } + + int count = 3; + while (count > 0) + { + var result = this.RequestZigbeeHttps("FirmwareMana/DownloadPlatformUploadFirmware", pra, waitTime); + if (result != null) + { + return result.Length == 0 ? null : result; + } + count--; + } + return null; } /// <summary> @@ -693,6 +751,31 @@ #endregion + #region 鈻� 璁块棶浜戠鐨勬柟娉昣____________________ + + /// <summary> + /// 浜戠鍥轰欢鐨勭綉鍧� + /// </summary> + public string RequestHttpsHost = "https://global.hdlcontrol.com/ProposedProductionApi"; + + /// <summary> + /// 璁块棶浜戠鍥轰欢鐨勬柟娉� + /// </summary> + /// <param name="i_interfaceName">鎺ュ彛鍚嶅瓧</param> + /// <param name="i_body">body鏁版嵁</param> + /// <param name="i_waitTime">瓒呮椂鏃堕棿</param> + /// <returns></returns> + public byte[] RequestZigbeeHttps(string i_interfaceName, object i_body, int i_waitTime) + { + string fullUrl = this.RequestHttpsHost + "/" + i_interfaceName; + + var result = HdlHttpLogic.Current.DoRequestZigbeeHttps(fullUrl, null, RestSharp.Method.POST, i_body, null, null, CheckMode.A涓嶆娴�, i_waitTime, false); + + return result; + } + + #endregion + #region 鈻� 涓�鑸柟娉昣__________________________ /// <summary> @@ -700,7 +783,7 @@ /// </summary> /// <param name="Info"></param> /// <param name="remark"></param> - private static void DoAdjustFirmwareInformation(FirmwareVersionInfo Info, string remark) + private void DoAdjustFirmwareInformation(FirmwareVersionInfo Info, string remark) { if (string.IsNullOrEmpty(remark) == true) { -- Gitblit v1.8.0