From 271015c6e90c195103cc7f34eda87966acd74dcc Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期日, 13 十二月 2020 20:46:12 +0800
Subject: [PATCH] 2020121301

---
 HDL_ON/DAL/Server/HttpServerRequest.cs |  110 +++++++++++++++++++++++++++----------------------------
 1 files changed, 54 insertions(+), 56 deletions(-)

diff --git a/HDL_ON/DAL/Server/HttpServerRequest.cs b/HDL_ON/DAL/Server/HttpServerRequest.cs
index 15c157b..2a667fb 100644
--- a/HDL_ON/DAL/Server/HttpServerRequest.cs
+++ b/HDL_ON/DAL/Server/HttpServerRequest.cs
@@ -59,7 +59,7 @@
             d.Add("QueryType", queryType);
             d.Add("loopId", loopId);
             d.Add("NowMonth", nowMonth);
-            d.Add("MAC", DB_ResidenceData.residenceData.residenceGatewayMAC);
+            d.Add("MAC", DB_ResidenceData.Instance.residenceGatewayMAC);
             d.Add("LocalTimeZone", 8);
             var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(d);
             return RequestHttps("https://developer.hdlcontrol.com/api/GetSensorPushHistory", jsonString, true);
@@ -491,30 +491,28 @@
                         };
                         UserInfo.Current.regionList.Add(home);
                     }
-
-                    if (string.IsNullOrEmpty(UserInfo.Current.CurReginID))
+                    //浣忓畢琚垹闄�
+                    if (UserInfo.Current.regionList.Find((obj) => obj.RegionID == DB_ResidenceData.Instance.CurrentRegion.RegionID) == null)
                     {
-                        UserInfo.Current.CurReginID = UserInfo.Current.regionList[0].RegionID;
-                        //鎭㈠澶囦唤
-                        //HDLCommon.Current.RestoreHomeBackup(DB_ResidenceData.residenceData.CurReginID);
+                        Shared.Application.RunOnMainThread(() =>
+                        {
+                            DB_ResidenceData.Instance.CurrentRegion = UserInfo.Current.regionList[0];
+                            GetHomeGatewayList();
+                            DB_ResidenceData.Instance.SaveResidenceData();
+                            UserInfo.Current.SaveUserInfo();
+                            Action action = () =>
+                            {
+                                MainPage.GoUserPage();
+                            };
+                            new UI.PublicAssmebly().TipMsg(StringId.Tip, StringId.ResidenceDeletedSwitchToAnotherResidence, action);
+                        });
                     }
                     else
                     {
-                        var curRegion = UserInfo.Current.regionList.Find((obj) => obj.RegionID == UserInfo.Current.CurReginID);
-                        if(curRegion == null)
-                        {
-                            UserInfo.Current.CurReginID = UserInfo.Current.regionList[0].RegionID;
-                            //鎭㈠澶囦唤
-                            //HDLCommon.Current.RestoreHomeBackup(DB_ResidenceData.residenceData.CurReginID);
-                        }
+                        UserInfo.Current.SaveUserInfo();
+                        //鍒锋柊涓�娆′綇瀹呯綉鍏�
+                        GetHomeGatewayList();
                     }
-
-
-                    DB_ResidenceData.residenceData.SaveResidenceData();
-                    UserInfo.Current.SaveUserInfo();
-
-                    //鍒锋柊涓�娆′綇瀹呯綉鍏�
-                    GetHomeGatewayList();
                 }
             }
 
