From 5a5a2b696866f947b6025d26c3302e8ffef46435 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期一, 11 一月 2021 16:11:20 +0800
Subject: [PATCH] 2021-01-11 1.更新MQTT连接和本地搜索网关方法。2.子账号相关接口完善

---
 Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs |  122 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 111 insertions(+), 11 deletions(-)

diff --git a/Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs b/Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs
index 3d6bd2c..e354ea1 100644
--- a/Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs
+++ b/Crabtree/SmartHome/UI/SimpleControl/CommonPage.cs
@@ -4,10 +4,19 @@
 using System.Text;
 using System.Collections.Generic;
 using Shared.SimpleControl.Phone;
-using service.hdlcontrol.com_WebServiceAirQuality;
+//using service.hdlcontrol.com_WebServiceAirQuality;
 
 namespace Shared.SimpleControl
 {
+    public class AirQuality
+    {
+        public string city;
+        public string airQTemp;
+        public string airQHumidity;
+        public string airQAirPM25;
+        public string airQAirWeather;
+    }
+
     public static class CommonPage
     {
         public static AirQuality AirQuality;
@@ -26,7 +35,7 @@
                         //127.0.0.1
                         if (ip == "0.0.0.0") {
                             try {
-                                ip = System.Net.Dns.GetHostEntry ("homeautomation.havells.com").AddressList [0].ToString ();
+                                ip = System.Net.Dns.GetHostEntry ("smarth-api.havells.com").AddressList [0].ToString ();
                             } catch { }
                         }
                         return new System.Net.IPEndPoint (System.Net.IPAddress.Parse (ip), 9999);
@@ -348,12 +357,14 @@
                                     UserDeviceToLight.UpdataEnergy (usefullBytes [0], updateFlag, usefullBytes [2] * 256 + usefullBytes [3]);
                                     UserRoom.UpdataEnergy (usefullBytes [0], common.Type + "_" + updateFlag, usefullBytes [2] * 256 + usefullBytes [3]);
                                     break;
-                                } else if (usefullBytes [0] == 11) {
-                                    UserDeviceToSocket.UpdataEnergy (usefullBytes [0], updateFlag, usefullBytes [2] * 256 * 256 * 256 + usefullBytes [3] * 256 * 256 + usefullBytes [4] * 256 + usefullBytes [5]);
-                                    UserDeviceToLight.UpdataEnergy (usefullBytes [0], updateFlag, usefullBytes [2] * 256 * 256 * 256 + usefullBytes [3] * 256 * 256 + usefullBytes [4] * 256 + usefullBytes [5]);
-                                    UserRoom.UpdataEnergy (usefullBytes [0], common.Type + "_" + updateFlag, usefullBytes [2] * 256 * 256 * 256 + usefullBytes [3] * 256 * 256 + usefullBytes [4] * 256 + usefullBytes [5]);
-                                    break;
                                 }
+                                //2020-07-01 瀹㈡埛鎻愬嚭闅愯棌kwh
+                                //else if (usefullBytes [0] == 11) {
+                                //    UserDeviceToSocket.UpdataEnergy (usefullBytes [0], updateFlag, usefullBytes [2] * 256 * 256 * 256 + usefullBytes [3] * 256 * 256 + usefullBytes [4] * 256 + usefullBytes [5]);
+                                //    UserDeviceToLight.UpdataEnergy (usefullBytes [0], updateFlag, usefullBytes [2] * 256 * 256 * 256 + usefullBytes [3] * 256 * 256 + usefullBytes [4] * 256 + usefullBytes [5]);
+                                //    UserRoom.UpdataEnergy (usefullBytes [0], common.Type + "_" + updateFlag, usefullBytes [2] * 256 * 256 * 256 + usefullBytes [3] * 256 * 256 + usefullBytes [4] * 256 + usefullBytes [5]);
+                                //    break;
+                                //}
                             }
 
 
