From 365eadb33ee86b05ac74d408025d102a758c2efd Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 10 一月 2020 15:27:17 +0800
Subject: [PATCH] 2020-01-10 2020-01-10 1.修改切换本地和远程问题。 2.修改判断住宅网关方案。 3.其它优化修改。

---
 Crabtree/SmartHome/HDL/Operation/UserConfig.cs |  112 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 97 insertions(+), 15 deletions(-)

diff --git a/Crabtree/SmartHome/HDL/Operation/UserConfig.cs b/Crabtree/SmartHome/HDL/Operation/UserConfig.cs
index 8a4145b..ac01c14 100644
--- a/Crabtree/SmartHome/HDL/Operation/UserConfig.cs
+++ b/Crabtree/SmartHome/HDL/Operation/UserConfig.cs
@@ -149,33 +149,115 @@
 
         public List<RegionInfoRes> HomeLists = new List<RegionInfoRes> ();
 
-        public RegionInfoRes CurrentRegion = new RegionInfoRes ();
+        RegionInfoRes currentRegion = new RegionInfoRes ();
+        public RegionInfoRes CurrentRegion {
+            set {
+                currentRegion = value;
+                CheckIfNeedGetMasterAccountToken ();
+            }
+            get {
+                return currentRegion;
+            }
+
+        }
 
         public bool CheckHomeGateways ()
         {
-            if (CurrentRegion.HomeGateways != null && CurrentRegion.HomeGateways.Count > 0) {
+            if (CurrentRegion != null && CurrentRegion.HomeGateways != null && CurrentRegion.HomeGateways.Count > 0) {
                 return true;
             } else {
                 return false;
             }
         }
 
-        public List<GatewayRes> GatewayList = new List<GatewayRes> ();
-
-        public List<string> GatewayMACList {
-            get {
-                List<string> macList = new List<string> ();
-                foreach (var mac in GatewayList) {
-                    macList.Add (mac.GatewayUniqueId);
-                }
-                return macList;
+        public bool CheckHomeGatewaysNotEmpty ()
+        {
+            if (CheckHomeGateways () && !string.IsNullOrEmpty (currentRegion.HomeGateways [0].GatewayUniqueId)) {
+                return true;
+            } else {
+                return false;
             }
         }
-        public string GatewayMAC = "";
+
+        //public List<GatewayRes> GatewayList = new List<GatewayRes> ();
+
+        //public List<string> GatewayMACList {
+        //    get {
+        //        List<string> macList = new List<string> ();
+        //        foreach (var mac in GatewayList) {
+        //            macList.Add (mac.GatewayUniqueId);
+        //        }
+        //        return macList;
+        //    }
+        //}
+        //public string GatewayMAC = "";
+
+        public string GatewayMAC {
+            get {
+                if (CheckHomeGatewaysNotEmpty ()) {
+                    return currentRegion.HomeGateways [0].GatewayUniqueId;
+                } else {
+                    return "";
+                }
+            }
+            set {
+                if (CheckHomeGateways ()) {
+                    currentRegion.HomeGateways [0].GatewayUniqueId = value;
+                } else {
+                    if (currentRegion != null && currentRegion.HomeGateways == null) {
+                        var mHomeGateways = new HomeGateways () { GatewayUniqueId = value };
+                        List<HomeGateways> HomeGateways = new List<HomeGateways> ();
+                        HomeGateways.Add (mHomeGateways);
+                        currentRegion.HomeGateways = HomeGateways;
+                    }
+                }
+            }
+
+        }
+        
 
         public List<string> RometoUserInfoKeys = new List<string> ();
 
-        //public static List<string> LocalFiles = IO.FileUtils.ReadFiles ();
+        public string MasterAccountToken = "";
+        public string MasterAccountRequestBaseUrl = "";
 
-    }
-}
\ No newline at end of file
+        //public static List<string> LocalFiles = IO.FileUtils.ReadFiles ();
+        /// <summary>
+        /// 鑾峰彇鎺у埗鍒嗕韩椤圭洰(浣忓畢)璇锋眰淇℃伅
+        /// </summary>
+        /// <param name="mMainAccountId"></param>
+        /// <param name="mSharedHid"></param>
+        public void CheckIfNeedGetMasterAccountToken ()
+        {
+            //2020-01-08 鍒ゆ柇鏄惁鍒嗕韩杩囨潵鐨勪綇瀹�
+            if (CurrentRegion != null && CurrentRegion.IsOthreShare) {
+                //MainPage.IsAdministrator = UserConfig.Instance.CurrentRegion.IsOthreShare;
+                //璇锋眰涓昏处鍙穞oken
+                System.Threading.Tasks.Task.Run (() => {
+                    try {
+                        //var mMainAccountId = UserConfig.Instance.CurrentRegion.MainUserDistributedMark;
+                        //var mSharedHid = UserConfig.Instance.CurrentRegion.Id;
+                        var requestObj = new GetSharedHomeApiControlObj () {
+                            LoginAccessToken = MainPage.LoginUser.LoginTokenString,
+                            MainAccountId = UserConfig.Instance.CurrentRegion.MainUserDistributedMark,
+                            SharedHid = UserConfig.Instance.CurrentRegion.Id,
+
+                        };
+                        var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
+                        var revertObj = MainPage.RequestHttps (API.GetSharedHomeApiControl, requestJson);
+                        if (revertObj.StateCode.ToUpper () == "SUCCESS") {
+                            var responseDataObj = Newtonsoft.Json.JsonConvert.DeserializeObject<MemberAdministratorResult> (revertObj.ResponseData.ToString ());
+                            if (responseDataObj != null) {
+                                MasterAccountToken = responseDataObj.RequestToken;
+                                MasterAccountRequestBaseUrl = responseDataObj.RequestBaseUrl;
+                            }
+                        }
+                    } catch {
+
+                    }
+                });
+            }
+        }
+
+        }
+    }
\ No newline at end of file

--
Gitblit v1.8.0