| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 刷新本地的全部场景
|
| | | /// 刷新从网关刷新全部的场景
|
| | | /// </summary>
|
| | | public async Task<bool> RefreshSceneUIList()
|
| | | /// <param name="useLocalConnect">是否强制使用本地连接发送</param>
|
| | | public bool RefreshSceneUIList(bool useLocalConnect)
|
| | | {
|
| | | //获取网关存在的场景
|
| | | var sceneList = await ZigBee.Device.Scene.GetSceneListAsync();
|
| | | var sceneList = this.RefreshSceneListFromGateway(useLocalConnect);
|
| | | if (sceneList == null)
|
| | | {
|
| | | return false;
|
| | |
| | | continue;
|
| | | }
|
| | | listEsxit.Add(scene.ScenesId);
|
| | | //刷新scene的信息
|
| | | this.RefreshScene(scene);
|
| | | }
|
| | |
|
| | | var listDelete = new List<SceneUI>();
|
| | |
| | | foreach (var sceneui in listDelete)
|
| | | {
|
| | | //执行删除
|
| | | this.RemoveScene(sceneui);
|
| | | this.DeleteLocalScene(sceneui);
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 刷新scene的信息
|
| | | /// </summary>
|
| | | /// <param name="sceneInfo"></param>
|
| | | private void RefreshScene(Scene.GetSceneAllInfo sceneInfo)
|
| | | {
|
| | | if (this.dicScenes.ContainsKey(sceneInfo.ScenesId) == true)
|
| | | {
|
| | | var localScene = this.dicScenes[sceneInfo.ScenesId];
|
| | | //只刷新名字和绑定表
|
| | | localScene.Name = sceneInfo.ScenesName;
|
| | | localScene.AdjustTargetList.Clear();
|
| | | localScene.AdjustTargetList.AddRange(sceneInfo.DeviceList);
|
| | | localScene.Save();
|
| | | }
|
| | | else
|
| | | {
|
| | | var newScene = new SceneUI();
|
| | | newScene.Name = sceneInfo.ScenesName;
|
| | | newScene.IconPath = "SceneIcon/0.png";
|
| | | newScene.Id = sceneInfo.ScenesId;
|
| | | newScene.AdjustTargetList.AddRange(sceneInfo.DeviceList);
|
| | | //添加缓存
|
| | | newScene.Save();
|
| | | //加入缓存
|
| | | this.dicScenes[newScene.Id] = newScene;
|
| | | //备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(newScene.FileName);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从网关重新刷新场景列表
|
| | | /// </summary>
|
| | | /// <param name="useLocalConnect">是否强制使用本地连接发送</param>
|
| | | private List<Scene.GetSceneAllInfo> RefreshSceneListFromGateway(bool useLocalConnect)
|
| | | {
|
| | | var mainGateway = ZbGateway.MainGateWay;
|
| | | if (mainGateway == null)
|
| | | {
|
| | | //获取网关对象失败
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uGetGatewayTagartFail));
|
| | | return null;
|
| | | }
|
| | |
|
| | | //超时时间
|
| | | int TimeOut = 0;
|
| | | bool receiptAll = false;
|
| | | bool canReceve = false;
|
| | |
|
| | | var listScene = new List<Scene.GetSceneAllInfo>();
|
| | | Action<string, string> action = (topic, message) =>
|
| | | {
|
| | | var gatewayID = topic.Split('/')[0];
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | |
|
| | | if (topic == gatewayID + "/" + "Scene/GetAllInfo_Respon")
|
| | | {
|
| | | var sceneGetAllInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene.GetSceneAllInfo>(jobject["Data"].ToString());
|
| | | if (sceneGetAllInfo.ScenesSum != 0)
|
| | | {
|
| | | //如果网关里面没有场景的话,它也会推这个东西过来
|
| | | listScene.Add(sceneGetAllInfo);
|
| | | }
|
| | |
|
| | | //更够接收得到场景
|
| | | canReceve = true;
|
| | | if (sceneGetAllInfo.ScenesNum == sceneGetAllInfo.ScenesSum)
|
| | | {
|
| | | //接收完成
|
| | | receiptAll = true;
|
| | | TimeOut = 0;
|
| | | }
|
| | | }
|
| | | };
|
| | | mainGateway.Actions += action;
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 807 } };
|
| | | if (useLocalConnect == false)
|
| | | {
|
| | | mainGateway.Send(("Scene/GetAllInfo"), System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
|
| | | }
|
| | | else
|
| | | {
|
| | | mainGateway.SendLocation(("Scene/GetAllInfo"), System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
|
| | | }
|
| | |
|
| | | int waitTime = 20 * 6;
|
| | | while (receiptAll == false && TimeOut < waitTime)
|
| | | {
|
| | | //全部接收才退出
|
| | | System.Threading.Thread.Sleep(50);
|
| | | TimeOut++;
|
| | | }
|
| | | mainGateway.Actions -= action;
|
| | | action = null;
|
| | | if (canReceve == false)
|
| | | {
|
| | | //获取场景列表失败,网关回复超时
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uGetSceneListFailAndTimeOut));
|
| | | return null;
|
| | | }
|
| | | else if (receiptAll == false)
|
| | | {
|
| | | //网络不稳定,场景列表信息缺损
|
| | | this.ShowTipMsg(Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndSceneInfoIsNotFull));
|
| | | return null;
|
| | | }
|
| | |
|
| | | return listScene;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <param name="sceneName">场景名称</param>
|
| | | /// <param name="listAdjustTarget">执行目标</param>
|
| | | /// <returns></returns>
|
| | | public async Task<SceneUI> AddNewSceneToGateway(string sceneName, List<Scene.DeviceListData> listAdjustTarget)
|
| | | public SceneUI AddNewSceneToGateway(string sceneName, List<Scene.DeviceListData> listAdjustTarget)
|
| | | {
|
| | | var result1 = await Scene.GetSceneNewIdAsync(sceneName);
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result1);
|
| | | if (error != null)
|
| | | int NewScenesId = -1;
|
| | | //如果当前住宅不是虚拟住宅
|
| | | if (Config.Instance.Home.IsVirtually == false)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | return null;
|
| | | //获取新建一个场景的命令字符
|
| | | var strCommand = this.GetAddNewSceneCommand(sceneName);
|
| | | var result = HdlGatewayLogic.Current.SendJobjectDataToGateway(ZbGateway.MainGateWay, "Scene/GetNewId", strCommand, "Scene/GetNewId_Respon");
|
| | | if (result.ErrorMsg != null)
|
| | | {
|
| | | this.ShowTipMsg(result.ErrorMsg);
|
| | | return null;
|
| | | }
|
| | | if (result.ErrorMsgDiv == 0)
|
| | | {
|
| | | //添加场景失败
|
| | | string msg1 = Language.StringByID(R.MyInternationalizationString.AddSceneFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg1 = UserCenterLogic.CombineGatewayTimeOutMsg(msg1, result);
|
| | | this.ShowTipMsg(msg1);
|
| | | return null;
|
| | | }
|
| | | var getSceneIdData = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene.GetSceneIdData>(result.ReceiptData);
|
| | | NewScenesId = getSceneIdData.NewScenesId;
|
| | | }
|
| | | if (result1 == null || result1.getSceneIdData == null)
|
| | | else
|
| | | {
|
| | | //添加场景失败
|
| | | string msg1 = Language.StringByID(R.MyInternationalizationString.AddSceneFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg1 = UserCenterLogic.CombineGatewayTimeOutMsg(msg1, result1);
|
| | | this.ShowTipMsg(msg1);
|
| | | return null;
|
| | | //虚拟场景ID
|
| | | NewScenesId = Convert.ToInt32(DateTime.Now.ToString("HHmmss"));
|
| | | }
|
| | | //添加执行目标
|
| | | var listSuccess = await this.AddTargetToScene(result1.getSceneIdData.NewScenesId, listAdjustTarget);
|
| | | var listSuccess = this.AddTargetToScene(NewScenesId, listAdjustTarget);
|
| | | if (listSuccess == null)
|
| | | {
|
| | | return null;
|
| | |
| | | //创建场景对象
|
| | | var newScene = new SceneUI();
|
| | | newScene.Name = sceneName;
|
| | | newScene.Id = result1.getSceneIdData.NewScenesId;
|
| | | newScene.Id = NewScenesId;
|
| | | newScene.AdjustTargetList.AddRange(listSuccess);
|
| | | //添加缓存
|
| | | newScene.Save();
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取新建一个场景的命令字符
|
| | | /// </summary>
|
| | | /// <param name="sceneName">场景名称</param>
|
| | | /// <returns></returns>
|
| | | public string GetAddNewSceneCommand(string sceneName)
|
| | | {
|
| | | var bytes = new byte[32];
|
| | | var reamarkGwBytes = Encoding.UTF8.GetBytes(sceneName);
|
| | | Array.Copy(reamarkGwBytes, 0, bytes, 0, 32 < reamarkGwBytes.Length ? 32 : reamarkGwBytes.Length);
|
| | | sceneName = Encoding.UTF8.GetString(bytes);
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject() { { "Cluster_ID", 0 }, { "Command", 800 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "ScenesName", sceneName } };
|
| | | jObject.Add("Data", data);
|
| | |
|
| | | return jObject.ToString();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 添加执行目标到指定的场景(返回成功添加的执行目标)
|
| | | /// </summary>
|
| | | /// <param name="sceneId">场景Id</param>
|
| | | /// <param name="listAdjustTarget">执行目标</param>
|
| | | /// <returns></returns>
|
| | | private async Task<List<Scene.DeviceListData>> AddTargetToScene(int sceneId, List<Scene.DeviceListData> listAdjustTarget)
|
| | | private List<Scene.DeviceListData> AddTargetToScene(int sceneId, List<Scene.DeviceListData> listAdjustTarget)
|
| | | {
|
| | | var listSuccess = new List<Scene.DeviceListData>();
|
| | | for (int i = 0; i < listAdjustTarget.Count; i++)
|
| | | //如果当前住宅是虚拟住宅的话
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | var data = listAdjustTarget[i];
|
| | | var addData = new Scene.AddSceneMemberData();
|
| | | if (data.Type == 0)
|
| | | {
|
| | | //设备
|
| | | addData.Type = 0;
|
| | | addData.ScenesId = sceneId;
|
| | | addData.DeviceAddr = data.DeviceAddr;
|
| | | addData.Epoint = data.Epoint;
|
| | | addData.TaskList = data.TaskList;
|
| | | addData.DelayTime = 0;
|
| | | addData.MemberNumber = i + 1;
|
| | | }
|
| | | else if (data.Type == 1)
|
| | | {
|
| | | //场景
|
| | | addData.Type = 1;
|
| | | addData.ScenesId = sceneId;
|
| | | addData.ElseScenesId = data.ElseScenesId;
|
| | | addData.DelayTime = 0;
|
| | | addData.MemberNumber = i + 1;
|
| | | }
|
| | | else
|
| | | {
|
| | | //延时
|
| | | addData.Type = 2;
|
| | | addData.ScenesId = sceneId;
|
| | | addData.DelayTime = data.DelayTime;
|
| | | addData.MemberNumber = i + 1;
|
| | | }
|
| | | //不需要更新网关
|
| | | return listAdjustTarget;
|
| | | }
|
| | | var listSuccess = new List<Scene.DeviceListData>();
|
| | |
|
| | | //添加新成员 返回结果
|
| | | var result2 = await Scene.AddSceneMemberAsync(addData);
|
| | | if (result2 == null || result2.addSceneMemberResponseData == null
|
| | | || result2.addSceneMemberResponseData.Result != 1)
|
| | | //获取添加执行目标到场景的命令
|
| | | var listCommand = this.GetAddTargetToSceneCommand(sceneId, listAdjustTarget);
|
| | | for (int i = 0; i < listCommand.Count; i++)
|
| | | {
|
| | | var result = HdlGatewayLogic.Current.SendJobjectDataToGateway(ZbGateway.MainGateWay, "Scene/AddMember", listCommand[i], "Scene/AddMember_Respon");
|
| | | if (result.ErrorMsg != null || result.ErrorMsgDiv == 0)
|
| | | {
|
| | | //出现错误
|
| | | continue;
|
| | | }
|
| | | //拥有成功的
|
| | | listSuccess.Add(data);
|
| | | var addSceneMemberData = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene.AddSceneMemberResponseData>(result.ReceiptData);
|
| | | if (addSceneMemberData.Result == 1)
|
| | | {
|
| | | listSuccess.Add(listAdjustTarget[i]);
|
| | | }
|
| | | }
|
| | | if (listSuccess.Count == 0)
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取添加执行目标到场景的命令
|
| | | /// </summary>
|
| | | /// <param name="sceneId">场景id</param>
|
| | | /// <param name="listAdjustTarget">执行目标</param>
|
| | | /// <param name="dicChangedMac">交换mac key:listAdjustTarget当前的Mac value:转换的mac</param>
|
| | | /// <param name="sceneName">场景名称(特殊用途,请勿设置)</param>
|
| | | /// <returns></returns>
|
| | | public List<string> GetAddTargetToSceneCommand(int sceneId, List<Scene.DeviceListData> listAdjustTarget, Dictionary<string, string> dicChangedMac = null, string sceneName = null)
|
| | | {
|
| | | var listCommand = new List<string>();
|
| | | int index = 1;
|
| | | for (int i = 0; i < listAdjustTarget.Count; i++)
|
| | | {
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 820 } };
|
| | | var data = listAdjustTarget[i];
|
| | | //设备
|
| | | if (data.Type == 0)
|
| | | {
|
| | | string deviceAddr = data.DeviceAddr;
|
| | | if (dicChangedMac != null)
|
| | | {
|
| | | //如果不包含,则不作为处理对象
|
| | | if (dicChangedMac.ContainsKey(deviceAddr) == false)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | deviceAddr = dicChangedMac[deviceAddr];
|
| | | }
|
| | |
|
| | | var taskList = new Newtonsoft.Json.Linq.JArray { };
|
| | | foreach (var taskInfo in data.TaskList)
|
| | | {
|
| | | var tInfo = new Newtonsoft.Json.Linq.JObject{{ "TaskType", taskInfo.TaskType},
|
| | | { "Data1", taskInfo.Data1},{ "Data2",taskInfo.Data2}};
|
| | | taskList.Add(tInfo);
|
| | | }
|
| | | var data2 = new Newtonsoft.Json.Linq.JObject {{ "ScenesId",sceneId},{ "Type", 0} ,{ "DeviceAddr",deviceAddr} ,
|
| | | { "Epoint", data.Epoint} ,{ "TaskList", taskList },{ "DelayTime", 0} ,{ "MemberNumber",index}};
|
| | | if (sceneName != null)
|
| | | {
|
| | | data2.Add(new Newtonsoft.Json.Linq.JProperty("ScenesName", sceneName));
|
| | | }
|
| | | jObject.Add("Data", data2);
|
| | | }
|
| | | //场景
|
| | | else if (data.Type == 1)
|
| | | {
|
| | | var data2 = new Newtonsoft.Json.Linq.JObject {{ "ScenesId",sceneId},{ "Type", 1} ,
|
| | | { "ElseScenesId", data.ElseScenesId },{ "DelayTime", 0} ,{ "MemberNumber",index} };
|
| | | if (sceneName != null)
|
| | | {
|
| | | data2.Add(new Newtonsoft.Json.Linq.JProperty("ScenesName", sceneName));
|
| | | }
|
| | | jObject.Add("Data", data2);
|
| | | }
|
| | | //延时
|
| | | else
|
| | | {
|
| | | var data2 = new Newtonsoft.Json.Linq.JObject {{ "Type", 2} ,{ "ScenesId",sceneId},
|
| | | { "DelayTime", data.DelayTime} ,{ "MemberNumber",index}};
|
| | | if (sceneName != null)
|
| | | {
|
| | | data2.Add(new Newtonsoft.Json.Linq.JProperty("ScenesName", sceneName));
|
| | | }
|
| | | jObject.Add("Data", data2);
|
| | | }
|
| | | listCommand.Add(jObject.ToString());
|
| | | index++;
|
| | | }
|
| | | return listCommand;
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 添加场景(这个单纯只改房间)
|
| | | /// </summary>
|
| | | /// <param name="scene">Scene.</param>
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 改变场景房间
|
| | | /// </summary>
|
| | | /// <param name="scene">场景对象</param>
|
| | | /// <param name="newRoomId">新的房间的ID</param>
|
| | | public void ChangedSceneRoom(SceneUI scene, string newRoomId)
|
| | | {
|
| | | var room = HdlRoomLogic.Current.GetRoomBySceneId(scene.Id);
|
| | | if (room != null)
|
| | | {
|
| | | //房间没有改变
|
| | | if (room.Id == newRoomId)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //从房间中移除缓存
|
| | | this.DeleteSceneFromRoom(room, scene);
|
| | | }
|
| | | //添加进新房间
|
| | | var newRoom = HdlRoomLogic.Current.GetRoomById(newRoomId);
|
| | | this.AddSceneToRoom(newRoom, scene);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 添加搜藏场景
|
| | | /// </summary>
|
| | | /// <param name="scene">Scene.</param>
|
| | |
| | | {
|
| | | nowRoom.ListSceneId.Add(scene.Id);
|
| | | nowRoom.Save();
|
| | | //添加收藏场景时,需要刷新主页
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除场景(这个只移除内存)
|
| | | /// 添加虚拟场景
|
| | | /// </summary>
|
| | | /// <param name="scene"></param>
|
| | | public void DeleteSceneFromRoom(Room i_room, SceneUI scene)
|
| | | /// <param name="sceneId">指定场景id,如果为-1,则会内部自动编号(可能会重复)</param>
|
| | | /// <param name="sceneName">场景名字</param>
|
| | | /// <param name="listAdjustTarget">绑定目标</param>
|
| | | /// <returns></returns>
|
| | | public SceneUI AddVirtualScene(int sceneId, string sceneName, List<Scene.DeviceListData> listAdjustTarget)
|
| | | {
|
| | | //移除缓存
|
| | | if (i_room.ListSceneId.Contains(scene.Id) == true)
|
| | | if (sceneId == -1)
|
| | | {
|
| | | i_room.ListSceneId.Remove(scene.Id);
|
| | | i_room.Save();
|
| | | sceneId = Convert.ToInt32(DateTime.Now.ToString("HHmmss"));
|
| | | }
|
| | | }
|
| | | //创建场景对象
|
| | | var newScene = new SceneUI();
|
| | | newScene.Name = sceneName;
|
| | | newScene.IconPath = "SceneIcon/0.png";
|
| | | //虚拟场景ID
|
| | | newScene.Id = sceneId;
|
| | | if (listAdjustTarget != null)
|
| | | {
|
| | | newScene.AdjustTargetList.AddRange(listAdjustTarget);
|
| | | }
|
| | | //添加缓存
|
| | | newScene.Save();
|
| | | //加入缓存
|
| | | this.dicScenes[newScene.Id] = newScene;
|
| | |
|
| | | /// <summary>
|
| | | /// 删除搜藏场景
|
| | | /// </summary>
|
| | | /// <param name="scene"></param>
|
| | | public void DeleteLoveScene(SceneUI scene)
|
| | | {
|
| | | var nowRoom = HdlRoomLogic.Current.GetLoveRoom();
|
| | | //移除缓存
|
| | | if (nowRoom.ListSceneId.Contains(scene.Id) == true)
|
| | | {
|
| | | nowRoom.ListSceneId.Remove(scene.Id);
|
| | | nowRoom.Save();
|
| | | }
|
| | | return newScene;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <returns></returns>
|
| | | public async Task<bool> EditorSceneFromGateway(SceneUI sceneUI, List<Scene.DeviceListData> listAdjustTarget)
|
| | | {
|
| | | //如果当前住宅是虚拟住宅的话
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | //清空场景的执行目标列表的缓存
|
| | | sceneUI.AdjustTargetList.Clear();
|
| | | sceneUI.AdjustTargetList.AddRange(listAdjustTarget);
|
| | | sceneUI.Save();
|
| | | return true;
|
| | | }
|
| | |
|
| | | //先清空全部的执行目标
|
| | | var deleteData = new Scene.SceneRemoveMemberData();
|
| | | var deleteTargetData = new List<Scene.RemoveSceneDeviceListInfo>();
|
| | |
| | | sceneUI.AdjustTargetList.Clear();
|
| | |
|
| | | //然后重新添加
|
| | | var listSuccess = await this.AddTargetToScene(sceneUI.Id, listAdjustTarget);
|
| | | var listSuccess = this.AddTargetToScene(sceneUI.Id, listAdjustTarget);
|
| | | if (listSuccess == null)
|
| | | {
|
| | | return false;
|
| | |
| | | /// <returns></returns>
|
| | | public async Task<bool> EditorSceneNameFromGateway(SceneUI scene, string newName)
|
| | | {
|
| | | //如果当前住宅是虚拟住宅的话
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | //不需要更新网关
|
| | | return true;
|
| | | }
|
| | | var result1 = await Scene.RenameSceneAsync(scene.Id, newName);
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result1);
|
| | |
| | | #region ■ 删除场景___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 移除场景--该仅进行了对本地场景数据的删除
|
| | | /// 删除本地场景数据
|
| | | /// </summary>
|
| | | /// <param name="sceneUI">Scene user interface.</param>
|
| | | public void RemoveScene(SceneUI sceneUI)
|
| | | public void DeleteLocalScene(SceneUI sceneUI)
|
| | | {
|
| | | //移除缓存
|
| | | this.dicScenes.Remove(sceneUI.Id);
|
| | |
| | | HdlAutoBackupLogic.DeleteFile(sceneUI.IconPath);
|
| | | }
|
| | | }
|
| | | //删除场景时,需要刷新主页
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 清空本地全部的场景数据
|
| | | /// </summary>
|
| | | public void DeleteAllLocalScene()
|
| | | {
|
| | | var listScene = new List<SceneUI>();
|
| | | foreach (var scene in this.dicScenes.Values)
|
| | | {
|
| | | listScene.Add(scene);
|
| | | }
|
| | | foreach (var scene in listScene)
|
| | | {
|
| | | this.DeleteLocalScene(scene);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除场景(这个只移除内存)
|
| | | /// </summary>
|
| | | /// <param name="scene"></param>
|
| | | public void DeleteSceneFromRoom(Room i_room, SceneUI scene)
|
| | | {
|
| | | //移除缓存
|
| | | if (i_room.ListSceneId.Contains(scene.Id) == true)
|
| | | {
|
| | | i_room.ListSceneId.Remove(scene.Id);
|
| | | i_room.Save();
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除搜藏场景
|
| | | /// </summary>
|
| | | /// <param name="scene"></param>
|
| | | public void DeleteLoveScene(SceneUI scene)
|
| | | {
|
| | | var nowRoom = HdlRoomLogic.Current.GetLoveRoom();
|
| | | //移除缓存
|
| | | if (nowRoom.ListSceneId.Contains(scene.Id) == true)
|
| | | {
|
| | | nowRoom.ListSceneId.Remove(scene.Id);
|
| | | nowRoom.Save();
|
| | | //取消收藏场景时,需要刷新主页
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取场景___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取本地全部的场景(包含未分配)
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public List<SceneUI> GetAllLocalScene()
|
| | | {
|
| | | //房间的场景放在前面
|
| | | var listScene = this.GetAllRoomSceneList();
|
| | | //未分配的场景
|
| | | var listUnalloctScene = this.GetUnalloctedScenes();
|
| | | listScene.AddRange(listUnalloctScene);
|
| | | return listScene;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 通过场景id获取场景
|
| | |
| | | /// <returns></returns>
|
| | | public string GetZoneById(int sceneId)
|
| | | {
|
| | | var room =HdlRoomLogic.Current.GetRoomBySceneId(sceneId);
|
| | | var room = HdlRoomLogic.Current.GetRoomBySceneId(sceneId);
|
| | | if (room == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | var floorName = Shared.Common.Config.Instance.Home.GetFloorNameById(room.FloorId);
|
| | | if (floorName == null)
|
| | | var floorName = HdlResidenceLogic.Current.GetFloorNameById(room.FloorId);
|
| | | //更改代码:如果floorName=“”也要判断,否则有“,”
|
| | | if (string.IsNullOrEmpty(floorName))
|
| | | {
|
| | | return room.Name;
|
| | | }
|
| | |
| | | sceneUIs.Add(myScene);
|
| | | }
|
| | | }
|
| | |
|
| | | if (sceneUIs.Count == 0)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return sceneUIs;
|
| | | }
|
| | |
|
| | |
| | | var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
|
| | | foreach (var room in listAllRoom)
|
| | | {
|
| | | if (room.IsLove == true)
|
| | | {
|
| | | //不包含收藏房间
|
| | | continue;
|
| | | }
|
| | | foreach (int sceneId in room.ListSceneId)
|
| | | {
|
| | | if (this.dicScenes.ContainsKey(sceneId) == true)
|
| | |
| | | });
|
| | | return false;
|
| | | }
|
| | | //如果是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | //不调用网关
|
| | | return true;
|
| | | }
|
| | |
|
| | | //执行调用场景
|
| | | var result = await Scene.ControlSceneAsync(scene.Id, scene.SceneDelayTime);
|
| | | if (result == null || result.sceneOpenData == null)
|
| | |
| | | /// </summary>
|
| | | /// <param name="i_scene">场景对象</param>
|
| | | /// <returns></returns>
|
| | | public async Task<List<Scene.DeviceListData>> GetAdjustTargetList(SceneUI i_scene)
|
| | | public List<Scene.DeviceListData> GetAdjustTargetList(SceneUI i_scene)
|
| | | {
|
| | | var result = await Scene.GetSceneDeviceListAsync(i_scene.Id);
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | //如果住宅为虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | var listAdjustTarget = new List<Scene.DeviceListData>();
|
| | | listAdjustTarget.AddRange(i_scene.AdjustTargetList);
|
| | | return listAdjustTarget;
|
| | | }
|
| | | //如果是有模板,有设备的时候,在没有发送成功之前,不允许刷新执行目标对象
|
| | | if (Common.Config.Instance.Home.TemplateMode == 2
|
| | | && Common.Config.Instance.Home.SendTemplateSuccess == false)
|
| | | {
|
| | | var listAdjustTarget = new List<Scene.DeviceListData>();
|
| | | listAdjustTarget.AddRange(i_scene.AdjustTargetList);
|
| | | return listAdjustTarget;
|
| | | }
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 806 } };
|
| | | var data = new Newtonsoft.Json.Linq.JObject { { "ScenesId", i_scene.Id } };
|
| | | jObject.Add("Data", data);
|
| | | //发送命令
|
| | | var result = HdlGatewayLogic.Current.SendJobjectDataToGateway(ZbGateway.MainGateWay, "Scene/GetDeviceList", jObject.ToString(), "Scene/GetDeviceList_Respon");
|
| | |
|
| | | if (result.ErrorMsg != null)
|
| | | {
|
| | | this.ShowTipMsg(result.ErrorMsg);
|
| | | return null;
|
| | | }
|
| | | if (result == null || result.getSceneDeviceListInfo == null)
|
| | | if (result.ErrorMsgDiv == 0)
|
| | | {
|
| | | //获取执行目标失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetAdjustTargetFail);
|
| | |
| | | this.ShowTipMsg(msg);
|
| | | return null;
|
| | | }
|
| | | i_scene.AdjustTargetList = result.getSceneDeviceListInfo.DeviceList;
|
| | | var sceneGetDeviceListObj = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene.GetSceneDeviceListInfo>(result.ReceiptData);
|
| | |
|
| | | i_scene.AdjustTargetList = sceneGetDeviceListObj.DeviceList;
|
| | | //保存缓存
|
| | | i_scene.Save(false);
|
| | |
|
| | | var listData = new List<Scene.DeviceListData>();
|
| | | listData.AddRange(result.getSceneDeviceListInfo.DeviceList);
|
| | | listData.AddRange(sceneGetDeviceListObj.DeviceList);
|
| | |
|
| | | return listData;
|
| | | }
|
| | |
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 改变场景房间
|
| | | /// </summary>
|
| | | /// <param name="scene">场景对象</param>
|
| | | /// <param name="newRoomId">新的房间的ID</param>
|
| | | public void ChangedSceneRoom(SceneUI scene, string newRoomId)
|
| | | {
|
| | | var room = HdlRoomLogic.Current.GetRoomBySceneId(scene.Id);
|
| | | if (room != null)
|
| | | {
|
| | | //房间没有改变
|
| | | if (room.Id == newRoomId)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //从房间中移除缓存
|
| | | this.DeleteSceneFromRoom(room, scene);
|
| | | }
|
| | | //添加进新房间
|
| | | var newRoom = HdlRoomLogic.Current.GetRoomById(newRoomId);
|
| | | this.AddSceneToRoom(newRoom, scene);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取本地全部的场景文件
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public List<string> GetAllSceneFile()
|
| | | {
|
| | | List<string> listSceneFile = new List<string>();
|
| | | List<string> listAllFile = Global.FileListByHomeId();
|
| | | List<string> listAllFile = HdlFileLogic.Current.GetRootPathListFile();
|
| | |
|
| | | foreach (string file in listAllFile)
|
| | | {
|