From f77a3add1e7ab266e473da9128bbe5758ba3a890 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期日, 20 十二月 2020 19:29:03 +0800 Subject: [PATCH] Merge branch 'NewFilePath' into CJL --- HDL_ON/Entity/Function/Scene.cs | 183 ++++++++++++++++++++++++++++++++++----------- 1 files changed, 138 insertions(+), 45 deletions(-) diff --git a/HDL_ON/Entity/Function/Scene.cs b/HDL_ON/Entity/Function/Scene.cs index 362a245..c6ad0eb 100644 --- a/HDL_ON/Entity/Function/Scene.cs +++ b/HDL_ON/Entity/Function/Scene.cs @@ -24,10 +24,18 @@ public class Scene { + public Scene() + { + sid = NewSid(); + if (!DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull()) + { + gatewayId = DB_ResidenceData.Instance.HomeGateway.gatewayId; + } + } /// <summary> /// 浜戠鍞竴ID /// </summary> - public string userSceneId = ""; + public string userSceneId = null; /// <summary> /// 鍦烘櫙sid /// </summary> @@ -55,37 +63,11 @@ /// <summary> /// 寤舵椂 /// </summary> - public int delay = 0; + public string delay = "0"; /// <summary> - /// 寤舵椂鏄剧ず鐨勬枃鏈� + /// 鍦烘櫙鐨勬渶濂戒竴娆℃墽琛屾椂闂� /// </summary> - [Newtonsoft.Json.JsonIgnore] - public string delayText - { - get - { - 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; - } - } + public string LastExecutionTime = ""; /// <summary> /// 鍦烘櫙鍒嗙粍 @@ -202,7 +184,7 @@ string roomNameList = ""; foreach (var roomId in roomIds) { - var findRoom = DB_ResidenceData.residenceData.Rooms.Find(obj => obj.uid == roomId); + var findRoom = SpatialInfo.CurrentSpatial.RoomList.Find(obj => obj.roomId == roomId); if (findRoom == null) { continue; @@ -215,7 +197,7 @@ } if (roomNameList == "" ) { - roomNameList = Shared.Language.StringByID(StringId.WholeHouseScene); + roomNameList = Shared.Language.StringByID(StringId.WholeZone); } return roomNameList; } @@ -231,6 +213,57 @@ return "SceneData_" + sid; } } + /// <summary> + /// 鍦烘櫙鎵ц\鍊掕鏃� + /// </summary> + /// <param name="btnShowDelay"></param> + public void SceneCountDown(Button btnShowDelay) + { + //鍦烘櫙姝e湪鍊掕鏃舵墽琛屼腑 + if (LastExecutionTime != "" && Convert.ToDouble(LastExecutionTime) + Convert.ToDouble(delay) > Convert.ToDouble(Utlis.GetTimestamp(false))) + { + int time = 0; + int.TryParse(Convert.ToInt32( + Convert.ToDouble(LastExecutionTime) + Convert.ToDouble(delay) - Convert.ToDouble(Utlis.GetTimestamp(false)) + ).ToString(), out time); + if (time > 0) + { + new System.Threading.Thread(() => + { + if (time > 0) + { + while (time > 0) + { + Application.RunOnMainThread(() => + { + if (time / 60 > 1) + { + btnShowDelay.Text = (time / 60).ToString() + "min"; + } + else + { + btnShowDelay.Text = (time--).ToString() + "s"; + } + }); + if (time / 60 > 1) + { + System.Threading.Thread.Sleep(time / 60 * 60000); + } + else + { + System.Threading.Thread.Sleep(1000); + } + } + Application.RunOnMainThread(() => + { + btnShowDelay.Text = ""; + }); + } + }) + { IsBackground = true, Priority = System.Threading.ThreadPriority.BelowNormal }.Start(); + } + } + } /// <summary> /// 淇濆瓨鍔熻兘鏁版嵁 @@ -241,10 +274,73 @@ { UploadScene(); } - var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); - FileUtils.WriteFileByBytes(savePath, ssd); - MainPage.Log($"Save Scene Data : {savePath}"); + else + { + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); + MainPage.Log($"Save Scene Data : {savePath}"); + } } + /// <summary> + /// 鏀惰棌鍦烘櫙 + /// </summary> + /// <returns></returns> + public string CollectScene() + { + var pm = new HttpServerRequest(); + if (this.collect) + { + var revPack = pm.CollectScene(this.userSceneId); + return revPack; + } + else + { + var revPack = pm.CancelCollectScene(this.userSceneId); + return revPack; + } + } + + /// <summary> + /// 缂栬緫鍦烘櫙 + /// </summary> + public string EditScene() + { + var pm = new HttpServerRequest(); + var revPack = pm.EditScene(this); + if (revPack.Code == StateCode.SUCCESS) + { + var scenes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString()); + var tempScene = scenes.Find((obj) => obj.sid == sid); + if (tempScene != null) + { + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene)); + Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); + } + } + return revPack.Code; + } + + /// <summary> + /// 淇敼鍦烘櫙 + /// </summary> + public string UpdateScene() + { + var pm = new HttpServerRequest(); + var revPack = pm.EditScene(this); + if (revPack.Code == StateCode.SUCCESS) + { + var scenes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString()); + var tempScene = scenes.Find((obj) => obj.sid == sid); + if (tempScene != null) + { + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene)); + Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); + } + } + return revPack.Code; + } + + /// <summary> /// 涓婁紶鏁版嵁鍒颁簯绔� @@ -259,7 +355,7 @@ if (revPack.Code == StateCode.SUCCESS) { var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); - FileUtils.WriteFileByBytes(savePath, ssd); + Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); } } else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime)) @@ -272,7 +368,7 @@ if (tempScene != null) { var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene)); - FileUtils.WriteFileByBytes(savePath, ssd); + Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); } } } @@ -305,10 +401,11 @@ /// 鏈湴瀵瑰簲鐨勫姛鑳� /// </summary> [Newtonsoft.Json.JsonIgnore] - public Function localFunction { + public Function localFunction + { get { - if(_localFunction == null) + if (_localFunction == null) { _localFunction = ConvertFunctionObject(); } @@ -322,14 +419,10 @@ /// <returns></returns> Function ConvertFunctionObject() { - var localFunction = DB_ResidenceData.functionList.GetAllDeviceFunctionList().Find((obj) => obj.sid == sid); - foreach (var s in status) - { - localFunction.attributes.Add(new FunctionAttributes() { key = s.key, curValue = s.value, value = new List<string>() { s.value } }); - } + var localFunction = FunctionList.List.GetDeviceFunctionList().Find((obj) => obj.sid == sid); return localFunction; } - + } /// <summary> -- Gitblit v1.8.0