| | |
| | | public Scene() |
| | | { |
| | | sid = NewSid(); |
| | | gatewayId = DB_ResidenceData.residenceData.HomeGateway.gatewayId; |
| | | if (!DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull()) |
| | | { |
| | | gatewayId = DB_ResidenceData.Instance.HomeGateway.gatewayId; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 云端唯一ID |
| | | /// </summary> |
| | | public string userSceneId = ""; |
| | | public string userSceneId = null; |
| | | /// <summary> |
| | | /// 场景sid |
| | | /// </summary> |
| | |
| | | /// <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> |
| | | /// 场景分组 |
| | |
| | | string roomNameList = ""; |
| | | foreach (var roomId in roomIds) |
| | | { |
| | | var findRoom = DB_ResidenceData.residenceData.Rooms.Find(obj => obj.roomId == roomId); |
| | | var findRoom = SpatialInfo.CurrentSpatial.RoomList.Find(obj => obj.roomId == roomId); |
| | | if (findRoom == null) |
| | | { |
| | | continue; |
| | |
| | | } |
| | | if (roomNameList == "" ) |
| | | { |
| | | roomNameList = Shared.Language.StringByID(StringId.WholeHouseScene); |
| | | roomNameList = Shared.Language.StringByID(StringId.WholeZone); |
| | | } |
| | | return roomNameList; |
| | | } |
| | |
| | | return "SceneData_" + sid; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 场景执行\倒计时 |
| | | /// </summary> |
| | | /// <param name="btnShowDelay"></param> |
| | | public void SceneCountDown(Button btnShowDelay) |
| | | { |
| | | //场景正在倒计时执行中 |
| | | 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> |
| | | /// 保存功能数据 |
| | |
| | | else |
| | | { |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | FileUtils.WriteFileByBytes(savePath, ssd); |
| | | 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> |
| | | /// 上传数据到云端 |
| | |
| | | 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)) |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | /// 本地对应的功能 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public Function localFunction { |
| | | public Function localFunction |
| | | { |
| | | get |
| | | { |
| | | if(_localFunction == null) |
| | | if (_localFunction == null) |
| | | { |
| | | _localFunction = ConvertFunctionObject(); |
| | | } |
| | |
| | | /// <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> |