From d4811b7d34b45ff6b21b97f11da128b5572ec526 Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期三, 03 三月 2021 16:03:03 +0800 Subject: [PATCH] 20210303-1 --- HDL_ON/Entity/Function/Scene.cs | 270 +++++++++++++++++++++++++++++++++++------------------ 1 files changed, 178 insertions(+), 92 deletions(-) diff --git a/HDL_ON/Entity/Function/Scene.cs b/HDL_ON/Entity/Function/Scene.cs index c8d208e..c974e1e 100644 --- a/HDL_ON/Entity/Function/Scene.cs +++ b/HDL_ON/Entity/Function/Scene.cs @@ -1,5 +1,6 @@ 锘縰sing System; using System.Collections.Generic; +using HDL_ON.Common; using HDL_ON.DAL.Server; using Shared; @@ -24,10 +25,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> @@ -48,40 +57,18 @@ /// 鎵�灞炴埧闂村垪琛� /// </summary> public List<string> roomIds = new List<string>(); + ///// <summary> + ///// 鎵�灞炴埧闂村垪琛� + ///// </summary> + //public List<string> uids = new List<string>(); /// <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> /// 鍦烘櫙鍒嗙粍 @@ -134,21 +121,18 @@ public List<ScenePushConfig> pushConfigs = new List<ScenePushConfig>(); /// <summary> - /// 鐢熸垚鍦烘櫙sid + /// 鐢熸垚閫昏緫sid鏂规硶 /// </summary> - public void NewSid() + public string NewSid() { - string sSceneid = ""; + string sceneId = ""; try { string sOidBeginsWith = "000101";//鍘傚晢 + 閫氳鏂瑰紡 DateTime dt = DateTime.Now; - - DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1)); long m = (long)((dt - startTime).TotalMilliseconds / 10); string sTimeSpan = "00000000"; - byte[] arry = new byte[4]; arry[0] = (byte)(m & 0xFF); @@ -167,25 +151,29 @@ sTimeSpan = "00000000"; } - sSceneid = sOidBeginsWith + sTimeSpan; + sceneId = sOidBeginsWith + sTimeSpan; - sSceneid += "0A"; - sSceneid += "0A01"; - //0A01 鐗╂ā鍨嬩负鍦烘櫙锛� 0001 琛ㄧず 1 鍙峰満鏅姛鑳� - int iTopSceneId = 1; + sceneId += "0A"; + sceneId += "0A01"; + int maxId = 1; - Random random = new Random(); - iTopSceneId = random.Next(0, 255); - iTopSceneId += random.Next(0, 255); - sSceneid += iTopSceneId.ToString("X4");//鍦烘櫙鍙� 涓や釜byte - sSceneid += "1100"; - sid = sSceneid; + for (int i = 0; i < FunctionList.List.scenes.Count; i++) + { + string s = FunctionList.List.scenes[i].sid.Substring(20, 4); + int iThisSceneId = Convert.ToInt16(s, 16); + if (iThisSceneId > maxId) + maxId = iThisSceneId; + } + + sceneId += (maxId + 1).ToString("X4"); + sceneId += "0000"; } catch { - sid = sSceneid; + return sceneId; } + return sceneId; } /// <summary> @@ -197,7 +185,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; @@ -210,7 +198,7 @@ } if (roomNameList == "" ) { - roomNameList = Shared.Language.StringByID(StringId.WholeHouseScene); + roomNameList = Shared.Language.StringByID(StringId.WholeZone); } return roomNameList; } @@ -226,17 +214,132 @@ return "SceneData_" + sid; } } - /// <summary> - /// 淇濆瓨鍔熻兘鏁版嵁 + /// 鍦烘櫙鎵ц\鍊掕鏃� /// </summary> - public void SaveSceneData() + /// <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) + { + btnShowDelay.Text = (time / 60).ToString() + "min" + time % 60 + "s"; + } + else + { + btnShowDelay.Text = time.ToString() + "s"; + } + }); + System.Threading.Thread.Sleep(1000); + time--; + } + Application.RunOnMainThread(() => + { + btnShowDelay.Text = ""; + }); + } + }) + { IsBackground = true, Priority = System.Threading.ThreadPriority.BelowNormal }.Start(); + } + } + } + /// <summary> + /// 淇濆瓨鍦烘櫙鏁版嵁鏂囦欢 + /// </summary> + public void SaveSceneFile() { var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); - FileUtils.WriteFileByBytes(savePath, ssd); + FileUtlis.Files.WriteFileByBytes(savePath, ssd); MainPage.Log($"Save Scene Data : {savePath}"); - UploadScene(); } + + /// <summary> + /// 鏀惰棌鍦烘櫙 + /// </summary> + /// <returns></returns> + public void CollectScene() + { + var result = StateCode.SUCCESS; + new System.Threading.Thread(() => + { + if (collect) + { + result = ApiUtlis.Ins.HttpRequest.CollectScene(userSceneId); + } + else + { + result = ApiUtlis.Ins.HttpRequest.CancelCollectScene(userSceneId); + } + //鎻愮ず閿欒 + if (result != StateCode.SUCCESS) + { + Application.RunOnMainThread(() => + { + collect = !collect; + IMessageCommon.Current.ShowErrorInfoAlter(result); + }); + } + }) + { IsBackground = true }.Start(); + } + + /// <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> /// 涓婁紶鏁版嵁鍒颁簯绔� @@ -245,44 +348,30 @@ { var pm = new HttpServerRequest(); ResponsePackNew revPack; - if (DeleteSign) + if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime)) { - var resCode = pm.DeleteScene(userSceneId); - } - else - { - if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime)) + revPack = pm.AddScene(this); + if (revPack.Code == StateCode.SUCCESS) { - revPack = pm.AddScene(this); - if (revPack.Code == StateCode.SUCCESS) - { - var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); - FileUtils.WriteFileByBytes(savePath, ssd); - } + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); } - else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime)) + } + else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime)) + { + revPack = pm.EditScene(this); + if (revPack.Code == StateCode.SUCCESS) { - 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 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)); - FileUtils.WriteFileByBytes(savePath, ssd); - } + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene)); + Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); } } } } - - /// <summary> - /// 鍒犻櫎鏍囪 - /// 闇�瑕佸垹闄ゆ暟鎹椂锛屾爣璁颁负锛歵rue - /// 鐢变簯绔垹闄ゆ垚鍔熶箣鍚庯紝杩斿洖鏁版嵁鍐嶆竻闄ゆ湰鍦版暟鎹� - /// </summary> - public bool DeleteSign = false; /// <summary> /// 浜戠鏁版嵁鍒涘缓鐨勬椂闂� @@ -311,10 +400,11 @@ /// 鏈湴瀵瑰簲鐨勫姛鑳� /// </summary> [Newtonsoft.Json.JsonIgnore] - public Function localFunction { + public Function localFunction + { get { - if(_localFunction == null) + if (_localFunction == null) { _localFunction = ConvertFunctionObject(); } @@ -328,14 +418,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