| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using Shared.Phone.Device.Category; |
| | | using Shared.Phone;
|
| | | using Shared.Phone.UserCenter; |
| | | |
| | | namespace Shared.Common |
| | |
| | | /// 场景 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneUI : ZigBee.Device.CommonDevice |
| | | { |
| | | #region ◆ 变量____________________________ |
| | | public class SceneUI |
| | | {
|
| | | #region ■ 变量声明_________________________ |
| | | /// <summary> |
| | | /// 场景文件 |
| | | /// </summary> |
| | |
| | | /// 场景id |
| | | /// </summary> |
| | | public int Id = -1; |
| | | |
| | | /// <summary> |
| | | /// 场景名 |
| | | /// </summary> |
| | | public string Name = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 图片路径 |
| | | /// </summary> |
| | |
| | | /// 图片来源 0--本地图库 1--拍照 2--系统图库 |
| | | /// </summary> |
| | | public int IconPathType = 0; |
| | | |
| | | /// <summary> |
| | | /// 功能路径列表---备用 |
| | | /// </summary> |
| | | public List<string> FunctionFilePathList = new List<string> { }; |
| | | |
| | | /// <summary> |
| | | /// 通用标识--备用 |
| | | /// </summary> |
| | | public object Tag; |
| | | |
| | | /// <summary> |
| | | /// 延时执行时间--设备延时 |
| | | /// </summary> |
| | | public int DelayTime = 0;
|
| | |
|
| | | /// <summary>
|
| | | /// 标识当前场景是否是分享的场景
|
| | | /// </summary>
|
| | | public bool IsSharedScene = false; |
| | | ///// <summary> |
| | | ///// 是否收藏 |
| | | ///// </summary> |
| | | //public bool IsCollected = false; |
| | | |
| | | /// <summary> |
| | | /// 延时执行时间--整个场景延时(不是延时场景里面的执行目标) |
| | | /// 不序列化,重新打开APP置。即只对本次编辑场景延时执行有效 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int SceneDelayTime = 0;
|
| | | |
| | | public int SceneDelayTime = 0; |
| | | /// <summary> |
| | | /// 剩余触发时间,单位秒 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public int RemainTime; |
| | |
|
| | | public int RemainTime;
|
| | | /// <summary>
|
| | | /// 延时时间线程是否运行
|
| | | /// </summary>
|
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public bool RemainThreadAction = false;
|
| | | /// <summary>
|
| | | /// 场景执行目标
|
| | | /// </summary>
|
| | | public List<ZigBee.Device.Scene.AddSceneMemberData> AddSceneMemberDataList = new List<ZigBee.Device.Scene.AddSceneMemberData> { }; |
| | | ///// <summary> |
| | | ///// RoomId |
| | | ///// </summary> |
| | | //public string RoomId = string.Empty; |
| | | public List<ZigBee.Device.Scene.DeviceListData> AdjustTargetList = new List<ZigBee.Device.Scene.DeviceListData>(); |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 通过场景id获取场景路径_____________ |
| | | /// <summary> |
| | | /// GetSceneFilePathBySceneId |
| | | /// </summary> |
| | | /// <param name="sceneId"></param> |
| | | /// <returns></returns> |
| | | public static string GetSceneFilePathBySceneId(int sceneId) |
| | | { |
| | | return $"Scene_{sceneId}.json"; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 通过id获取场景区域_________________ |
| | | |
| | | /// <summary> |
| | | /// GetZone |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public string GetZone() |
| | | { |
| | | var room = Room.CurrentRoom.GetRoomBySceneId(Id); |
| | | if(room==null) |
| | | { |
| | | return null; |
| | | } |
| | | var floorName = Shared.Common.Config.Instance.Home.GetFloorNameById(room.FloorId); |
| | | if (floorName == null) |
| | | { |
| | | return room.Name; |
| | | } |
| | | return $"{floorName},{room.Name}"; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ◆ 编辑场景_________________________ |
| | | /// <summary> |
| | | /// 编辑场景 |
| | | /// </summary> |
| | | /// <param name="sceneUI">sceneUI</param> |
| | | /// <param name="room">Room.</param> |
| | | public static void EditScene(SceneUI sceneUI, Room room) |
| | | { |
| | | Application.RunOnMainThread(async () => |
| | | { |
| | | try |
| | | { |
| | | var targetList = new List<SceneTargetDeviceUI> { }; |
| | | CommonPage.Loading.Start(); |
| | | //从网关中反序列化出对应的房间设备 |
| | | var sceneDeviceList = await ZigBee.Device.Scene.GetSceneDeviceListAsync(sceneUI.Id); |
| | | if (sceneDeviceList == null) |
| | | { |
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheMainGatewayIsNotOnLine); |
| | | return; |
| | | } |
| | | |
| | | if (Shared.Common.Room.AllRoomDeviceUIList.Count == 0) |
| | | { |
| | | |
| | | if (Shared.Common.Room.AllRoomDeviceUIList.Count == 0) |
| | | { |
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ThisSceneHaveNoDevice); |
| | | } |
| | | //return; |
| | | } |
| | | if (sceneDeviceList.getSceneDeviceListInfo != null) |
| | | { |
| | | var deviceList = sceneDeviceList.getSceneDeviceListInfo.DeviceList; |
| | | |
| | | if (deviceList != null && Room.AllRoomDeviceUIList.Count != 0) |
| | | { |
| | | foreach (var sceneDev in deviceList) |
| | | { |
| | | if (sceneDev.Type == 0) |
| | | { |
| | | var dev = Room.AllRoomDeviceUIList.Find((obj) => obj.DeviceEpoint == sceneDev.Epoint && obj.DeviceAddr == sceneDev.DeviceAddr); |
| | | if(dev!=null) |
| | | { |
| | | var sceneTargetDevice = new SceneTargetDeviceUI { |
| | | Type = 0, |
| | | DeviceUI = dev, |
| | | TaskList = sceneDev.TaskList, |
| | | DelayTimeSerialNumber= deviceList.IndexOf(sceneDev) + 1 |
| | | }; |
| | | |
| | | targetList.Add(sceneTargetDevice); |
| | | } |
| | | } |
| | | else if (sceneDev.Type == 1) |
| | | { |
| | | var localScene = Room.AllRoomSceneUIList.Find((obj) => obj.Id == sceneDev.ElseScenesId); |
| | | if (localScene != null) |
| | | { |
| | | var sceneTargetDeviceScene = new SceneTargetDeviceUI { |
| | | Type = 1, |
| | | ElseScenesId = sceneDev.ElseScenesId, |
| | | SceneName = localScene.Name, |
| | | SceneUI = localScene, |
| | | DelayTimeSerialNumber = deviceList.IndexOf(sceneDev) + 1 |
| | | }; |
| | | targetList.Add(sceneTargetDeviceScene); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var sceneTargetDeviceScene = new SceneTargetDeviceUI |
| | | { |
| | | Type = 2, |
| | | DelayTime = sceneDev.DelayTime, |
| | | DelayTimeSerialNumber = deviceList.IndexOf(sceneDev)+1 |
| | | }; |
| | | targetList.Add(sceneTargetDeviceScene); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain); |
| | | } |
| | | var scene = new CategoryAddScene(); |
| | | Phone.UserView.HomePage.Instance.AddChidren(scene); |
| | | Phone.UserView.HomePage.Instance.PageIndex += 1; |
| | | scene.isModify = true; |
| | | scene.modifyRoom = room; |
| | | scene.modifySceneUI = sceneUI; |
| | | scene.modifySceneTargetDevicesList = targetList; |
| | | scene.Show(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | System.Console.WriteLine($"编辑场景出错---{ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | CommonPage.Loading.Hide(); |
| | | } |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region ◆ 保存____________________________ |
| | | |
| | |
|
| | | #region ■ 保存_____________________________ |
| | |
|
| | | /// <summary> |
| | | /// 保存 |
| | | /// </summary> |
| | |
| | | Global.WriteFileByBytesByHomeId(FileName, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | if (autoBackup == true) |
| | | { |
| | | HdlAutoBackupLogic.AddOrEditorFile(FileName); |
| | | HdlBackupLogic.Current.AddOrEditorAutoBackFileStatu(FileName); |
| | | } |
| | | } |
| | | |
| | | }
|
| | |
|
| | | #endregion |
| | | |
| | | } |
| | | } |