@@ -531,7 +529,7 @@
         {
             var requestObj = new AddOrUpdateHomeObj()
             {
-                homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID,
+                homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID,
             };
 
             if (editId == 0)
@@ -554,32 +552,32 @@
         {
             try
             {
-                if (string.IsNullOrEmpty(DB_ResidenceData.residenceData.residecenInfo.RegionID)) return;
-                var nowhomeId = DB_ResidenceData.residenceData.residecenInfo.RegionID;
+                if (string.IsNullOrEmpty(DB_ResidenceData.Instance.CurrentRegion.RegionID)) return;
+                var nowhomeId = DB_ResidenceData.Instance.CurrentRegion.RegionID;
                 var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = nowhomeId });
                 var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_GetGatewayList, requestJson);
                 if (revertObj.Code == StateCode.SUCCESS)
                 {
                     var mHomeGatewayRes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HomeGatewayInfo>>(revertObj.Data.ToString());
-                    if (nowhomeId == DB_ResidenceData.residenceData.residecenInfo.RegionID)
+                    if (nowhomeId == DB_ResidenceData.Instance.CurrentRegion.RegionID)
                     {
                         if (mHomeGatewayRes != null)
                         {
                             if (mHomeGatewayRes.Count > 0)
                             {
-                                DB_ResidenceData.residenceData.HomeGateway = mHomeGatewayRes[0];
+                                DB_ResidenceData.Instance.HomeGateway = mHomeGatewayRes[0];
                                 if(mHomeGatewayRes[0].gatewayStatus == "ON_LINE")
                                 {
                                     DriverLayer.Control.Ins.IsRemote = true;
                                     DriverLayer.Control.Ins.GatewayOnline = true;
                                 }
-                                DB_ResidenceData.residenceData.SaveResidenceData();
+                                DB_ResidenceData.Instance.SaveResidenceData();
                                 return;
                             }
                         }
                         //鍏朵綑鎯呭喌娓呯┖缃戝叧淇℃伅
-                        DB_ResidenceData.residenceData.HomeGateway = null;
-                        DB_ResidenceData.residenceData.SaveResidenceData();
+                        DB_ResidenceData.Instance.HomeGateway = null;
+                        DB_ResidenceData.Instance.SaveResidenceData();
                     }
                 }
                 else
@@ -599,7 +597,7 @@
         /// <returns></returns>
         public ResponsePackNew GetResidenceMemberAccount()
         {
-            var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID });
+            var requestJson = HttpUtil.GetSignRequestJson(new HomeIdObj() { homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID });
             return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_FindAll, requestJson);
         }
 
