| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 刷新本地的全部场景
|
| | | /// 刷新从网关刷新全部的场景
|
| | | /// </summary>
|
| | | public bool RefreshSceneUIList()
|
| | | /// <param name="useLocalConnect">是否强制使用本地连接发送</param>
|
| | | public bool RefreshSceneUIList(bool useLocalConnect)
|
| | | {
|
| | | //获取网关存在的场景
|
| | | var sceneList = this.RefreshSceneListFromGateway();
|
| | | var sceneList = this.RefreshSceneListFromGateway(useLocalConnect);
|
| | | if (sceneList == null)
|
| | | {
|
| | | return false;
|
| | |
| | | /// <summary>
|
| | | /// 从网关重新刷新场景列表
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private List<Scene.GetSceneAllInfo> RefreshSceneListFromGateway()
|
| | | /// <param name="useLocalConnect">是否强制使用本地连接发送</param>
|
| | | private List<Scene.GetSceneAllInfo> RefreshSceneListFromGateway(bool useLocalConnect)
|
| | | {
|
| | | var mainGateway = ZbGateway.MainGateWay;
|
| | | if (mainGateway == null)
|
| | |
| | | mainGateway.Actions += action;
|
| | |
|
| | | var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 807 } };
|
| | | mainGateway.Send(("Scene/GetAllInfo"), System.Text.Encoding.UTF8.GetBytes(jObject.ToString()));
|
| | | 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)
|
| | |
| | | /// <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)
|
| | | {
|
| | | int NewScenesId = -1;
|
| | | //如果当前住宅不是虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == false)
|
| | | if (Config.Instance.Home.IsVirtually == false)
|
| | | {
|
| | | var result1 = await Scene.GetSceneNewIdAsync(sceneName);
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result1);
|
| | | if (error != null)
|
| | | //获取新建一个场景的命令字符
|
| | | var strCommand = this.GetAddNewSceneCommand(sceneName);
|
| | | var result = HdlGatewayLogic.Current.SendJobjectDataToGateway(ZbGateway.MainGateWay, "Scene/GetNewId", strCommand, "Scene/GetNewId_Respon");
|
| | | if (result.ErrorMsg != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | this.ShowTipMsg(result.ErrorMsg);
|
| | | return null;
|
| | | }
|
| | | if (result1 == null || result1.getSceneIdData == null)
|
| | | if (result.ErrorMsgDiv == 0)
|
| | | {
|
| | | //添加场景失败
|
| | | string msg1 = Language.StringByID(R.MyInternationalizationString.AddSceneFail);
|
| | | //拼接上【网关回复超时】的Msg
|
| | | msg1 = UserCenterLogic.CombineGatewayTimeOutMsg(msg1, result1);
|
| | | msg1 = UserCenterLogic.CombineGatewayTimeOutMsg(msg1, result);
|
| | | this.ShowTipMsg(msg1);
|
| | | return null;
|
| | | }
|
| | | NewScenesId = result1.getSceneIdData.NewScenesId;
|
| | | var getSceneIdData = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene.GetSceneIdData>(result.ReceiptData);
|
| | | NewScenesId = getSceneIdData.NewScenesId;
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | NewScenesId = Convert.ToInt32(DateTime.Now.ToString("HHmmss"));
|
| | | }
|
| | | //添加执行目标
|
| | | var listSuccess = await this.AddTargetToScene(NewScenesId, listAdjustTarget);
|
| | | var listSuccess = this.AddTargetToScene(NewScenesId, listAdjustTarget);
|
| | | if (listSuccess == null)
|
| | | {
|
| | | return null;
|
| | |
| | | }
|
| | |
|
| | | /// <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)
|
| | | {
|
| | | //如果当前住宅是虚拟住宅的话
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | |
| | | return listAdjustTarget;
|
| | | }
|
| | | var listSuccess = new List<Scene.DeviceListData>();
|
| | | for (int i = 0; i < listAdjustTarget.Count; i++)
|
| | | {
|
| | | 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;
|
| | | }
|
| | |
|
| | | //添加新成员 返回结果
|
| | | 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"></param>
|
| | | /// <param name="listAdjustTarget"></param>
|
| | | /// <returns></returns>
|
| | | public List<string> GetAddTargetToSceneCommand(int sceneId, List<Scene.DeviceListData> listAdjustTarget)
|
| | | {
|
| | | var listCommand = new List<string>();
|
| | | 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)
|
| | | {
|
| | | 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",data.DeviceAddr} ,
|
| | | { "Epoint", data.Epoint} ,{ "TaskList", taskList },{ "DelayTime", 0} ,{ "MemberNumber",i + 1}};
|
| | | 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",i + 1} };
|
| | | jObject.Add("Data", data2);
|
| | | }
|
| | | //延时
|
| | | else
|
| | | {
|
| | | var data2 = new Newtonsoft.Json.Linq.JObject {{ "Type", 2} ,{ "ScenesId",sceneId},
|
| | | { "DelayTime", data.DelayTime} ,{ "MemberNumber",i + 1}};
|
| | | jObject.Add("Data", data2);
|
| | | }
|
| | | listCommand.Add(jObject.ToString());
|
| | | }
|
| | | return listCommand;
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 添加场景(这个单纯只改房间)
|
| | | /// </summary>
|
| | | /// <param name="scene">Scene.</param>
|
| | |
| | | i_room.ListSceneId.Add(scene.Id);
|
| | | i_room.Save();
|
| | | }
|
| | | }
|
| | |
|
| | | /// <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>
|
| | |
| | | sceneUI.AdjustTargetList.Clear();
|
| | |
|
| | | //然后重新添加
|
| | | var listSuccess = await this.AddTargetToScene(sceneUI.Id, listAdjustTarget);
|
| | | var listSuccess = this.AddTargetToScene(sceneUI.Id, listAdjustTarget);
|
| | | if (listSuccess == null)
|
| | | {
|
| | | return false;
|
| | |
| | | /// </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)
|
| | | {
|
| | | //如果住宅为虚拟住宅
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | |
| | | 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");
|
| | |
|
| | | var result = await Scene.GetSceneDeviceListAsync(i_scene.Id);
|
| | | //共通错误检测
|
| | | string error = HdlCheckLogic.Current.CheckCommonErrorCode(result);
|
| | | if (error != null)
|
| | | if (result.ErrorMsg != null)
|
| | | {
|
| | | this.ShowErrorMsg(error);
|
| | | 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>
|