From 2313f465c76d58d93d7cea5e1c3dfe5361853006 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 06 一月 2021 17:55:20 +0800
Subject: [PATCH] 2021-1-6-1
---
HDL_ON/Entity/FunctionList.cs | 329 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 296 insertions(+), 33 deletions(-)
diff --git a/HDL_ON/Entity/FunctionList.cs b/HDL_ON/Entity/FunctionList.cs
index 8a38fa0..7adfaaf 100644
--- a/HDL_ON/Entity/FunctionList.cs
+++ b/HDL_ON/Entity/FunctionList.cs
@@ -2,8 +2,10 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
+using HDL_ON.Common;
using HDL_ON.DAL;
using HDL_ON.DAL.Server;
+using Shared;
namespace HDL_ON.Entity
{
@@ -90,10 +92,18 @@
/// </summary>
public List<Sensor> sensorsEnvironmentalScience = new List<Sensor>();
+ public List<Scene> scenes = new List<Scene>();
/// <summary>
/// 鍦烘櫙鍒楄〃
/// </summary>
- public List<Scene> scenes = new List<Scene>();
+ //public List<Scene> Scenes
+ //{
+ // get
+ // {
+ // List.scenes = List.scenes.OrderByDescending(o => o.createTime).ToList();
+ // return List.scenes;
+ // }
+ //}
/// <summary>
/// 鍔熻兘鍒楄〃
/// </summary>
@@ -206,7 +216,7 @@
}
try
{
- deviceFunctionList.OrderByDescending(o => o.usageCount).ToList();
+ deviceFunctionList = deviceFunctionList.OrderByDescending(o => o.controlCounter).ToList();
}
catch (Exception ex)
{
@@ -362,7 +372,7 @@
}
else
{
- Utlis.ShowTip(Shared.Language.StringByID(StringId.EditFunctionInfoFail) + "\r\nCode:" + pack.Code);
+ IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
}
return pack.Code;
}
@@ -381,28 +391,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
+ {
+ MainPage.Log($"deviceType:{localFunction.spk} local:{localFunction.modifyTime} server:{newFunction.modifyTime}");
+ i++;
+ if (localFunction.modifyTime != 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,15 +455,7 @@
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)
@@ -589,12 +599,21 @@
{
if (DriverLayer.Control.Ins.IsRemote)
{
- var functionIds = new List<string>();
+ var page = new List<string>();
+ int count = 0;
+
foreach (var function in GetDeviceFunctionList())
{
- functionIds.Add(function.deviceId);
+ page.Add(function.deviceId);
+ count++;
+ if (count > 9)
+ {
+ DriverLayer.Control.Ins.SendApiReadCommand(page);
+ page.Clear();
+ count = 0;
+ }
}
- DriverLayer.Control.Ins.SendApiReadCommand(functionIds);
+ DriverLayer.Control.Ins.SendApiReadCommand(page);
}
else
{
@@ -625,7 +644,251 @@
})
{ IsBackground = true }.Start();
}
+ #region 鍦烘櫙鐩稿叧
+ /// <summary>
+ /// 娣诲姞鍦烘櫙
+ /// </summary>
+ public string AddScene(Scene scene, out Scene 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.sid == scene.sid);
+ var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene));
+ FileUtlis.Files.WriteFileByBytes(scene.savePath, ssd);
+ result = tempScene;
+ }
+ else
+ {
+ result = tempScene;
+ }
+ return revPack.Code;
+ }
+ #endregion
+ #region 鏀惰棌鍔熻兘
+
+ /// <summary>
+ /// 鏀惰棌鍦烘櫙
+ /// </summary>
+ public string CollectScene(Scene scene)
+ {
+ var result = "";
+ if (scene.collect)
+ {
+ result = ApiUtlis.Ins.HttpRequest.CollectDevice(scene.userSceneId).Code;
+ }
+ else
+ {
+ result = ApiUtlis.Ins.HttpRequest.CancelCollectDevice(scene.userSceneId).Code;
+ }
+
+ //鎻愮ず閿欒
+ if (result != StateCode.SUCCESS)
+ {
+ IMessageCommon.Current.ShowErrorInfoAlter(result);
+ }
+
+ return result;
+ }
+
+ #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;
+ case FunctionAttributeKey.FadeTime:
+ text = Language.StringByID(StringId.FadeSpeed);
+ 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