@@ -628,7 +626,7 @@
         {
             var requestJson = HttpUtil.GetSignRequestJson(new UpdateChildNickNameObj()
             {
-                homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID,
+                homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID,
                 childAccountId = childAccountId,
                 nickName = nickName,
             });
@@ -645,7 +643,7 @@
         {
             var requestJson = HttpUtil.GetSignRequestJson(new UpdateChildAllowCreateSceneObj()
             {
-                homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID,
+                homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID,
                 childAccountId = childAccountId,
                 isAllowCreateScene = isAllow,
             });
@@ -686,7 +684,7 @@
         {
             var requestJson = HttpUtil.GetSignRequestJson(new GetShareObj()
             {
-                homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID,
+                homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID,
                 childAccountId = childAccountId,
             });
 
@@ -825,7 +823,7 @@
         public ResponsePackNew BindResidenceMemberAccount(string subAccount, string nickName)
         {
             //娣诲姞瀛愯处鍙�
-            var requestObj = new ChildAddObj() { homeId = DB_ResidenceData.residenceData.residecenInfo.RegionID, account = subAccount, nickName = nickName };
+            var requestObj = new ChildAddObj() { homeId = DB_ResidenceData.Instance.CurrentRegion.RegionID, account = subAccount, nickName = nickName };
             var requestJson = HttpUtil.GetSignRequestJson(requestObj);
             return HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_Child_Add, requestJson);
 
@@ -859,7 +857,7 @@
                     attachClientId = attachClientId,
                     homeType = HomeTypeEnum.BUSPRO.ToString()
                 });
-                var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GetMqttRemoteInfo, requestJson, DB_ResidenceData.residenceData.residecenInfo.regionUrl);
+                var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GetMqttRemoteInfo, requestJson, DB_ResidenceData.Instance.CurrentRegion.regionUrl);
                 if (revertObj.Code == StateCode.SUCCESS)
                 {
                     return Newtonsoft.Json.JsonConvert.DeserializeObject<MqttInfo>(revertObj.Data.ToString());
@@ -1734,7 +1732,7 @@
         public ResponsePackNew GetDeviceList()
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             //d.Add("gatewayId", DB_ResidenceData.residenceData.HomeGateway.gatewayId);
             //d.Add("roomId", DB_ResidenceData.residenceData.residecenInfo.RegionID);//鍙帶鍙傛暟锛屽綋闇�瑕佸垎椤佃幏鍙栵紝鎬庝箞鐭ラ亾鍒嗛〉鎬绘暟
             //d.Add("searchType", DB_ResidenceData.residenceData.residecenInfo.RegionID);
@@ -1751,7 +1749,7 @@
         public ResponsePackNew GetDeviceInfoList(List<string> functionIds)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("deviceIds", functionIds);
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1764,7 +1762,7 @@
         public ResponsePackNew RefreshDeviceStatus(List<string> functionIds)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("deviceIds", functionIds);
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1778,8 +1776,8 @@
         public ResponsePackNew ControlDevice(List<ApiAlinkControlActionObj> actionObjs)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
-            d.Add("gatewayId", DB_ResidenceData.residenceData.HomeGateway.gatewayId);//DriverLayer.Control.Ins.GatewayId);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
+            d.Add("gatewayId", DB_ResidenceData.Instance.HomeGateway.gatewayId);//DriverLayer.Control.Ins.GatewayId);
             d.Add("actions", actionObjs);
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1793,7 +1791,7 @@
         public ResponsePackNew UpdataDevcieInfo(Function function)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("deviceId", function.deviceId);//DriverLayer.Control.Ins.GatewayId);
             d.Add("name", function.name);
             d.Add("collect", function.collect);
@@ -1808,7 +1806,7 @@
         public ResponsePackNew BindDeviceToRoom(List<string> deviceIds,List<string> roomIds)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("deviceIds", deviceIds);
             d.Add("roomIds", roomIds);
 
@@ -1821,7 +1819,7 @@
         public string UnbindDeviceToRoom(string deviceId, string roomId)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("deviceIds", new List<string>() { deviceId });
             d.Add("roomIds", new List<string>() { roomId });
 
@@ -1834,7 +1832,7 @@
         public string EditDeviceName(string deviceId, string deviceName)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("deviceId", deviceId);
             d.Add("name", deviceName);
 
@@ -1847,7 +1845,7 @@
         public ResponsePackNew CollectDevice(string deviceId)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("deviceIds",new List<string>() { deviceId });
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1859,7 +1857,7 @@
         public ResponsePackNew CancelCollectDevice(string deviceId)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("deviceIds", new List<string>() { deviceId });
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1878,7 +1876,7 @@
         public ResponsePackNew GetSceneList(string roomId = null)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             if (roomId != null)
             {
                 d.Add("roomId", roomId);
@@ -1907,7 +1905,7 @@
         public ResponsePackNew AddScene(Scene scene)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("scenes", new List<Scene>() { scene });
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1921,7 +1919,7 @@
         public ResponsePackNew EditScene(Scene scene)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("scenes", new List<Scene>() { scene });
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1934,7 +1932,7 @@
         public string DeleteScene(string userSceneId)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("userSceneIds", new List<string>() { userSceneId });
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1947,7 +1945,7 @@
         public string ExecuteScene(string userSceneId)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("userSceneIds", new List<string>() { userSceneId });
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1961,7 +1959,7 @@
         public string CollectScene(string userSceneId)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("userSceneIds", new List<string>() { userSceneId });
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1975,7 +1973,7 @@
         public string CancelCollectScene(string userSceneId)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("userSceneIds", new List<string>() { userSceneId });
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -1992,7 +1990,7 @@
         public ResponsePackNew GetRoomList(string GetType = "All")
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             if (GetType != "All")
             {
                 d.Add("roomType", GetType);
@@ -2010,7 +2008,7 @@
         public ResponsePackNew AddRoom(List<SpatialInfo> rooms)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("rooms", rooms);
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -2029,7 +2027,7 @@
         public ResponsePackNew UpdateRoom(List<SpatialInfo> rooms)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("rooms", rooms);
 
             var requestJson = HttpUtil.GetSignRequestJson(d);
@@ -2049,7 +2047,7 @@
         public ResponsePackNew DeleteRoom(List<string> roomIds)
         {
             Dictionary<string, object> d = new Dictionary<string, object>();
-            d.Add("homeId", DB_ResidenceData.residenceData.residecenInfo.RegionID);
+            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.RegionID);
             d.Add("ids", roomIds);
 
             var requestJson = HttpUtil.GetSignRequestJson(d);

--
Gitblit v1.8.0