From d53e6af2c5f17838fa79659614b15a2a1f383399 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期五, 31 三月 2023 10:04:58 +0800
Subject: [PATCH] 1

---
 Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs |  125 ++++++++++++++++++++++++++++++++++-------
 1 files changed, 104 insertions(+), 21 deletions(-)

diff --git a/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs b/Crabtree/SmartHome/HDL/Common/HDLLinkUtlis.cs
index 5147063..4beb6ca 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
 {
@@ -116,6 +117,82 @@
         }
         #endregion
 
+        /// <summary>
+        /// 涓�閿皢鏈湴鍥炶矾璁惧鍜屽満鏅暟鎹浆鎹�
+        /// 鐒跺悗涓婁紶oid銆乻id銆佷互鍙婂満鏅垪琛�
+        /// </summary>
+        /// <returns></returns>
+        public void OneclickUpload (bool isMigrate = false)
+        {
+            if (isMigrate) {
+                var res = false;
+                res = UploadOidAndSidList ();
+                if (res) {
+                    res = GetFunctionList ();
+                    if (res) {
+                        res = UploadSecneList ();
+                    }
+                }
+                return;
+            }
+            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>
         /// 涓婁紶鍦烘櫙鍒楄〃
@@ -144,7 +221,6 @@
             }
             return res;
         }
-
 
         /// <summary>
         /// 鑾峰彇鎵�鏈夊満鏅垪琛�
@@ -220,25 +296,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鏁版嵁鏍煎紡
@@ -588,6 +664,13 @@
                 IotCloud currentProject = new IotCloud ();
                 var list = GetAllDeviceList ();
                 ConvertOidListToIotStruct (UserConfig.Instance.CurrentRegion.Id, UserConfig.Instance.HomeGateway.gatewayId, list, ref currentProject);
+                //2022-06-21 13:10:07 mac涓嶈兘涓虹┖锛屽惁鍒欎簯绔湁闂
+                foreach (var bean in currentProject.modules.devices) {
+                    if (string.IsNullOrEmpty (bean.mac)) {
+                        bean.mac = bean.oid;
+                    }
+                }
+
                 Utlis.WriteLine ("list: " + list.Count + "currentProject : " + currentProject.functions.devices.Count);
 
                 var revertObj = HttpServerRequest.Current.UploadDeviceOidList (currentProject.modules);
@@ -601,8 +684,8 @@
                 } else {
                     IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
                 }
-            } catch {
-
+            } catch(Exception EX) {
+                Utlis.WriteLine ("catch: " + EX.ToString());
             }
             return res;
         }

--
Gitblit v1.8.0