From ea285ffe71284f5499e870f89c65b710d2d6a79c Mon Sep 17 00:00:00 2001
From: lss <lsc@hdlchina.com.cn>
Date: 星期一, 27 六月 2022 10:54:32 +0800
Subject: [PATCH] Merge branch 'wxr0114' of http://59.41.255.150:6688/r/~wxr/OnPro into wxr0114

---
 HDL_ON/DAL/DriverLayer/Control.cs |  177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 163 insertions(+), 14 deletions(-)

diff --git a/HDL_ON/DAL/DriverLayer/Control.cs b/HDL_ON/DAL/DriverLayer/Control.cs
index 17cc7b5..333d101 100644
--- a/HDL_ON/DAL/DriverLayer/Control.cs
+++ b/HDL_ON/DAL/DriverLayer/Control.cs
@@ -94,7 +94,7 @@
             }
             set
             {
-                if (_GatewayOnline_Local != value)
+                //if (_GatewayOnline_Local != value)
                 {
                     _GatewayOnline_Local = value;
                     if (value)
@@ -129,7 +129,7 @@
             }
             set
             {
-                if (_GatewayOnline_Cloud != value)
+                //if (_GatewayOnline_Cloud != value)
                 {
                     _GatewayOnline_Cloud = value;
                     if(GatewayOnline_Local)
@@ -280,7 +280,8 @@
                         }
                         if (DB_ResidenceData.Instance.GatewayType == 0)
                         {
-                            new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) });
+                            new Control_Udp().ControlBytesSend(Command.ReadGateway, 255, 255,
+                                new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) });
                         }
                         else if (DB_ResidenceData.Instance.GatewayType == 1)
                         {
@@ -360,10 +361,11 @@
         /// <param name="function"></param>
         /// <param name="useRemote">鏄惁鐩存帴浣跨敤杩滅▼鍙戦��</param>
         /// <returns></returns>
-        public void SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false,int resend = 3)
+        public bool SendWriteCommand(Function function, Dictionary<string, string> commandDictionary, bool useRemote = false,int resend = 3)
         {
             function.controlCounter++;
             function.refreshTime = DateTime.Now;
+
 
             //濡傛灉鏄帶鍒惰皟鍏夌殑寮�鏃讹紝浜害鍊间笉鑳戒负0
             if (commandDictionary.Count > 2)
@@ -404,7 +406,7 @@
                 upDataObj.objects.Add(asd);
                 revString = Newtonsoft.Json.JsonConvert.SerializeObject(upDataObj);
                 UpdataFunctionStatus(revString, null, true);
-                return;
+                return true;
             }
 
 
@@ -493,6 +495,8 @@
                 }
 
             }
+
+            return true;
         }
         /// <summary>
         /// 鍏ㄥ紑鍏ㄥ叧鍔熻兘
@@ -650,6 +654,79 @@
                 }
             }
         }
+
+        /// <summary>
+        /// 鍙戦�佽鍙栧懡浠�
+        /// 鑷姩鍒ゆ柇鏄惁涓篈鍗忚璁惧
+        /// </summary>
+        public void SendReadCommand(List<Function> functions, bool forceRemote = false)
+        {
+            List<string> sids = new List<string>();
+            foreach (Function function in functions)
+            {
+                sids.Add(function.sid);
+                function.refreshTime = DateTime.Now;
+            }
+            if (forceRemote)
+            {
+
+                var pm = new DAL.Server.HttpServerRequest();
+                var pack = pm.RefreshDeviceStatus(sids);
+            }
+            else
+            {
+                if (Ins.GatewayOnline_Local)
+                {
+
+                    if (DB_ResidenceData.Instance.GatewayType == 0)
+                    {
+                        try
+                        {
+                            var busClient = new Control_Udp();
+                            foreach (Function function in functions)
+                            {
+                                busClient.ReadBusData(function);
+                            }
+                            
+                        }
+                        catch (Exception ex)
+                        {
+                            MainPage.Log($"鍙戦�佹暟鎹紓甯�: {ex.Message}");
+                        }
+                    }
+                    else
+                    {
+                        var objects = new List<Dictionary<string, string>>();
+
+
+                        foreach (Function function in functions)
+                        {
+                            var readKey = new Dictionary<string, string>();
+                            readKey.Add("sid", function.sid);
+                            objects.Add(readKey);
+                        }
+
+
+                        var readDataObj = new AlinkReadFunctionStatusObj()
+                        {
+                            id = Ins.msg_id.ToString(),
+                            objects = objects,
+                            time_stamp = Utlis.GetTimestamp()
+                        };
+                        var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(readDataObj);
+                        var sendBytes = Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadStatus, functionControlDataJson);
+                        MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
+                        new Control_Udp().SendLocalHdlLinkData(sendBytes, readDataObj.id);
+                    }
+                }
+                else
+                {
+                    var pm = new DAL.Server.HttpServerRequest();
+                    var pack = pm.RefreshDeviceStatus(sids);
+                }
+            }
+        }
+
 
         /// <summary>
         /// 瀹夐槻鎺у埗
