From bb6ad792b598927a5459a5fb6f6c27fb1aa9e94e Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期四, 17 十二月 2020 14:06:36 +0800
Subject: [PATCH] 20201217-1

---
 HDL_ON/Entity/FunctionList.cs |  268 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 241 insertions(+), 27 deletions(-)

diff --git a/HDL_ON/Entity/FunctionList.cs b/HDL_ON/Entity/FunctionList.cs
index 0dd75e6..0be3c7f 100644
--- a/HDL_ON/Entity/FunctionList.cs
+++ b/HDL_ON/Entity/FunctionList.cs
@@ -4,6 +4,7 @@
 using System.Threading;
 using HDL_ON.DAL;
 using HDL_ON.DAL.Server;
+using Shared;
 
 namespace HDL_ON.Entity
 {
@@ -381,28 +382,36 @@
                     var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(pack.Data.ToString());
                     if (deviceList != null)
                     {
-                        for (int i =0;i < List.GetDeviceFunctionList().Count;)
+                        if (List.GetDeviceFunctionList().Count > 0)
                         {
-                            var localFunction = List.GetDeviceFunctionList()[i];
-                            var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId);
-                            if (newFunction == null)//濡傛灉浜戠鏈�鏂版暟鎹病鏈夎鏉℃暟鎹紝鍒欐湰鍦伴渶瑕佸垹鎺夎鏁版嵁璁板綍
+                            for (int i = 0; i < List.GetDeviceFunctionList().Count;)
                             {
-                                List.DeleteFunction(localFunction);
-                            }
-                            else
-                            {
-                                i++;
-                                if (localFunction.modifyTime != newFunction.modifyTime)
+                                var localFunction = List.GetDeviceFunctionList()[i];
+                                if (localFunction.functionCategory == FunctionCategory.Music)
                                 {
-                                    MainPage.Log($"local:{localFunction.modifyTime}\r\n server:{newFunction.modifyTime}");
-                                    localFunction.name = newFunction.name;
-                                    localFunction.collect = newFunction.collect;
-                                    localFunction.modifyTime = newFunction.modifyTime;
-                                    localFunction.roomIds = newFunction.roomIds;
-                                    localFunction.bus_Data = newFunction.bus_Data;
-                                    localFunction.SaveFunctionData(false);
+                                    i++;
+                                    continue;
                                 }
-                                deviceList.list.Remove(newFunction);//鎿嶄綔瀹岀殑鏁版嵁娓呯悊鎺夛紝鍓╀笅鐨勫氨鏄柊澧炵殑鍔熻兘
+                                var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId);
+                                if (newFunction == null)//濡傛灉浜戠鏈�鏂版暟鎹病鏈夎鏉℃暟鎹紝鍒欐湰鍦伴渶瑕佸垹鎺夎鏁版嵁璁板綍
+                                {
+                                    List.DeleteFunction(localFunction);
+                                }
+                                else
+                                {
+                                    i++;
+                                    if (localFunction.modifyTime != newFunction.modifyTime)
+                                    {
+                                        MainPage.Log($"local:{localFunction.modifyTime}\r\n server:{newFunction.modifyTime}");
+                                        localFunction.name = newFunction.name;
+                                        localFunction.collect = newFunction.collect;
+                                        localFunction.modifyTime = newFunction.modifyTime;
+                                        localFunction.roomIds = newFunction.roomIds;
+                                        localFunction.bus = newFunction.bus;
+                                        localFunction.SaveFunctionData(false);
+                                    }
+                                    deviceList.list.Remove(newFunction);//鎿嶄綔瀹岀殑鏁版嵁娓呯悊鎺夛紝鍓╀笅鐨勫氨鏄柊澧炵殑鍔熻兘
+                                }
                             }
                         }
                         //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳�
@@ -437,17 +446,14 @@
                     var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString());
                     if (sceneList != null)
                     {
-                        ////灏嗕笅杞藉埌鍒版暟鎹叏閮ㄤ繚瀛�
-                        //new Thread(() => {
-                        //    foreach (var temp in sceneList)
-                        //    {
-                        //        temp.SaveSceneData();
-                        //    }
-                        //})
-                        //{ IsBackground = true }.Start();
-                        for(int i=0;i<List.scenes.Count;)
+                        for (int i=0;i<List.scenes.Count;)
                         {
                             var localScene = List.scenes[i];
+                            if (localScene == null)
+                            {
+                                List.scenes.Remove(localScene);
+                                continue;
+                            }
                             var newScene = sceneList.Find((obj) => obj.userSceneId == localScene.userSceneId);
                             if (newScene == null)//濡傛灉浜戠鏈�鏂版暟鎹病鏈夎鏉℃暟鎹紝鍒欐湰鍦伴渶瑕佸垹鎺夎鏁版嵁璁板綍
                             {
@@ -620,7 +626,215 @@
             })
             { IsBackground = true }.Start();
         }
+        #region 鍦烘櫙鐩稿叧
+        /// <summary>
+        /// 娣诲姞鍦烘櫙
+        /// </summary>
+        public Scene AddScene(Scene scene,out string result)
+        {
+            Scene tempScene = null;
+            var pm = new HttpServerRequest();
+            var revPack = pm.AddScene(scene);
+            if (revPack.Code == StateCode.SUCCESS)
+            {
+                var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString());
+                tempScene = sceneList.Find((obj) => obj.userSceneId == scene.userSceneId);
+                var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene));
+                Common.FileUtlis.Files.WriteFileByBytes(scene.savePath, ssd);
+            }
+            result = revPack.Code;
+            return tempScene;
+        }
+        #endregion
 
