From 5eeafe3af80bfd88306bd8ad9e76c8f4b51ca35f Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期四, 17 十二月 2020 14:16:20 +0800 Subject: [PATCH] 增加本地发送的重发机制 --- HDL_ON/Entity/Function/Scene.cs | 612 ++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 382 insertions(+), 230 deletions(-) diff --git a/HDL_ON/Entity/Function/Scene.cs b/HDL_ON/Entity/Function/Scene.cs index 500f47e..207a844 100644 --- a/HDL_ON/Entity/Function/Scene.cs +++ b/HDL_ON/Entity/Function/Scene.cs @@ -1,45 +1,163 @@ 锘縰sing System; using System.Collections.Generic; +using HDL_ON.DAL.Server; +using Shared; namespace HDL_ON.Entity { - public class Scene : Function + public class SceneApiPack + { + static SceneApiPack _ScenePack; + public static SceneApiPack ScenePack + { + get + { + if(_ScenePack == null) + { + _ScenePack = new SceneApiPack(); + } + return _ScenePack; + } + } + + } + + public class Scene { public Scene() { + sid = NewSid(); + if (!DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull()) + { + gatewayId = DB_ResidenceData.Instance.HomeGateway.gatewayId; + } } + /// <summary> + /// 浜戠鍞竴ID + /// </summary> + public string userSceneId = ""; + /// <summary> + /// 鍦烘櫙sid + /// </summary> + public string sid = ""; + /// <summary> + /// 鍦烘櫙鍚嶇О + /// </summary> + public string name = ""; + /// <summary> + /// 缃戝叧ID + /// </summary> + public string gatewayId = ""; + /// <summary> + /// 浜戠oss瀛樺偍鍥剧墖鐨勮矾寰� + /// </summary> + public string image = ""; + /// <summary> + /// 鎵�灞炴埧闂村垪琛� + /// </summary> + public List<string> roomIds = new List<string>(); + /// <summary> + /// 鎵�灞炴埧闂村垪琛� + /// </summary> + public List<string> uids = new List<string>(); + /// <summary> + /// 寤舵椂 + /// </summary> + 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; + // } + //} + /// <summary> + /// 鍦烘櫙鍒嗙粍 + /// </summary> + public string group = "1"; /// <summary> /// 鍦烘櫙绫诲瀷 /// </summary> public SceneType sceneType = SceneType.OrdinaryScenes; - /// <summary> - /// 鍦烘櫙鑳屾櫙 + /// 鏀惰棌鏍囪 /// </summary> - public string ImagePath = "Intelligence/Gallery/scenebg1.png";//"FunctionIcon/Scene/s1.png"; + public bool collect = false; + + ///// <summary> + ///// 鍦烘櫙鑳屾櫙 + ///// </summary> + //public string ImagePath = "Intelligence/Gallery/scenebg1.png";//"FunctionIcon/Scene/s1.png"; + + ///// <summary> + ///// 鍦烘櫙鑳屾櫙 + ///// </summary> + public string ImagePath + { + get + { + if (string.IsNullOrEmpty(image)) + { + return "Intelligence/Gallery/scenebg1.png"; + } + else + { + return image; + } + } + set + { + image = value; + } + } + /// <summary> /// 鍦烘櫙鍔熻兘鍒楄〃 /// </summary> - public List<Function> sceneFunctionList = new List<Function>(); + public List<SceneFunction> functions = new List<SceneFunction>(); + /// <summary> + /// 鍦烘櫙鎺ㄩ�侀厤缃垪琛� + /// </summary> + 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); @@ -53,239 +171,273 @@ { sTimeSpan = sTimeSpan.Substring(0, 8); } - else + else { 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> + /// 鑾峰彇璁惧娣诲姞鍒版埧闂寸殑鎴块棿鍚嶇О + /// </summary> + /// <returns></returns> + public string GetRoomListName() + { + string roomNameList = ""; + foreach (var roomId in roomIds) + { + var findRoom = SpatialInfo.CurrentSpatial.RoomList.Find(obj => obj.roomId == roomId); + if (findRoom == null) + { + continue; + } + if (roomNameList != "") + { + roomNameList += ","; + } + roomNameList += findRoom.floorName + findRoom.roomName; + } + if (roomNameList == "" ) + { + roomNameList = Shared.Language.StringByID(StringId.WholeHouseScene); + } + return roomNameList; + } + + /// <summary> + /// 鏁版嵁瀛樺偍鏂囦欢鍚� + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public string savePath + { + get + { + return "SceneData_" + sid; + } + } + + /// <summary> + /// 淇濆瓨鍔熻兘鏁版嵁 + /// </summary> + public void SaveSceneData(bool upServer) + { + if (upServer) + { + UploadScene(); + } + else + { + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + 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> + /// 娣诲姞鍦烘櫙 + /// </summary> + public string AddScene() + { + var pm = new HttpServerRequest(); + var revPack = pm.AddScene(this); + if (revPack.Code == StateCode.SUCCESS) + { + var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); + Common.FileUtlis.Files.WriteFileByBytes(savePath, ssd); + } + return revPack.Code; + } + + /// <summary> + /// 涓婁紶鏁版嵁鍒颁簯绔� + /// </summary> + void UploadScene() + { + var pm = new HttpServerRequest(); + ResponsePackNew revPack; + if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime)) + { + revPack = pm.AddScene(this); + if (revPack.Code == StateCode.SUCCESS) + { + 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)) + { + 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); + } + } + } + } + + /// <summary> + /// 浜戠鏁版嵁鍒涘缓鐨勬椂闂� + /// </summary> + public string createTime = ""; + /// <summary> + /// 浜戠鏁版嵁淇敼鐨勬渶鍚庢椂闂� + /// </summary> + public string modifyTime = ""; + } + /// <summary> + /// 鍦烘櫙鍔熻兘瀵硅薄 + /// </summary> + public class SceneFunction + { + public string sid = ""; + + public List<SceneFunctionStatus> status = new List<SceneFunctionStatus>(); + /// <summary> + /// 鍔熻兘寤舵椂 + /// </summary> + public string delay = "0"; + + Function _localFunction; + /// <summary> + /// 鏈湴瀵瑰簲鐨勫姛鑳� + /// </summary> + [Newtonsoft.Json.JsonIgnore] + public Function localFunction + { + get + { + if (_localFunction == null) + { + _localFunction = ConvertFunctionObject(); + } + return _localFunction; + } + } + + /// <summary> + /// 杞崲鎴愬姛鑳藉璞� + /// </summary> + /// <returns></returns> + Function ConvertFunctionObject() + { + var localFunction = FunctionList.List.GetDeviceFunctionList().Find((obj) => obj.sid == sid); + return localFunction; } } + /// <summary> + /// 鍦烘櫙鍔熻兘灞炴�� + /// </summary> + public class SceneFunctionStatus + { + public string key = ""; + public string value = ""; + } + /// <summary> + /// 鍦烘櫙鎺ㄩ�侀厤缃� + /// </summary> + public class ScenePushConfig + { + /// <summary> + /// 鎺ㄩ�佹柟寮� + /// </summary> + public string pushMethod = ""; + /// <summary> + /// 鎺ㄩ�佸唴瀹� + /// </summary> + public string pushContent = ""; + /// <summary> + /// 鎺ㄩ�佺洰鏍囬泦鍚� + /// </summary> + public List<string> pushTarget = new List<string>(); + } } -//5.1.14鑾峰彇鍦烘櫙鍒楄〃 -//璇锋眰鍙傛暟 -//{ -// "namespace": "HDL", -// "type": "scene", -// "command": "get_list" -//} -//杩斿洖鍊� json鏍煎紡 鎵�鏈夊満鏅痠d鍙婂満鏅噷鎵ц鐨勭洰鏍囨暟鎹� -//杩斿洖渚嬪瓙 -//{ -// "namespace": "HDL", -// "command": "get_list_respond", -// "type": "scene", -// "number": [{ -// "scene_id": "0001", -// "scene_name": "dinner", -// "objects": [{ -// "sid": "00010019101209000025670100010001", -//"data_type": "string ", -// "value": "on" -// }] -// }] -//} -//璇存槑 鑾峰彇鍦烘櫙鍒楄〃鍜屽睘鎬э紝鍙紑锛屽彧鍏筹紝鏃㈠紑鍙堝叧 - -//5.1.15鍒涘缓鍦烘櫙 -//璇锋眰鍙傛暟 -//{ -// "namespace": "HDL", -// "command": "create", -// "type": "scene", -// "objects": [{ -// "scene_name": "Away ", -// "status": "single_off" -// }] -//} -//杩斿洖鍊� json鏍煎紡 -//杩斿洖渚嬪瓙 { -// "namespace": "HDL", -// "command": "create_respond", -// "type": "scene", -// "objects": [{ -// "scene_id": "0004", -// "name": "Away", -// "status": "single_off" -// }] -//} -//璇存槑 鍒涘缓鍦烘櫙 - -//5.1.16娣诲姞鐩爣鍒板満鏅� -//璇锋眰鍙傛暟 -//{ -// "namespace": "HDL", -// "command": "add_member", -// "type": "scene", -// "number": [{ -// "scene_id": "0001", -// "objects": [{ -// "sid": "00010019101209000025670100010001", -// "function": [{ -// "attri": "switch", -//"data_type": "string ", -// "value": "on" -// }] - -// }] -// }, { -// "scene_id": "0002", -// "objects": [{ -// "sid": "00010019101209000025670200010001", -// "function": [{ -// "attri": "brightness", -//"data_type": "int", -// "value": 50 -// }] -// }] -// }] -//} -//杩斿洖鍊� json鏍煎紡 -//杩斿洖渚嬪瓙 { -// "namespace": "HDL", -// "command": "add_member_respond", -// "type": "scene", -// "scene_id": "0001", -// "value": "success" -//} -//璇存槑 鎴愬姛娣诲姞鐩爣鐨勫満鏅垪琛� - -//5.1.17鍒犻櫎鍦烘櫙鍛戒护 -//璇锋眰鍙傛暟 -//{ -// "namespace": "HDL", -// "command": "delete", -// "type": "scene", -// "objects": [{ -// "scene_id": "0001" -// }] -//} -//杩斿洖鍊� json鏍煎紡 -//杩斿洖渚嬪瓙 { -// "namespace": "HDL", -// "command": "delete_respond", -// "type": "scene", -// "scene_id": "0001", -// "value": "success" -//} -//璇存槑 鍒犻櫎鍦烘櫙 - -//5.1.18鍒犻櫎鍦烘櫙閲岀殑鐩爣 -//璇锋眰鍙傛暟 -//{ -// "Namespace": "HDL", -// "Command": "delete_member", -// "type": "scene", -// "number": [{ -// "scene_id": "0001", -// "objects": [{ -// "sid": "00010019101209000025670100010001" -// }, { -// "sid": "00010019101209000025670100010002" -// }] -// }] -//} -//杩斿洖鍊� json鏍煎紡 -//杩斿洖渚嬪瓙 { -// "namespace": "HDL", -// "command": "delete_member_respond", -// "type": "scene", -// "scenesid": "0001", -// "sid": "00010019101209000025670100010001", -// "value": "success" -//} -//璇存槑 鍒犻櫎鍦烘櫙鍐呰澶� - -//5.1.19閰嶇疆鍦烘櫙鍒嗙粍锛堣冻鍐呭満鏅姸鎬佽嚜鍔ㄨ褰曟渶鍚庝竴娆¤褰曪級 -//璇锋眰鍙傛暟 { -// "namespace": "HDL", -// "command": "group", -// "type": "scene", -// "objects": [{ -// "group_id": 1, -// "scene_ids": [{ -// "scene_id": "0001" -// }, { -// "scene_id": "0002" -// }] -// }] -//} -//杩斿洖鍊� json鏍煎紡 -//杩斿洖渚嬪瓙 { -// "namespace": "HDL", -// "command": "group_respond", -// "type": "scene", -// "group_id": "0001", -// "value": "success" -//} -//璇存槑 鎺у埗鍦烘櫙 - - -//5.1.20璇诲彇鍦烘櫙鍒嗙粍 -//璇锋眰鍙傛暟 -//{ -// "namespace": "HDL", -// "command": "read_group", -// "type": "scene", -// "objects": [{ -// "group_id": 1 -// }] -//} -//杩斿洖鍊� json鏍煎紡 -//杩斿洖渚嬪瓙 { -// "namespace": "HDL", -// "command": "read_group_respond", -// "type": "scene", -// "objects": [{ -// "group_id": 1, -// "scene_ids": [{ -// "scene_id": "0001" -// }, { -// "scene_id": "0002" -// }] -// }] -//} -//璇存槑 鎺у埗鍦烘櫙 - - -//5.1.21鎺у埗鍦烘櫙 -//璇锋眰鍙傛暟 -//{ -// "namespace": "HDL", -// "command": "contrl", -// "type": "scene", -// "objects": [{ -// "scene_id": "0001", -// "value": 鈥渙n鈥� -// }] -//} -//杩斿洖鍊� json鏍煎紡 -//杩斿洖渚嬪瓙 { -// "namespace": "HDL", -// "command": "contrl_respond", -// "type": "scene", -// "scene_id": "0001", -// "value": "success" -//} -//璇存槑 鎺у埗鍦烘櫙 \ No newline at end of file -- Gitblit v1.8.0