@@ -1241,7 +1252,7 @@
                             common.isMixBox = true;
                         } else {
                             Application.RunOnMainThread (() => {
-                                MainPage.Loading.Start ("Search for device:" + devcieTempName);
+                                //MainPage.Loading.Start ("Search for device:" + devcieTempName);
                                 ++searchTotal;
                                 GuideSettingGateway.InitSearchDeviceList (common);
                                 for (int k = 1; k <= common.LoopCount; k++) {
@@ -1274,6 +1285,14 @@
                         //} else if (deviceType1.ToString ().Contains ("Switch")) {
                         //    devcieLoopName = "Relay SW" + usefullBytes [2].ToString ();
                         //}
+
+                        //2020-07-03 濡傛灉鏄孩澶栨ā鍧楃被鍨嬶紝澶囨敞涓虹┖鐨勮瘽锛岄粯璁や负TV鍚嶅瓧
+                        if (deviceType1 == DeviceType.InfraredMode) {
+                            devcieLoopName = "TV " + usefullBytes [2].ToString ();
+                        } else if (deviceType1 == DeviceType.ACInfrared) {
+                            //2020-08-28 濡傛灉鏄孩澶栫┖璋冪被鍨嬶紝澶囨敞涓虹┖鐨勮瘽锛岄粯璁や负AC鍚嶅瓧
+                            devcieLoopName = "AC " + usefullBytes [2].ToString ();
+                        }
                         byte [] ddd = CommonPage.MyEncodingGB2312.GetBytes (devcieLoopName);
                         byte [] newddd = new byte [20];
                         Array.Copy (ddd, 0, newddd, 0, 20 < ddd.Length ? 20 : ddd.Length);
@@ -2112,6 +2131,85 @@
             return s;//
         }
 
+        //static void httpListener_EventHandler (System.Collections.Specialized.NameValueCollection nameValueCollection, System.IO.Stream outputStream, System.IO.Stream inputStream)
+        //{
+        //    //if (!isHttpListenerStart) {
+        //    //    return;
+        //    //}
+        //    try {
+        //        //System.Net.WebClient webClient = new System.Net.WebClient ();
+        //        //byte []bytes= webClient.DownloadData("http://ip:6001/GetAllFiles");
+        //        //               System.Text.Encoding.UTF8.GetString (bytes);
+        //        //List<string> list = new List<string> ();
+        //        //foreach(string s in list) { 
+        //        //    byte [] bytes = webClient.DownloadData ("http://ip:6001/Get"+s);
+        //        //    FileUtils.WriteFileByBytes (s, bytes);
+        //        //}
+
+        //        if (nameValueCollection ["Command"] != null && nameValueCollection ["Command"].StartsWith ("Get")) {
+        //            string tempFileName = nameValueCollection ["Command"].Replace ("Get", "");
+        //            if ("AllFiles" == tempFileName) {
+        //                byte [] bytes = System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (IO.FileUtils.ReadFiles ()));
+        //                outputStream.Write (bytes, 0, bytes.Length);
+        //                outputStream.Flush ();
+        //            } else {
+        //                byte [] bytes;
+        //                if (!IO.FileUtils.Exists (tempFileName)) {
+        //                    bytes = System.Text.Encoding.UTF8.GetBytes ("鏂囦欢鍚嶄笉瀛樺湪锛�");
+        //                    outputStream.Write (bytes, 0, bytes.Length);
+        //                    outputStream.Flush ();
+        //                    return;
+        //                }
+        //                System.IO.FileStream fs = new System.IO.FileStream (Application.RootPath + tempFileName, System.IO.FileMode.Open);
+        //                bytes = new byte [fs.Length];
+        //                fs.Read (bytes, 0, bytes.Length);
+        //                fs.Close ();
+        //                outputStream.Write (bytes, 0, bytes.Length);
+        //                outputStream.Flush ();
+        //            }
+        //        } else if (nameValueCollection ["Command"].StartsWith ("Upload")) {
+        //            string path = Application.RootPath + nameValueCollection ["Command"].Replace ("Upload", "");
+        //            string dePath = nameValueCollection ["Command"].Replace ("Upload", "");
+        //            if (dePath.StartsWith ("Room_")) {
+        //                new Room ().Add (dePath);
+        //            }
+        //            if (dePath.Split ('_').Length == 5) {
+        //                if (dePath.Split ('_') [1] == (typeof (OnePortBus).Name) || dePath.Split ('_') [1] == (typeof (OnePortWirelessFR).Name)) {
+        //                    UserConfig.Instance.RemoteModeFile = dePath;
+        //                    UserConfig.Instance.SaveUserConfig ();
+        //                }
+        //                if (dePath.Split ('_') [1] == (typeof (SecurityModul).Name)) {
+        //                    if (UserConfig.Instance.HideDeviceTypes.Contains ((R.MyInternationalizationString.Security))) {
+        //                        UserConfig.Instance.HideDeviceTypes.Remove (R.MyInternationalizationString.Security);
+        //                        UserConfig.Instance.SaveUserConfig ();
+        //                    }
+        //                }
+        //            }
+
+        //            if (dePath.Split ('_').Length == 2 && dePath.StartsWith ("GlobalScene")) {
+        //                var sceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
+        //                if (!sceneFileList.Contains (dePath)) {
+        //                    sceneFileList.Add (dePath);
+        //                    IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFileList)));
+        //                }
+        //            }
+        //            //Utlis.WriteLine ("鎺ユ敹"+path);
+        //            FileUtils.WriteFileByInputStream (path, inputStream);
+        //            Common common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (path)));
+        //            if (common.DeviceTextID == R.MyInternationalizationString.ElectricalControl) {
+        //                UserConfig.Instance.SocketList.Add (common.CommonLoopID);
+        //            }
+        //        } else {
+        //            byte [] bytes = System.Text.Encoding.UTF8.GetBytes ("璇锋眰鍛戒护鏃犳晥锛�");
+        //            outputStream.Write (bytes, 0, bytes.Length);
+        //            outputStream.Flush ();
+        //        }
+        //    } catch (Exception ex) {
+        //        Utlis.WriteLine ("httpListener_EventHandler" + ex.ToString ());
+        //    } 
+        //}
+
+
         static void httpListener_EventHandler (System.Collections.Specialized.NameValueCollection nameValueCollection, System.IO.Stream outputStream, System.IO.Stream inputStream)
         {
             //if (!isHttpListenerStart) {
@@ -2151,9 +2249,11 @@
                 } else if (nameValueCollection ["Command"].StartsWith ("Upload")) {
                     string path = Application.RootPath + nameValueCollection ["Command"].Replace ("Upload", "");
                     string dePath = nameValueCollection ["Command"].Replace ("Upload", "");
-                    if (dePath.StartsWith ("Room_")) {
+                    if (dePath.Contains ("Room_")) {
                         new Room ().Add (dePath);
                     }
+
+
                     if (dePath.Split ('_').Length == 5) {
                         if (dePath.Split ('_') [1] == (typeof (OnePortBus).Name) || dePath.Split ('_') [1] == (typeof (OnePortWirelessFR).Name)) {
                             UserConfig.Instance.RemoteModeFile = dePath;
@@ -2165,6 +2265,7 @@
                                 UserConfig.Instance.SaveUserConfig ();
                             }
                         }
+
                     }
 
                     if (dePath.Split ('_').Length == 2 && dePath.StartsWith ("GlobalScene")) {
@@ -2174,7 +2275,6 @@
                             IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFileList)));
                         }
                     }
-                    //Utlis.WriteLine ("鎺ユ敹"+path);
                     FileUtils.WriteFileByInputStream (path, inputStream);
                     Common common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (path)));
                     if (common.DeviceTextID == R.MyInternationalizationString.ElectricalControl) {
@@ -2187,7 +2287,7 @@
                 }
             } catch (Exception ex) {
                 Utlis.WriteLine ("httpListener_EventHandler" + ex.ToString ());
-            } 
+            }
         }
 
         /// <summary>

--
Gitblit v1.8.0