+        #region 鍔熻兘鏂囨湰鐩稿叧
+        /// <summary>
+        /// 灞炴�у悕绉版樉绀烘枃鏈�
+        /// 涓嫳鏂囨樉绀�
+        /// </summary>
+        public string GetNameText(string key)
+        {
+            string text = "";
+            switch (key)
+            {
+                case FunctionAttributeKey.OnOff:
+                    text = Language.StringByID(StringId.OnOff);
+                    break;
+                case FunctionAttributeKey.Brightness:
+                    text = Language.StringByID(StringId.Brightness);
+                    break;
+                case FunctionAttributeKey.RGB:
+                    text = Language.StringByID(StringId.ColorValue);
+                    break;
+                case FunctionAttributeKey.Mode:
+                    text = Language.StringByID(StringId.Mode);
+                    break;
+                case FunctionAttributeKey.FanSpeed:
+                    text = Language.StringByID(StringId.FanSpeed);
+                    break;
+                case FunctionAttributeKey.SetTemp:
+                    text = Language.StringByID(StringId.Temp);
+                    break;
+                case FunctionAttributeKey.IndoorTemp:
+                    text = Language.StringByID(StringId.IndoorTemp);
+                    break;
+                case FunctionAttributeKey.Delay:
+                    text = Language.StringByID(StringId.Delay);
+                    break;
+                case FunctionAttributeKey.CCT:
+                    text = "CCT";
+                    break;
+                case FunctionAttributeKey.Percent:
+                    text = Language.StringByID(StringId.PercentAdjustment);
+                    break;
+            }
+            return text;
+        }
+
+        /// <summary>
+        /// 灞炴�у�煎崟浣�
+        /// </summary>
+        public string GetUintString(string key)
+        {
+            var us = "";
+            switch (key)
+            {
+                case FunctionAttributeKey.SetTemp:
+                case FunctionAttributeKey.IndoorTemp:
+                    us = "掳C";
+                    break;
+                case FunctionAttributeKey.Percent:
+                case FunctionAttributeKey.Brightness:
+                    us = "%";
+                    break;
+            }
+            return us;
+        }
+
+        /// <summary>
+        /// 鑾峰彇鎸囧畾灞炴�х殑鏄剧ず鏂囨湰
+        /// 涓嫳鏂囨樉绀�
+        /// </summary>
+        public string GetValueText(string key, string value)
+        {
+            string text = "";
+            switch (key)
+            {
+                case FunctionAttributeKey.OnOff:
+                    text = value == "on" ? Language.StringByID(StringId.On) : Language.StringByID(StringId.OFF);
+                    break;
+                case FunctionAttributeKey.SetTemp:
+                case FunctionAttributeKey.IndoorTemp:
+                case FunctionAttributeKey.Brightness:
+                case FunctionAttributeKey.Percent:
+                    if (value == "")
+                    {
+                        value = "0";
+                    }
+                    text = value;
+                    break;
+                case FunctionAttributeKey.Mode:
+                    switch (value)
+                    {
+                        //----绌鸿皟
+                        case "auto":
+                            text = Language.StringByID(StringId.Auto);
+                            break;
+                        case "cool":
+                            text = Language.StringByID(StringId.Cool);
+                            break;
+                        case "heat":
+                            text = Language.StringByID(StringId.Heat);
+                            break;
+                        case "dry":
+                            text = Language.StringByID(StringId.Dry);
+                            break;
+                        case "fan":
+                            text = Language.StringByID(StringId.AirSupply);
+                            break;
+                        //-----鍦扮儹
+                        case "day":
+                            text = Language.StringByID(StringId.Day);
+                            break;
+                        case "night":
+                            text = Language.StringByID(StringId.Night);
+                            break;
+                        case "away":
+                            text = Language.StringByID(StringId.Away);
+                            break;
+                        case "normal":
+                            text = Language.StringByID(StringId.Normal);
+                            break;
+                        case "timer":
+                            text = Language.StringByID(StringId.Timer);
+                            break;
+                    }
+                    break;
+                case FunctionAttributeKey.FanSpeed:
+                    switch (value)
+                    {
+                        case "high":
+                            text = Language.StringByID(StringId.HighWindSpeed);
+                            break;
+                        case "medium":
+                            text = Language.StringByID(StringId.MiddleWindSpeed);
+                            break;
+                        case "low":
+                            text = Language.StringByID(StringId.LowWindSpeed);
+                            break;
+                        case "auto":
+                            text = Language.StringByID(StringId.Auto);
+                            break;
+                        default:
+                            text = "low";
+                            break;
+                    }
+                    break;
+                case "high":
+                    text = Language.StringByID(StringId.HighWindSpeed);
+                    break;
+                case "medium":
+                    text = Language.StringByID(StringId.MiddleWindSpeed);
+                    break;
+                case "low":
+                    text = Language.StringByID(StringId.LowWindSpeed);
+                    break;
+                case "auto":
+                    text = Language.StringByID(StringId.Auto);
+                    break;
+            }
+            return text;
+        }
+
+
+        /// <summary>
+        /// 寤舵椂鏄剧ず鐨勬枃鏈�
+        /// </summary>
+        public string GetDelayText(string delay)
+        {
+            string text = "";
+            switch (delay)
+            {
+                case "0":
+                    text = Language.StringByID(StringId.NoDelay);
+                    break;
+                case "30":
+                    text = "30s";
+                    break;
+                case "60":
+                    text = "1min";
+                    break;
+                case "120":
+                    text = "2min";
+                    break;
+                case "300":
+                    text = "5min";
+                    break;
+            }
+            return text;
+        }
+
+        #endregion
     }
 
 }

--
Gitblit v1.8.0