From 4a83749337096aae6dd5ec4f44f16653fbc7268a Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期三, 10 三月 2021 16:19:52 +0800
Subject: [PATCH] 2021-03-10 1.合并
---
HDL_ON/Entity/FunctionList.cs | 475 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 455 insertions(+), 20 deletions(-)
diff --git a/HDL_ON/Entity/FunctionList.cs b/HDL_ON/Entity/FunctionList.cs
index eb8157c..b4abf79 100644
--- a/HDL_ON/Entity/FunctionList.cs
+++ b/HDL_ON/Entity/FunctionList.cs
@@ -1,56 +1,491 @@
锘縰sing System;
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
{
public class FunctionList
{
+ static FunctionList _FunctionList;
+ public static FunctionList List
+ {
+ get
+ {
+ if (_FunctionList == null)
+ {
+ _FunctionList = new FunctionList();
+ #region 鎭㈠鏁版嵁
+ var filePathList = FileUtlis.Files.ReadFiles();
+ foreach (var filePath in filePathList)
+ {
+ _FunctionList.IniFunctionList(filePath);
+ }
+ #endregion
+ }
+ return _FunctionList;
+ }
+ }
+ /// <summary>
+ /// 鍔熻兘鍒楄〃
+ /// </summary>
+ public List<Function> Functions = new List<Function>();
+
/// <summary>
/// 绌鸿皟鍒楄〃
/// </summary>
- public List<AC> aCs = new List<AC>();
+ /// <returns></returns>
+ public List<Function> GetAcList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.AcStandard || obj.spk == SPK.AcIr);
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public List<Function> GetList()
+ {
+ List<Function> list = new List<Function>();
+
+
+ return list;
+ }
+
/// <summary>
/// 鐏厜鍒楄〃
/// </summary>
- public List<Light> lights = new List<Light>();
+ public List<Function> GetLightList()
+ {
+ return Functions.FindAll((obj) =>
+ obj.spk == SPK.LightSwitch
+ || obj.spk == SPK.LightDimming
+ || obj.spk == SPK.LightRGB
+ || obj.spk == SPK.LightRGBW
+ || obj.spk == SPK.LightCCT);
+ }
/// <summary>
/// 绐楀笜鍒楄〃
/// </summary>
- public List<Curtain> curtains = new List<Curtain>();
+ public List<Function> GetCurtainList()
+ {
+ return Functions.FindAll((obj) =>
+ obj.spk == SPK.CurtainRoller
+ || obj.spk == SPK.CurtainShades
+ || obj.spk == SPK.CurtainSwitch
+ || obj.spk == SPK.CurtainTrietex
+ );
+ }
+
/// <summary>
/// 鍦扮儹鍒楄〃
/// </summary>
- public List<FloorHeating> floorHeatings = new List<FloorHeating>();
+ public List<Function> GetFloorHeatingList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.FloorHeatStandard);
+ }
+ #region 瀹剁數鍒楄〃 electricals
/// <summary>
- /// 鍦烘櫙鍒楄〃
+ /// 瀹剁數鍒楄〃
/// </summary>
+ public List<Function> GetElectricals()
+ {
+
+ return Functions.FindAll((obj) => obj.spk == SPK.ElectricFan || obj.spk == SPK.ElectricTuyaFan
+ || obj.spk == SPK.ElectricSocket
+ || obj.spk == SPK.ElectricTV
+ || obj.spk == SPK.ElectricTuyaAirCleaner
+ || obj.spk == SPK.ElectricTuyaWeepRobot
+ || obj.spk == SPK.ElectricTuyaWaterValve
+ || obj.spk == SPK.ClothesHanger);
+ }
+ /// <summary>
+ /// 椋庢墖鍒楄〃
+ /// </summary>
+ public List<Function> GetFanList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.ElectricFan || obj.spk == SPK.ElectricTuyaFan);
+ }
+ /// <summary>
+ /// 鐢佃鍒楄〃
+ /// </summary>
+ public List<Function> GetTVList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.ElectricTV);
+ }
+ /// <summary>
+ /// 瀹剁數鎻掑骇鍒楄〃
+ /// </summary>
+ public List<Function> GetElectricSocketList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.ElectricSocket);
+ }
+ /// <summary>
+ /// 绌烘皵鍑�鍖栧櫒鍒楄〃
+ /// </summary>
+ public List<Function> GetAirCleanerList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.ElectricTuyaAirCleaner);
+ }
+ /// <summary>
+ /// 鎵湴鏈哄櫒浜哄垪琛�
+ /// </summary>
+ public List<Function> GetWeepRobotList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.ElectricTuyaWeepRobot);
+ }
+ /// <summary>
+ /// 姘撮榾鍒楄〃
+ /// </summary>
+ public List<Function> GetWaterValveList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.ElectricTuyaWaterValve);
+ }
+ /// <summary>
+ /// 鍑夐湼鍒楄〃
+ /// </summary>
+ public List<Function> GetClothesHangerList ()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.ClothesHanger);
+ }
+ /// <summary>
+ /// 绾㈠瀹濆垪琛�
+ /// </summary>
+ public List<Function> GetIrModuleList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.IrModule);
+ }
+
+ #endregion
+ /// <summary>
+ /// 鐜浼犳劅鍣ㄥ垪琛�
+ /// </summary>
+ public List<Function> GetEnvirSensorsList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.SensorPm25
+ || obj.spk == SPK.SensorCO2
+ || obj.spk == SPK.SensorTVOC
+ || obj.spk == SPK.SensorTemperature
+ || obj.spk == SPK.SensorHumidity
+ );
+ }
+ /// <summary>
+ /// 瀹夐槻璁惧鍒楄〃
+ /// </summary>
+ public List<Function> GetArmSensorList()
+ {
+ return Functions.FindAll((obj) => obj.spk == SPK.SensorSmoke
+ || obj.spk == SPK.SensorWater
+ || obj.spk == SPK.SensorDoorWindow
+ || obj.spk == SPK.SensorPir
+ );
+ }
+
public List<Scene> scenes = new List<Scene>();
- [Newtonsoft.Json.JsonIgnore]
- public List<Function> functions = new List<Function>();
-
/// <summary>
- /// 鑾峰彇鎵�鏈夊姛鑳藉垪琛�
+ /// 鍔犺浇鍔熻兘鍒楄〃
/// </summary>
- public void GetAllFunction()
+ /// <param name="filePath"></param>
+ public void IniFunctionList(string filePath)
{
- functions.Clear();
- functions.AddRange(GetAllDeviceFunctionList());
- functions.AddRange(scenes);
+ // todo 澧炲姞璁惧锛屽鍔犲姛鑳借繘鍔熻兘鍒楄〃
+ if (filePath.StartsWith("FunctionData_"))
+ {
+ var functionDataBytes = FileUtlis.Files.ReadFile(filePath);
+ var functionDataString = System.Text.Encoding.UTF8.GetString(functionDataBytes);
+ var tempFunction = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(functionDataString);
+ if (tempFunction == null)
+ {
+ FileUtlis.Files.DeleteFile(filePath);
+ return;
+ }
+
+
+ Functions.Add(tempFunction);
+
+ }
+ if (filePath.StartsWith("SceneData_"))
+ {
+ var sceneDataBytes = FileUtlis.Files.ReadFile(filePath);
+ var sceneDataString = System.Text.Encoding.UTF8.GetString(sceneDataBytes);
+ var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene>(sceneDataString);
+ List.scenes.Add(tempScene);
+ }
}
/// <summary>
/// 鑾峰彇璁惧鍔熻兘鍒楄〃
/// </summary>
- public List<Function> GetAllDeviceFunctionList()
+ public List<Function> GetDeviceFunctionList(SPK.BrandType brandType = SPK.BrandType.All)
{
- var deviceFunctionList = new List<Function>();
- deviceFunctionList.AddRange(aCs);
- deviceFunctionList.AddRange(lights);
- deviceFunctionList.AddRange(curtains);
- deviceFunctionList.AddRange(floorHeatings);
- return deviceFunctionList;
+ List<Function> resultFunctions = new List<Function>();
+ if (brandType == SPK.BrandType.All)
+ {
+ }
+ else
+ {
+ switch (brandType)
+ {
+ case SPK.BrandType.Hdl:
+ foreach (var function in Functions)
+ {
+ if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(function.spk))
+ {
+ resultFunctions.Add(function);
+ }
+ }
+ break;
+
+ case SPK.BrandType.Tuya:
+ foreach (var function in Functions)
+ {
+ if (SPK.Get3tySpk(SPK.BrandType.Tuya).Contains(function.spk))
+ {
+ resultFunctions.Add(function);
+ }
+ }
+ break;
+ }
+ return resultFunctions;
+ }
+
+ return Functions;
}
+ /// <summary>
+ /// 娓呯┖璁惧鍔熻兘鍒楄〃
+ /// </summary>
+ public void Clear()
+ {
+ Functions = new List<Function>();
+ _FunctionList = null;
+ }
+
+ /// <summary>
+ /// 鍔熻兘缁戝畾鎴块棿
+ /// </summary>
+ public string FunctionsBindRooms(List<string> roomIds,List<string> deviceIds)
+ {
+ var pm = new HttpServerRequest();
+ var pack = pm.BindDeviceToRoom(deviceIds, roomIds);
+ if(pack.Code == StateCode.SUCCESS)
+ {
+
+ }
+ else
+ {
+ IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
+ }
+ return pack.Code;
+ }
+
+ /// <summary>
+ /// 鍒犻櫎鍦烘櫙
+ /// todo
+ /// </summary>
+ public void DeleteScene(Scene scene,bool upSevser)
+ {
+ if (upSevser)
+ {
+ var pm = new HttpServerRequest();
+ var packCode = pm.DeleteScene(scene.userSceneId);
+ if (packCode == StateCode.SUCCESS)
+ {
+ FileUtlis.Files.DeleteFile(scene.savePath);
+ List.scenes.Remove(scene);
+ }
+ else
+ {
+ IMessageCommon.Current.ShowErrorInfoAlter(packCode);
+ }
+ }
+ else
+ {
+ FileUtlis.Files.DeleteFile(scene.savePath);
+ List.scenes.Remove(scene);
+ }
+ }
+ /// <summary>
+ /// 鍒犻櫎鏈湴鍔熻兘鍙婃枃浠�
+ /// </summary>
+ public void DeleteFunction(Function delTemp)
+ {
+ Functions.Remove(Functions.Find((obj) => obj.deviceId == delTemp.deviceId));
+ FileUtlis.Files.DeleteFile(delTemp.savePath);
+ }
+
+ bool lockReadFunctionStatus = false;
+
+ /// <summary>
+ /// 璇诲彇绗笁鏂硅澶囩姸鎬�
+ /// </summary>
+ public void Read3tyFunctionStatus()
+ {
+ //璇诲彇娑傞甫璁惧鐘舵��
+ if (GetDeviceFunctionList(SPK.BrandType.Tuya).Count > 0)
+ {
+ var page = new List<string>();
+ int count = 0;
+ foreach (var function in GetDeviceFunctionList(SPK.BrandType.Tuya))
+ {
+ page.Add(function.deviceId);
+ count++;
+ if (count > 9)
+ {
+ DriverLayer.Control.Ins.ReadFunctionsInfo(page);
+ page.Clear();
+ count = 0;
+ }
+ }
+ DriverLayer.Control.Ins.ReadFunctionsInfo(page);
+ }
+
+ }
+
+ /// <summary>
+ /// 璇诲彇鍏ㄩ儴鍔熻兘鐨勭姸鎬�
+ /// </summary>
+ public void ReadAllFunctionStatus()
+ {
+ if (lockReadFunctionStatus)
+ {
+ MainPage.Log($"澶氭杩涘叆--杩斿洖");
+ return;
+ }
+ new Thread(() =>
+ {
+ if (lockReadFunctionStatus)
+ {
+ MainPage.Log($"澶氭杩涘叆--杩斿洖");
+ return;
+ }
+ MainPage.Log($"杩涘叆--璇诲彇");
+ lockReadFunctionStatus = true;
+ try
+ {
+ Read3tyFunctionStatus();
+
+ if(DriverLayer.Control.Ins.GatewayOnline_Local)
+ {
+ foreach (var function in GetDeviceFunctionList(SPK.BrandType.Hdl))
+ {
+ switch (function.Spk_Prefix)
+ {
+ case FunctionCategory.Music:
+ case FunctionCategory.DryContact:
+ continue;
+ }
+ DriverLayer.Control.Ins.SendReadCommand(function);
+ //switch (function.Spk_Prefix)
+ //{
+ // case FunctionCategory.Light:
+ // case FunctionCategory.Electric:
+ // case FunctionCategory.Curtain:
+ // case FunctionCategory.AC:
+ // case FunctionCategory.FloorHeat:
+ // case FunctionCategory.Sensor:
+ // DriverLayer.Control.Ins.SendReadCommand(function);
+ // break;
+ //}
+ }
+ }
+ else
+ {
+ var page = new List<string>();
+ int count = 0;
+
+ foreach (var function in GetDeviceFunctionList(SPK.BrandType.Hdl))
+ {
+ page.Add(function.deviceId);
+ count++;
+ if (count > 9)
+ {
+ DriverLayer.Control.Ins.SendApiReadCommand(page);
+ page.Clear();
+ count = 0;
+ }
+ }
+ DriverLayer.Control.Ins.SendApiReadCommand(page);
+ }
+ }
+ catch (Exception ex)
+ {
+ MainPage.Log($"Refresh Residence Function Status Error : {ex.Message}");
+ }
+ finally
+ {
+ lockReadFunctionStatus = false;
+ MainPage.Log($"缁撴潫--璇诲彇");
+ }
+
+
+ })
+ { 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
+
+
+
+ #endregion
}
+
}
--
Gitblit v1.8.0