| | |
| | | /// </summary> |
| | | public List<string> roomIds = new List<string>(); |
| | | /// <summary> |
| | | /// 所属房间列表 |
| | | /// </summary> |
| | | public List<string> uids = new List<string>(); |
| | | /// <summary> |
| | | /// 延时 |
| | | /// </summary> |
| | | public int delay = 0; |
| | |
| | | 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); |
| | |
| | | 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> |
| | | /// 保存功能数据 |
| | | /// </summary> |
| | | public void SaveSceneData() |
| | | public void SaveSceneData(bool upServer) |
| | | { |
| | | if (upServer) |
| | | { |
| | | UploadScene(); |
| | | } |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | FileUtils.WriteFileByBytes(savePath, ssd); |
| | | MainPage.Log($"Save Scene Data : {savePath}"); |
| | | UploadScene(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | ResponsePackNew revPack; |
| | | if (DeleteSign) |
| | | if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime)) |
| | | { |
| | | var resCode = pm.DeleteScene(userSceneId); |
| | | } |
| | | else |
| | | { |
| | | if (string.IsNullOrEmpty(createTime) && string.IsNullOrEmpty(modifyTime)) |
| | | revPack = pm.AddScene(this); |
| | | if (revPack.Code == StateCode.SUCCESS) |
| | | { |
| | | revPack = pm.AddScene(this); |
| | | if (revPack.Code == StateCode.SUCCESS) |
| | | { |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | FileUtils.WriteFileByBytes(savePath, ssd); |
| | | } |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); |
| | | FileUtils.WriteFileByBytes(savePath, ssd); |
| | | } |
| | | else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime)) |
| | | } |
| | | else if (!string.IsNullOrEmpty(createTime) && !string.IsNullOrEmpty(modifyTime)) |
| | | { |
| | | revPack = pm.EditScene(this); |
| | | if (revPack.Code == StateCode.SUCCESS) |
| | | { |
| | | 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 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)); |
| | | FileUtils.WriteFileByBytes(savePath, ssd); |
| | | } |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene)); |
| | | FileUtils.WriteFileByBytes(savePath, ssd); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除标记 |
| | | /// 需要删除数据时,标记为:true |
| | | /// 由云端删除成功之后,返回数据再清除本地数据 |
| | | /// </summary> |
| | | public bool DeleteSign = false; |
| | | |
| | | /// <summary> |
| | | /// 云端数据创建的时间 |