@@ -974,9 +1051,6 @@
                             }
                         }
 
-
-
-
                         var localFunction = allLocalFuntion.Find((obj) => obj.sid == updateTemp.sid);
                         if (localFunction == null)
                         {
@@ -1194,7 +1268,7 @@
                             case SPK.AvMusic:
                             case SPK.MusicStandard:
                                 //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp);
-                                Console.WriteLine("闊充箰鎾斁鍣ㄦ樉绀虹姸鎬�======="+ revString);
+                                //Console.WriteLine("闊充箰鎾斁鍣ㄦ樉绀虹姸鎬�======="+ revString);
                                 //wjc
                                 break;
                         }
@@ -1232,13 +1306,88 @@
             }
             else
             {
-                Dictionary<string, object> d = new Dictionary<string, object>();
-                d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
-                d.Add("deviceId", doorlock.deviceId);
-                var requestJson = HttpUtil.GetSignRequestJson(d);
-                HttpUtil.RequestHttpsPost("/home-wisdom/app/device/door/remoteOpen", requestJson);
+                ConfirmUnlocking(doorlock.deviceId, extStr);
             }
         }
+        /// <summary>
+        /// 纭寮�閿�
+        /// </summary>
+        /// <param name="functionId"></param>
+        /// <param name="pwd"></param>
+        public void ConfirmUnlocking(string functionId,string pwd)
+        {
+            Loading loading = new Loading();
+            MainPage.BaseView.AddChidren(loading);
+            loading.BackgroundColor = 0x88000000;
+            loading.LodingBackgroundColor = UI.CSS.CSS_Color.BackgroundColor;
+            loading.Start(Language.StringByID(StringId.PleaseWait));
+            new System.Threading.Thread(() =>
+            {
+                try
+                {
+                    Dictionary<string, object> d = new Dictionary<string, object>();
+                    d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+                    d.Add("deviceId", functionId);
+                    d.Add("pwd", pwd);
+                    var requestJson = HttpUtil.GetSignRequestJson(d);
+                    var pack = HttpUtil.RequestHttpsPost("/home-wisdom/app/device/door/pwdConfirm", requestJson);
+                    if (pack.Code == StateCode.SUCCESS)
+                    {
+                        Newtonsoft.Json.Linq.JObject pairs = Newtonsoft.Json.Linq.JObject.Parse(pack.Data.ToString());
+                        var scrip = pairs.GetValue("scrip");
+
+                        d = new Dictionary<string, object>();
+                        d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
+                        d.Add("deviceId", functionId);
+                        d.Add("scrip", scrip);
+                        requestJson = HttpUtil.GetSignRequestJson(d);
+                        pack = HttpUtil.RequestHttpsPost("/home-wisdom/app/device/door/remoteOpen", requestJson);
+                        //if(pack.Code == StateCode.SUCCESS)
+                        //{
+                        //    return true;
+                        //}
+                        //else
+                        //{
+                        //    return false;
+                        //}
+                        if (pack.Code != StateCode.SUCCESS) {
+                            Application.RunOnMainThread(() => {
+                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip), pack.message);
+                                UserInfo.Current.doorPasswordString = "";//
+                                UserInfo.Current.LastTimeOpenDoor = DateTime.MinValue;
+                            });
+                        }
+                    }
+                    if (pack.Code != StateCode.SUCCESS)
+                    {
+                        Application.RunOnMainThread(() => {
+                            if(string.IsNullOrEmpty(pack.message))
+                            {
+                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip),
+                                    Language.StringByID(StringId.OperationFailed));
+                            }
+                            else
+                            {
+                                new PublicAssmebly().TipMsg(Language.StringByID(StringId.Tip), pack.message);
+                            }
+                        });
+                    }
+                }
+                catch (Exception ex)
+                {
+
+                }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        loading.Hide();
+                        loading.RemoveFromParent();
+                    });
+                }
+            })
+            { IsBackground = true }.Start();
+        }
         //瀵嗙爜鍐荤粨
         //瀵嗙爜楠岃瘉
 

--
Gitblit v1.8.0