From e90209beae6a4e822cecb18e6889f8bda23f630e Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 14 十二月 2020 11:16:06 +0800 Subject: [PATCH] 合并了晾衣架(非新云端) --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlFirmwareUpdateLogic.cs | 191 +++++++++++++---------------------------------- 1 files changed, 54 insertions(+), 137 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Common/Logic/HdlFirmwareUpdateLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlFirmwareUpdateLogic.cs similarity index 75% rename from ZigbeeApp/Shared/Phone/Common/Logic/HdlFirmwareUpdateLogic.cs rename to ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlFirmwareUpdateLogic.cs index 0b33e20..17e781e 100644 --- a/ZigbeeApp/Shared/Phone/Common/Logic/HdlFirmwareUpdateLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlFirmwareUpdateLogic.cs @@ -3,48 +3,25 @@ using System.Text; using ZigBee.Device; -namespace Shared.Phone +namespace Shared.Phone.UserCenter { /// <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 void DoUpdateNextFirmware() + public static void DoUpdateNextFirmware() { //涓嬩竴涓鎵ц鏇存柊鐨勭綉鍏� - DeviceUpdateCommon gwControl = null; + HdlDeviceUpdateCommonLogic gwControl = null; //涓嬩竴涓鎵ц鏇存柊鐨勮澶� - DeviceUpdateCommon deviceControl = null; - foreach (var contr in HdlFirmwareUpdateResourse.dicUpdateList.Values) + HdlDeviceUpdateCommonLogic deviceControl = null; + foreach (var contr in FirmwareUpdateResourse.dicUpdateList.Values) { //濡傛灉鍒殑杩樺湪鍗囩骇涓�,鍒欎笉鍐嶅鐞� if (contr.IsFinishUpdate == false) @@ -95,7 +72,7 @@ /// <param name="HardwareVersion">纭欢鐗堟湰</param> /// <param name="imgType">闀滃儚绫诲瀷</param> /// <returns></returns> - public int AddFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) + public static int AddFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) { //妫�娴嬫湰鍦版槸鍚﹀凡缁忔湁杩欎釜缂撳瓨浜� if (IsEsixtFirmwareVersionInfo(levelType, HardwareVersion, imgType) == true) @@ -154,21 +131,14 @@ /// <param name="levelType"></param> /// <param name="pra"></param> /// <returns></returns> - private int GetFirmwareVersionAndSetToMemmory(FirmwareLevelType levelType, GetFirmwareVersionPra pra) + private static int GetFirmwareVersionAndSetToMemmory(FirmwareLevelType levelType, GetFirmwareVersionPra pra) { - var result = this.RequestZigbeeHttps("FirmwareMana/DetectionPlatformUploadFirmware", pra, 4); - if (result == null || result.Length == 0) + var listCheck = new List<string> { "NotCheck" }; + string resultValue = UserCenterLogic.GetResponseDataByRequestHttps("FirmwareMana/DetectionPlatformUploadFirmware", false, pra, listCheck, false); + if (string.IsNullOrEmpty(resultValue) == true) { 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) { @@ -176,11 +146,12 @@ } //纭欢鐗堟湰 - if (HdlFirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) + Dictionary<string, FirmwareHardInfo> dicHardData = null; + if (FirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) { - HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType] = new Dictionary<string, FirmwareHardInfo>(); + FirmwareUpdateResourse.dicFirmwareInfo[levelType] = new Dictionary<string, FirmwareHardInfo>(); } - var dicHardData = HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType]; + dicHardData = FirmwareUpdateResourse.dicFirmwareInfo[levelType]; foreach (var data in verResult.PageData) { @@ -247,7 +218,7 @@ /// <param name="imgType">闀滃儚绫诲瀷</param> /// <param name="nowVersion">鐜板湪鐨勭増鏈�</param> /// <returns></returns> - public FirmwareVersionInfo GetFirmwareMostVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType, int nowVersion) + public static FirmwareVersionInfo GetFirmwareMostVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType, int nowVersion) { //闀滃儚绫诲瀷 var listdata = GetFirmwareVersionListInfo(levelType, HardwareVersion, imgType); @@ -283,14 +254,14 @@ /// <param name="HardwareVersion">纭欢鐗堟湰</param> /// <param name="imgType">闀滃儚绫诲瀷</param> /// <returns></returns> - public List<FirmwareVersionInfo> GetFirmwareVersionListInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) + public static List<FirmwareVersionInfo> GetFirmwareVersionListInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) { - if (HdlFirmwareUpdateResourse.dicFirmwareInfo == null || HdlFirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) + if (FirmwareUpdateResourse.dicFirmwareInfo == null || FirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) { return new List<FirmwareVersionInfo>(); } //纭欢鐗堟湰鍙风骇鍒� - var dicHard = HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType]; + var dicHard = FirmwareUpdateResourse.dicFirmwareInfo[levelType]; //纭欢鐗堟湰 if (dicHard.ContainsKey(HardwareVersion) == false) @@ -320,14 +291,14 @@ /// <param name="levelType">鍥轰欢闃剁骇鍒嗙被</param> /// <param name="HardwareVersion">纭欢鐗堟湰</param> /// <returns></returns> - public Dictionary<string, FirmwareImgTypeInfo> GetImageVersionListInfo(FirmwareLevelType levelType, string HardwareVersion) + public static Dictionary<string, FirmwareImgTypeInfo> GetImageVersionListInfo(FirmwareLevelType levelType, string HardwareVersion) { - if (HdlFirmwareUpdateResourse.dicFirmwareInfo == null || HdlFirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) + if (FirmwareUpdateResourse.dicFirmwareInfo == null || FirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) { return new Dictionary<string, FirmwareImgTypeInfo>(); } //纭欢鐗堟湰鍙风骇鍒� - var dicHard = HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType]; + var dicHard = FirmwareUpdateResourse.dicFirmwareInfo[levelType]; //纭欢鐗堟湰 if (dicHard.ContainsKey(HardwareVersion) == false) @@ -350,7 +321,7 @@ /// <param name="imgType">闀滃儚绫诲瀷</param> /// <param name="nowVersion">鐜板湪鐨勭増鏈�</param> /// <returns></returns> - public FirmwareVersionInfo GetFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType, int nowVersion) + public static FirmwareVersionInfo GetFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType, int nowVersion) { //闀滃儚绫诲瀷 var listdata = GetFirmwareVersionListInfo(levelType, HardwareVersion, imgType); @@ -380,20 +351,20 @@ /// <param name="HardwareVersion">纭欢鐗堟湰</param> /// <param name="imgType">闀滃儚绫诲瀷</param> /// <returns></returns> - private bool IsEsixtFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) + private static bool IsEsixtFirmwareVersionInfo(FirmwareLevelType levelType, string HardwareVersion, string imgType) { //绗竴澶х被 - if (HdlFirmwareUpdateResourse.dicFirmwareInfo == null || HdlFirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) + if (FirmwareUpdateResourse.dicFirmwareInfo == null || FirmwareUpdateResourse.dicFirmwareInfo.ContainsKey(levelType) == false) { return false; } //纭欢 - if (HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType].ContainsKey(HardwareVersion) == false) + if (FirmwareUpdateResourse.dicFirmwareInfo[levelType].ContainsKey(HardwareVersion) == false) { return false; } //闀滃儚 - if (HdlFirmwareUpdateResourse.dicFirmwareInfo[levelType][HardwareVersion].dicImgType.ContainsKey(imgType) == false) + if (FirmwareUpdateResourse.dicFirmwareInfo[levelType][HardwareVersion].dicImgType.ContainsKey(imgType) == false) { return false; } @@ -405,7 +376,7 @@ /// </summary> /// <param name="device">璁惧瀵硅薄</param> /// <returns></returns> - public bool IsEsixtDeviceFirmwareFile(OTADevice device) + public static bool IsEsixtDeviceFirmwareFile(OTADevice device) { var fileFullName = GetDeviceFirmwareFile(device); return System.IO.File.Exists(fileFullName); @@ -416,11 +387,11 @@ /// </summary> /// <param name="device">璁惧瀵硅薄</param> /// <returns></returns> - public string GetDeviceFirmwareFile(OTADevice device) + public static string GetDeviceFirmwareFile(OTADevice device) { //纭欢鐗堟湰_闀滃儚ID_鍥轰欢鐗堟湰 string fileName = device.HwVersion + "_" + device.ImgTypeId + "_" + device.ImgVersion; - return System.IO.Path.Combine(HdlFileNameResourse.FirmwareUpdateDirectory, "Device_" + fileName + ".ota"); + return System.IO.Path.Combine(DirNameResourse.FirmwareUpdateDirectory, "Device_" + fileName + ".ota"); } /// <summary> @@ -428,10 +399,10 @@ /// </summary> /// <param name="zbGateway">缃戝叧瀵硅薄</param> /// <returns></returns> - public string GetGatewayLinuxFirmwareFile(ZbGateway zbGateway) + public static string GetGatewayLinuxFirmwareFile(ZbGateway zbGateway) { string fileName = zbGateway.LinuxHardVersion + "_" + zbGateway.LinuxImageType + "_" + zbGateway.LinuxFirmwareVersion; - return System.IO.Path.Combine(HdlFileNameResourse.FirmwareUpdateDirectory, "Linux_" + fileName + ".ota"); + return System.IO.Path.Combine(DirNameResourse.FirmwareUpdateDirectory, "Linux_" + fileName + ".ota"); } /// <summary> @@ -439,10 +410,10 @@ /// </summary> /// <param name="zbGateway">缃戝叧瀵硅薄</param> /// <returns></returns> - public string GetGatewayCoordinatorFirmwareFile(ZbGateway zbGateway) + public static string GetGatewayCoordinatorFirmwareFile(ZbGateway zbGateway) { string fileName = zbGateway.CoordinatorHardVersion + "_" + zbGateway.CoordinatorImageId + "_" + zbGateway.CoordinatorFirmwareVersion; - return System.IO.Path.Combine(HdlFileNameResourse.FirmwareUpdateDirectory, "Coordinator_" + fileName + ".ota"); + return System.IO.Path.Combine(DirNameResourse.FirmwareUpdateDirectory, "Coordinator_" + fileName + ".ota"); } /// <summary> @@ -450,10 +421,10 @@ /// </summary> /// <param name="codeObj">铏氭嫙椹卞姩鏁版嵁</param> /// <returns></returns> - public string GetGatewayDriveCodeFirmwareFile(ZbGatewayData.DriveCodeObj codeObj) + public static string GetGatewayDriveCodeFirmwareFile(ZbGatewayData.DriveCodeObj codeObj) { string fileName = codeObj.DriveHwVersion + "_" + codeObj.DriveImageType + "_" + codeObj.DriveFwVersion; - return System.IO.Path.Combine(HdlFileNameResourse.FirmwareUpdateDirectory, "DriveCode_" + fileName + ".ota"); + return System.IO.Path.Combine(DirNameResourse.FirmwareUpdateDirectory, "DriveCode_" + fileName + ".ota"); } #endregion @@ -465,7 +436,7 @@ /// </summary> /// <param name="fullFileName"></param> /// <param name="i_Msg"></param> - public int DownLoadTemplateDeviceFirmware(string fullFileName, string i_Msg) + public static int DownLoadTemplateDeviceFirmware(string fullFileName, string i_Msg) { //浠庢ā鏉垮綋涓幏鍙栬澶囧拰缃戝叧瀵硅薄 var listTempDevice = new List<OTADevice>(); @@ -490,7 +461,7 @@ System.Threading.Thread.Sleep(1000); var dicFirmwareName = new Dictionary<string, string>(); - var fileData = HdlFileLogic.Current.ReadFileTextContent(HdlFileNameResourse.FirmwareUpdateList); + var fileData = HdlFileLogic.Current.ReadFileTextContent(DirNameResourse.FirmwareUpdateList); if (fileData != null) { //鏈湴瀛樻斁鐨勫浐浠跺師鏉ョ殑鍚嶅瓧(鍥犱负璁惧鍗囩骇鏃�,瀹冮渶瑕佽瘑鍒枃浠跺悕瀛楅噷闈㈠寘鍚殑鐗规畩瀛楃) @@ -499,7 +470,7 @@ } //鍥轰欢瀛樺偍璺緞 - string firmwareDir = HdlFileNameResourse.FirmwareUpdateDirectory; + string firmwareDir = DirNameResourse.FirmwareUpdateDirectory; int nowCount = 0; int macCount = listVersion.Count + listAcUpdate.Count; @@ -512,7 +483,7 @@ { ProgressFormBar.Current.Close(); //淇濆瓨鍒楄〃鍚嶅瓧 - HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.FirmwareUpdateList, dicFirmwareName); + HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName); return -1; } //鑾峰彇褰撳墠杩欎釜鐗堟湰鐨勫浐浠朵俊鎭� @@ -524,12 +495,13 @@ continue; } //鍘讳笅杞借繖涓浐浠� - var byteData = this.DowLoadFirmware(versionData.levelType, versionFirmware.DistributedMark); + var pra = new { RequestVersion = Common.CommonPage.RequestVersion, DistributedMark = versionFirmware.DistributedMark }; + var byteData = UserCenterLogic.GetByteResponseDataByRequestHttps("FirmwareMana/DownloadPlatformUploadFirmware", false, pra, new List<string> { "NotCheck" }, true); if (byteData == null) { ProgressFormBar.Current.Close(); //淇濆瓨鍒楄〃鍚嶅瓧 - HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.FirmwareUpdateList, dicFirmwareName); + HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName); return -1; } //淇濆瓨鍥轰欢 @@ -543,12 +515,13 @@ for (int i = 0; i < listAcUpdate.Count; i++) { //涓嬭浇绌鸿皟妯″潡 - var deviceFirmwareByte = this.DowLoadFirmware(FirmwareLevelType.A璁惧, listAcUpdate[i].DistributedMark); + var pra = new { RequestVersion = Common.CommonPage.RequestVersion, DistributedMark = listAcUpdate[i].DistributedMark }; + var deviceFirmwareByte = UserCenterLogic.GetByteResponseDataByRequestHttps("FirmwareMana/DownloadPlatformUploadFirmware", false, pra, new List<string> { "NotCheck" }, true); if (deviceFirmwareByte == null) { ProgressFormBar.Current.Close(); //淇濆瓨鍒楄〃鍚嶅瓧 - HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.FirmwareUpdateList, dicFirmwareName); + HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName); return -1; } //淇濆瓨鍥轰欢 @@ -561,7 +534,7 @@ } //淇濆瓨鍒楄〃鍚嶅瓧 - HdlFileLogic.Current.SaveFileContent(HdlFileNameResourse.FirmwareUpdateList, dicFirmwareName); + HdlFileLogic.Current.SaveFileContent(DirNameResourse.FirmwareUpdateList, dicFirmwareName); ProgressFormBar.Current.Close(); return 1; @@ -573,10 +546,10 @@ /// <param name="listDevice">璁惧鍒楄〃</param> /// <param name="listGateway">缃戝叧鍒楄〃</param> /// <returns></returns> - private List<TemplateDeviceVersion> GetNeedToDownLoadVersionData(List<OTADevice> listDevice, List<ZbGateway> listGateway) + private static List<TemplateDeviceVersion> GetNeedToDownLoadVersionData(List<OTADevice> listDevice, List<ZbGateway> listGateway) { //瀛樺偍璺緞 - string firmwareDir = HdlFileNameResourse.FirmwareUpdateDirectory; + string firmwareDir = DirNameResourse.FirmwareUpdateDirectory; HdlFileLogic.Current.CreateDirectory(firmwareDir); var listVersion = new List<TemplateDeviceVersion>(); @@ -632,7 +605,7 @@ }); } //杩欎釜缃戝叧闇�瑕佹湁铏氭嫙椹卞姩杩欎釜涓滆タ鎵嶈 - if (gateway.LinuxImageType != 6) + if (HdlGatewayLogic.Current.CheckGatewayHadDriveCode(gateway) == true) { //铏氭嫙椹卞姩鍙� foreach (var data in gateway.DriveCodeList) @@ -663,16 +636,16 @@ /// </summary> /// <param name="listDevice">璁惧鍒楄〃</param> /// <param name="listTaget">涓庤繑鍥炲�煎搴旂殑涓滆タ</param> - private List<FirmwareVersionInfo> GetNeedDownLoadAirConditionerModule(List<OTADevice> listDevice, ref List<OTADevice> listTaget) + private static List<FirmwareVersionInfo> GetNeedDownLoadAirConditionerModule(List<OTADevice> listDevice, ref List<OTADevice> listTaget) { var listUpdate = new List<FirmwareVersionInfo>(); //鍥轰欢瀛樺偍璺緞 - string firmwareDir = HdlFileNameResourse.FirmwareUpdateDirectory; + string firmwareDir = DirNameResourse.FirmwareUpdateDirectory; foreach (var otaDevice in listDevice) { - var myType = HdlDeviceCommonLogic.Current.GetMyDeviceEnumInfo(new List<CommonDevice> { otaDevice }); - if (myType.ConcreteType != DeviceConcreteType.AirConditioner_ZbGateway) + var myType = Common.LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice> { otaDevice }); + if (myType.ConcreteType != Common.DeviceConcreteType.AirConditioner_ZbGateway) { //鍙鐞嗕腑澶┖璋� continue; @@ -689,37 +662,6 @@ } } 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> @@ -751,31 +693,6 @@ #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> @@ -783,7 +700,7 @@ /// </summary> /// <param name="Info"></param> /// <param name="remark"></param> - private void DoAdjustFirmwareInformation(FirmwareVersionInfo Info, string remark) + private static void DoAdjustFirmwareInformation(FirmwareVersionInfo Info, string remark) { if (string.IsNullOrEmpty(remark) == true) { -- Gitblit v1.8.0