From ac3c6b64df51443519d3a27fa8cf0d25dd6ff6d7 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期四, 04 三月 2021 09:37:54 +0800 Subject: [PATCH] Merge branch 'wjc' --- Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs | 149 ++++++++++++++++++++++++++++++++++++------------- 1 files changed, 110 insertions(+), 39 deletions(-) diff --git a/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs b/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs index 0359a0d..73c912e 100644 --- a/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs +++ b/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using Shared; using Shared.IO; +using Shared.SimpleControl; namespace Shared { @@ -72,7 +73,7 @@ public static long ConvertDateTimeLong () { System.DateTime startTime = TimeZoneInfo.ConvertTimeToUtc (new System.DateTime (2020, 1, 1)); - long l = (long)(Math.Round ((DateTime.Now - startTime).TotalSeconds, 1) * 10); + long l = (long)(Math.Round ((DateTime.Now - startTime).TotalMilliseconds, 1) / 10); if (l <= LastTime) l = LastTime + 1; LastTime = l; return l; @@ -116,6 +117,71 @@ } #endregion + /// <summary> + /// 涓�閿皢鏈湴鍥炶矾璁惧鍜屽満鏅暟鎹浆鎹� + /// 鐒跺悗涓婁紶oid銆乻id銆佷互鍙婂満鏅垪琛� + /// </summary> + /// <returns></returns> + public void OneclickUpload () + { + MainPage.Loading.Start ("Uploading..."); + System.Threading.Tasks.Task.Run (() => { + try { + var res = false; + res = UploadOidAndSidList (); + if (res) { + res = GetFunctionList (); + if (res) { + res = UploadSecneList (); + } + } + + if (res) { + Utlis.ShowAlertOnMainThread (Language.StringByID (SimpleControl.R.MyInternationalizationString.SuccessfullySynchronizedToTheCloud)); + } else { + Utlis.ShowAlertOnMainThread (Language.StringByID (SimpleControl.R.MyInternationalizationString.FailedToSyncToTheCloud)); + } + + } catch { + + } finally { + Application.RunOnMainThread (() => { + MainPage.Loading.Hide (); + }); + } + }); + + } + + /// <summary> + /// + /// </summary> + /// <returns></returns> + public bool GetFunctionList () + { + var res = false; + try { + var revertObj = HttpServerRequest.Current.GetDeviceList (); + if (revertObj.Code == StateCode.SUCCESS) { + var devcieFunctionRes = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieFunctionRes> (revertObj.Data.ToString ()); + if (devcieFunctionRes != null && devcieFunctionRes.list != null && devcieFunctionRes.list.Count > 0) { + CommonConfig.Current.FunctionList = devcieFunctionRes.list; + } else { + CommonConfig.Current.FunctionList = new List<Function> (); + } + CommonConfig.Current.Save (); + res = true; + } else { + //鎻愮ず閿欒 + IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); + } + } catch { + + } + + return res; + } + #region 鈻� 涓婁紶鍦烘櫙鍒楄〃___________________________ /// <summary> /// 涓婁紶鍦烘櫙鍒楄〃 @@ -134,21 +200,16 @@ hdlLinkSceneList.Add (mHDLLinkScene); } } - //2.涓婁紶鍦烘櫙 - //2.1涓嶅瓨鍦紝闇�瑕佹柊涓婁紶鐨� + + //鍏ㄩ噺鍚屾鍦烘櫙 res = UploadSceneList (hdlLinkSceneList); - //2.2宸插瓨鍦紝闇�瑕佹洿鏂扮殑 - //if (res) { - // var updateLinkSceneList = new List<HDLLinkScene> (); - // res = UploadSceneList (updateLinkSceneList); - //} + } catch (Exception ex){ Utlis.WriteLine ("catch :" + ex.ToString ()); } return res; } - /// <summary> /// 鑾峰彇鎵�鏈夊満鏅垪琛� @@ -205,14 +266,14 @@ } /// <summary> - /// + /// 鍏ㄩ噺鍚屾鍦烘櫙 /// </summary> /// <param name="mScene"></param> bool UploadSceneList (List<HDLLinkScene> hdlLinkSceneList) { var res = false; try { - var revertObj = HttpServerRequest.Current.AddScene (hdlLinkSceneList); + var revertObj = HttpServerRequest.Current.SecneSyncList (hdlLinkSceneList); if (revertObj.Code == StateCode.SUCCESS) { res = true; } else { @@ -224,25 +285,25 @@ return res; } - /// <summary> - /// - /// </summary> - /// <param name="mScene"></param> - bool UpdateSceneList (List<HDLLinkScene> updateLinkSceneList) - { - var res = false; - try { - var revertObj = HttpServerRequest.Current.EditScene (updateLinkSceneList); - if (revertObj.Code == StateCode.SUCCESS) { - res = true; - } else { - IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); - } - } catch { + ///// <summary> + ///// + ///// </summary> + ///// <param name="mScene"></param> + //bool UpdateSceneList (List<HDLLinkScene> updateLinkSceneList) + //{ + // var res = false; + // try { + // var revertObj = HttpServerRequest.Current.EditScene (updateLinkSceneList); + // if (revertObj.Code == StateCode.SUCCESS) { + // res = true; + // } else { + // IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); + // } + // } catch { - } - return res; - } + // } + // return res; + //} /// <summary> /// 鍘熺敓鍗忚Scene 杞崲鎴� HDLLinkScene鏁版嵁鏍煎紡 @@ -271,13 +332,18 @@ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (jsonInfo); var mSceneFunction = new SceneFunction (); mSceneFunction.sid = function.sid; - //1.Brightness + //1.on_off var status = new List<SceneFunctionStatus> (); + status.Add (new SceneFunctionStatus () { + key = FunctionAttributeKey.OnOff, + value = commonNew.CurrentBrightness > 0 ? "on" : "off", + }); + //2.Brightness status.Add (new SceneFunctionStatus () { key = FunctionAttributeKey.Brightness, value = commonNew.CurrentBrightness.ToString(), }); - //2.Delay + //3.Delay status.Add (new SceneFunctionStatus () { key = FunctionAttributeKey.Delay, value = (commonNew.DelayTimeHeight * 256 + commonNew.DelayTimeLow).ToString (), @@ -330,19 +396,24 @@ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (jsonInfo); var mSceneFunction = new SceneFunction (); mSceneFunction.sid = function.sid; - //1.Brightness + //1.on_off var status = new List<SceneFunctionStatus> (); + status.Add (new SceneFunctionStatus () { + key = FunctionAttributeKey.OnOff, + value = commonNew.CurrentBrightness > 0 ? "on" : "off", + }); + //2.Brightness status.Add (new SceneFunctionStatus () { key = FunctionAttributeKey.Brightness, value = commonNew.CurrentBrightness.ToString (), }); - //2.Delay + //3.Delay status.Add (new SceneFunctionStatus () { key = FunctionAttributeKey.Delay, value = (commonNew.DelayTimeHeigh * 256 + commonNew.DelayTimeLow).ToString (), }); - //3.rgb + //4.rgb status.Add (new SceneFunctionStatus () { key = FunctionAttributeKey.RGB, value = commonNew.RStatus + "," + commonNew.GStatus + "," + commonNew.BStatus, @@ -369,7 +440,7 @@ var commonNew = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (jsonInfo); var mSceneFunction = new SceneFunction (); mSceneFunction.sid = function.sid; - //1.Brightness + //1.OnOff var status = new List<SceneFunctionStatus> (); status.Add (new SceneFunctionStatus () { key = FunctionAttributeKey.OnOff, @@ -595,8 +666,8 @@ } else { IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code); } - } catch { - + } catch(Exception EX) { + Utlis.WriteLine ("catch: " + EX.ToString()); } return res; } @@ -736,11 +807,11 @@ functionLists.AddRange (ConvertToSidListToIotCloud (tmpOid.oid, tmp)); - Utlis.WriteLine ("鏂扮殑妯″潡锛屾柊鐨勭殑OID锛�" + tmpOid.addresses + " deviceType:" + tmpOid.deviceType); + //Utlis.WriteLine ("鏂扮殑妯″潡锛屾柊鐨勭殑OID锛�" + tmpOid.addresses + " deviceType:" + tmpOid.deviceType); } else { //3.2瀛樺湪鍒欏彇涔嬪墠鐨刼id functionLists.AddRange (ConvertToSidListToIotCloud (deviceOid.oid, tmp)); - Utlis.WriteLine ("鐩稿悓鐨勬ā鍧楋紝鍙栦箣鍓嶇殑OID锛�" + deviceOid.addresses + " deviceType:" + deviceOid.deviceType); + //Utlis.WriteLine ("鐩稿悓鐨勬ā鍧楋紝鍙栦箣鍓嶇殑OID锛�" + deviceOid.addresses + " deviceType:" + deviceOid.deviceType); } } -- Gitblit v1.8.0