From f4006f8c7d9650cd4ea4f508bc72bef0d5645899 Mon Sep 17 00:00:00 2001 From: nxiaoxiao <3247747442@qq.com> Date: Sun, 18 Aug 2024 10:52:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=97=E4=BB=A3=E7=A0=81=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E5=BB=BA=E8=AE=AE=EF=BC=8C=E7=A7=BB=E9=99=A4this.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/LayerData.cs | 20 ++++++++++---------- Common/Logger.cs | 10 +++++----- DbClass/AccountData.cs | 10 +++++----- DbClass/MapData.cs | 10 +++++----- DbClass/MapLayer.cs | 10 +++++----- Instructs/AddElementInstruct.cs | 2 +- Instructs/DeleteElementInstuct.cs | 2 +- Instructs/GetActiveDataInstruct.cs | 4 ++-- Instructs/GetMapDataInstruct.cs | 4 ++-- Instructs/GetMapLayerInstruct.cs | 4 ++-- Instructs/GetPresenceInstruct.cs | 4 ++-- Instructs/GetPublickeyInstruct.cs | 4 ++-- Instructs/GetServerConfigInstruct.cs | 4 ++-- Instructs/GetServerImgInstruct.cs | 8 ++++---- Instructs/GetUserDataInstruct.cs | 4 ++-- Instructs/Instruct.cs | 4 ++-- Instructs/PickEndElementInstruct.cs | 2 +- Instructs/PickIngElementInstruct.cs | 6 +++--- Instructs/PingInstuct.cs | 4 ++-- Instructs/SelectEndElementInstruct.cs | 2 +- Instructs/SelectIngElementInstruct.cs | 6 +++--- Instructs/TestInstuct.cs | 2 +- Instructs/TextMessageInstruct.cs | 4 ++-- MapServer.cs | 20 ++++++++++---------- 24 files changed, 75 insertions(+), 75 deletions(-) diff --git a/Common/LayerData.cs b/Common/LayerData.cs index 1557348..5d6e93b 100644 --- a/Common/LayerData.cs +++ b/Common/LayerData.cs @@ -32,16 +32,16 @@ namespace OMS.NET.Common public void AppendElement(long itemId, string ItemType) { - if (this.Type == "order") + if (Type == "order") { GlobalArea.Log.Error($"order图层不能添加{ItemType}元素"); return; } - if (this.Members![itemId.ToString()] == null) + if (Members![itemId.ToString()] == null) { - this.Members![itemId.ToString()] = ItemType; - this.Structure!.AsArray().Add(itemId); - this.HasChange = true; + Members![itemId.ToString()] = ItemType; + Structure!.AsArray().Add(itemId); + HasChange = true; //上传图层到数据库 MapLayer mapLayer = ConvertToMapLayer(); MapLayer.Update(mapLayer); @@ -52,11 +52,11 @@ namespace OMS.NET.Common { return new MapLayer() { - Id = this.LayerId, - Type = this.Type, - Members = (this.Type == "order") ? this.Members!.ToString() : Util.JsonToBase64(this.Members!.ToString()), - Structure = (this.Structure == null) ? "" : Util.JsonToBase64(this.Structure!.ToString()), - Phase = this.Phase + Id = LayerId, + Type = Type, + Members = (Type == "order") ? Members!.ToString() : Util.JsonToBase64(Members!.ToString()), + Structure = (Structure == null) ? "" : Util.JsonToBase64(Structure!.ToString()), + Phase = Phase }; } } diff --git a/Common/Logger.cs b/Common/Logger.cs index 65bcd7f..80e1795 100644 --- a/Common/Logger.cs +++ b/Common/Logger.cs @@ -11,7 +11,7 @@ namespace OMS.NET.Common { lock (LogLock) { - using var writer = new StreamWriter(this.logPath, true); + using var writer = new StreamWriter(logPath, true); writer.WriteLine(message); } } @@ -19,12 +19,12 @@ namespace OMS.NET.Common public Logger(int level) { _logLevel = level; - this.logPath = GetNewLogFile(); + logPath = GetNewLogFile(); } private string GetNewLogFile() { - this.logCount = 0; + logCount = 0; string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log", $"{DateTime.Now:yyyy-MM-dd-HH-mm-ss}.log"); if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log"))) { @@ -36,7 +36,7 @@ namespace OMS.NET.Common private void Log(string message, int level) { - if (level <= this._logLevel) + if (level <= _logLevel) { string logtime = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss]"); string leveltext = level switch @@ -51,7 +51,7 @@ namespace OMS.NET.Common Console.WriteLine(logtext); if (logCount > 100000) { - this.logPath = GetNewLogFile(); + logPath = GetNewLogFile(); } //File.AppendAllTextAsync(this.logPath, logtext); WriteLog(logtext); diff --git a/DbClass/AccountData.cs b/DbClass/AccountData.cs index 1bb5293..e612220 100644 --- a/DbClass/AccountData.cs +++ b/DbClass/AccountData.cs @@ -19,11 +19,11 @@ namespace OMS.NET.DbClass public AccountData() { - this.UserEmail = ""; - this.UserName = ""; - this.Password = ""; - this.Mode = 1; - this.Phase = 1; + UserEmail = ""; + UserName = ""; + Password = ""; + Mode = 1; + Phase = 1; //this.Custom = ""; } #endregion diff --git a/DbClass/MapData.cs b/DbClass/MapData.cs index 244674c..eccefaa 100644 --- a/DbClass/MapData.cs +++ b/DbClass/MapData.cs @@ -21,11 +21,11 @@ namespace OMS.NET.DbClass public MapData() { - this.Id = -1; - this.Type = ""; - this.Points = ""; - this.Point = ""; - this.Phase = 1; + Id = -1; + Type = ""; + Points = ""; + Point = ""; + Phase = 1; } #endregion diff --git a/DbClass/MapLayer.cs b/DbClass/MapLayer.cs index f3f810a..43abd5b 100644 --- a/DbClass/MapLayer.cs +++ b/DbClass/MapLayer.cs @@ -13,11 +13,11 @@ namespace OMS.NET.DbClass public MapLayer() { - this.Id = 0; - this.Type = ""; - this.Members = ""; - this.Structure = ""; - this.Phase = 1; + Id = 0; + Type = ""; + Members = ""; + Structure = ""; + Phase = 1; } public MapLayer(long id, string type, string members, string structure, int phase) { diff --git a/Instructs/AddElementInstruct.cs b/Instructs/AddElementInstruct.cs index 7601f93..0daaae0 100644 --- a/Instructs/AddElementInstruct.cs +++ b/Instructs/AddElementInstruct.cs @@ -66,7 +66,7 @@ namespace OMS.NET.Instructs { IsBroadcast = true, Type = "broadcast", - Class = this.Class, + Class = Class, Conveyor = conveyor, Time = time, Data = mapData, diff --git a/Instructs/DeleteElementInstuct.cs b/Instructs/DeleteElementInstuct.cs index 9c62936..6ad2cf6 100644 --- a/Instructs/DeleteElementInstuct.cs +++ b/Instructs/DeleteElementInstuct.cs @@ -6,7 +6,7 @@ namespace OMS.NET.Instructs { public DeleteElementInstruct() { - this.Class = "deleteElement"; + Class = "deleteElement"; } public override Task Handler(string wsid) diff --git a/Instructs/GetActiveDataInstruct.cs b/Instructs/GetActiveDataInstruct.cs index bd2b07d..dbc8699 100644 --- a/Instructs/GetActiveDataInstruct.cs +++ b/Instructs/GetActiveDataInstruct.cs @@ -4,7 +4,7 @@ namespace OMS.NET.Instructs { public GetActiveDataInstruct() { - this.Type = "get_activeData"; + Type = "get_activeData"; } public override Task Handler(string wsid) @@ -12,7 +12,7 @@ namespace OMS.NET.Instructs return Task.Run(() => { if (!GlobalArea.LoginCheckByID(wsid)) return;//登录检查,不通过则直接退出 - this.ResponseOrBroadcastInstructs.Add(new Instruct() + ResponseOrBroadcastInstructs.Add(new Instruct() { IsResponse = true, Type = "send_activeData", diff --git a/Instructs/GetMapDataInstruct.cs b/Instructs/GetMapDataInstruct.cs index f81fd0e..d689468 100644 --- a/Instructs/GetMapDataInstruct.cs +++ b/Instructs/GetMapDataInstruct.cs @@ -6,7 +6,7 @@ namespace OMS.NET.Instructs { public GetMapDataInstruct() { - this.Type = "get_mapData"; + Type = "get_mapData"; } public override Task Handler(string wsid) @@ -15,7 +15,7 @@ namespace OMS.NET.Instructs { if (!GlobalArea.LoginCheckByID(wsid)) return;//登录检查,不通过则直接退出 List mapDatas = MapData.GetMapDataList().Where(m => m.Phase != 2).ToList(); - this.ResponseOrBroadcastInstructs.Add(new Instruct() + ResponseOrBroadcastInstructs.Add(new Instruct() { IsResponse = true, Type = "send_mapData", diff --git a/Instructs/GetMapLayerInstruct.cs b/Instructs/GetMapLayerInstruct.cs index 67ccddb..c5bd5d6 100644 --- a/Instructs/GetMapLayerInstruct.cs +++ b/Instructs/GetMapLayerInstruct.cs @@ -6,7 +6,7 @@ namespace OMS.NET.Instructs { public GetMapLayerInstruct() { - this.Type = "get_mapLayer"; + Type = "get_mapLayer"; } public override Task Handler(string wsid) @@ -15,7 +15,7 @@ namespace OMS.NET.Instructs { if (!GlobalArea.LoginCheckByID(wsid)) return;//登录检查,不通过则直接退出 List mapLayers = MapLayer.GetMapLayerList().Where(m => m.Phase != 2).ToList(); - this.ResponseOrBroadcastInstructs.Add(new Instruct() + ResponseOrBroadcastInstructs.Add(new Instruct() { IsResponse = true, Type = "send_mapLayer", diff --git a/Instructs/GetPresenceInstruct.cs b/Instructs/GetPresenceInstruct.cs index 6786216..5bec3ed 100644 --- a/Instructs/GetPresenceInstruct.cs +++ b/Instructs/GetPresenceInstruct.cs @@ -6,7 +6,7 @@ namespace OMS.NET.Instructs { public GetPresenceInstruct() { - this.Type = "get_presence"; + Type = "get_presence"; } public override Task Handler(string wsid) @@ -30,7 +30,7 @@ namespace OMS.NET.Instructs headColor = accountData.HeadColor, }); }); - this.ResponseOrBroadcastInstructs.Add(new Instruct() + ResponseOrBroadcastInstructs.Add(new Instruct() { IsResponse = true, Type = "send_presence", diff --git a/Instructs/GetPublickeyInstruct.cs b/Instructs/GetPublickeyInstruct.cs index c04899c..9d9c86c 100644 --- a/Instructs/GetPublickeyInstruct.cs +++ b/Instructs/GetPublickeyInstruct.cs @@ -4,14 +4,14 @@ namespace OMS.NET.Instructs { public GetPublickeyInstruct() { - this.Type = "get_publickey"; + Type = "get_publickey"; } public override Task Handler(string wsid) { return Task.Run(() => { - this.ResponseOrBroadcastInstructs.Add(new Instruct() + ResponseOrBroadcastInstructs.Add(new Instruct() { IsResponse = true, Type = "publickey", diff --git a/Instructs/GetServerConfigInstruct.cs b/Instructs/GetServerConfigInstruct.cs index dfdcc7b..b314998 100644 --- a/Instructs/GetServerConfigInstruct.cs +++ b/Instructs/GetServerConfigInstruct.cs @@ -4,14 +4,14 @@ namespace OMS.NET.Instructs { public GetServerConfigInstruct() { - this.Type = "get_serverConfig"; + Type = "get_serverConfig"; } public override Task Handler(string wsid) { return Task.Run(() => { - this.ResponseOrBroadcastInstructs.Add(new Instruct() + ResponseOrBroadcastInstructs.Add(new Instruct() { IsResponse = true, Type = "send_serverConfig", diff --git a/Instructs/GetServerImgInstruct.cs b/Instructs/GetServerImgInstruct.cs index 0f9f3d5..3ff0566 100644 --- a/Instructs/GetServerImgInstruct.cs +++ b/Instructs/GetServerImgInstruct.cs @@ -7,18 +7,18 @@ namespace OMS.NET.Instructs { public GetServerImgInstruct() { - this.Type = "get_serverImg"; + Type = "get_serverImg"; } public override Task Handler(string wsid) { return Task.Run(() => { - if (this.Time != null) + if (Time != null) { //时间解析 string format = "yyyy-MM-dd HH:mm:ss"; - DateTime clientDateTime = DateTime.ParseExact(this.Time, format, CultureInfo.InvariantCulture); + DateTime clientDateTime = DateTime.ParseExact(Time, format, CultureInfo.InvariantCulture); //Console.WriteLine("Converted DateTime: " + clientDateTime); string serverImgPath = GlobalArea.ServerConfig.Img; if (File.Exists(serverImgPath)) @@ -48,7 +48,7 @@ namespace OMS.NET.Instructs @string = "" }; } - this.ResponseOrBroadcastInstructs.Add(res); + ResponseOrBroadcastInstructs.Add(res); } } }); diff --git a/Instructs/GetUserDataInstruct.cs b/Instructs/GetUserDataInstruct.cs index a40a266..89f5412 100644 --- a/Instructs/GetUserDataInstruct.cs +++ b/Instructs/GetUserDataInstruct.cs @@ -6,7 +6,7 @@ namespace OMS.NET.Instructs { public GetUserDataInstruct() { - this.Type = "get_userData"; + Type = "get_userData"; } public override Task Handler(string wsid) @@ -16,7 +16,7 @@ namespace OMS.NET.Instructs if (!GlobalArea.LoginCheckByID(wsid)) return;//登录检查,不通过则直接退出 string userEmail = GlobalArea.UserConnects.First(u => u.ID == wsid).UserEmail!; AccountData accountData = GlobalArea.GetLoginAccountData(userEmail)!; - this.ResponseOrBroadcastInstructs.Add(new Instruct() + ResponseOrBroadcastInstructs.Add(new Instruct() { IsResponse = true, Type = "send_userData", diff --git a/Instructs/Instruct.cs b/Instructs/Instruct.cs index 5f6122c..3582c7c 100644 --- a/Instructs/Instruct.cs +++ b/Instructs/Instruct.cs @@ -142,7 +142,7 @@ namespace OMS.NET.Instructs public Instruct() { - this.Type = ""; + Type = ""; } /// @@ -160,7 +160,7 @@ namespace OMS.NET.Instructs stopWatch.Start(); await Handler(wsid); stopWatch.Stop(); - GlobalArea.Log.Debug($"处理{this.GetType()}耗时:{stopWatch.ElapsedMilliseconds}ms"); + GlobalArea.Log.Debug($"处理{GetType()}耗时:{stopWatch.ElapsedMilliseconds}ms"); } public string ToJsonString() diff --git a/Instructs/PickEndElementInstruct.cs b/Instructs/PickEndElementInstruct.cs index 06f2933..2947a45 100644 --- a/Instructs/PickEndElementInstruct.cs +++ b/Instructs/PickEndElementInstruct.cs @@ -42,7 +42,7 @@ namespace OMS.NET.Instructs } catch (Exception ex) { - GlobalArea.Log.Warn($"处理{this.Class}广播指令出错:" + ex.Message); + GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message); } }); } diff --git a/Instructs/PickIngElementInstruct.cs b/Instructs/PickIngElementInstruct.cs index 7e9a33a..02f2ffe 100644 --- a/Instructs/PickIngElementInstruct.cs +++ b/Instructs/PickIngElementInstruct.cs @@ -8,8 +8,8 @@ namespace OMS.NET.Instructs { public PickIngElementInstruct() { - this.Type = "broadcast"; - this.Class = "pickIngElement"; + Type = "broadcast"; + Class = "pickIngElement"; } public override Task Handler(string wsid) @@ -63,7 +63,7 @@ namespace OMS.NET.Instructs } catch (Exception ex) { - GlobalArea.Log.Warn($"处理{this.Class}广播指令出错:" + ex.Message); + GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message); } }); } diff --git a/Instructs/PingInstuct.cs b/Instructs/PingInstuct.cs index c8796e7..055feb0 100644 --- a/Instructs/PingInstuct.cs +++ b/Instructs/PingInstuct.cs @@ -4,14 +4,14 @@ namespace OMS.NET.Instructs { public PingInstuct() { - this.Type = "ping"; + Type = "ping"; } public override Task Handler(string wsid) { return Task.Run(() => { - this.ResponseOrBroadcastInstructs.Add(new Instruct() + ResponseOrBroadcastInstructs.Add(new Instruct() { IsResponse = true, Type = "pong" diff --git a/Instructs/SelectEndElementInstruct.cs b/Instructs/SelectEndElementInstruct.cs index 5e363cb..51eab5d 100644 --- a/Instructs/SelectEndElementInstruct.cs +++ b/Instructs/SelectEndElementInstruct.cs @@ -42,7 +42,7 @@ namespace OMS.NET.Instructs } catch (Exception ex) { - GlobalArea.Log.Warn($"处理{this.Class}广播指令出错:" + ex.Message); + GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message); } }); } diff --git a/Instructs/SelectIngElementInstruct.cs b/Instructs/SelectIngElementInstruct.cs index 8db3278..d1de9b4 100644 --- a/Instructs/SelectIngElementInstruct.cs +++ b/Instructs/SelectIngElementInstruct.cs @@ -8,8 +8,8 @@ namespace OMS.NET.Instructs { public SelectIngElementInstruct() { - this.Type = "broadcast"; - this.Class = "selectIngElement"; + Type = "broadcast"; + Class = "selectIngElement"; } public override Task Handler(string wsid) @@ -63,7 +63,7 @@ namespace OMS.NET.Instructs } catch (Exception ex) { - GlobalArea.Log.Warn($"处理{this.Class}广播指令出错:" + ex.Message); + GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message); } }); } diff --git a/Instructs/TestInstuct.cs b/Instructs/TestInstuct.cs index 90b4821..76b0990 100644 --- a/Instructs/TestInstuct.cs +++ b/Instructs/TestInstuct.cs @@ -7,7 +7,7 @@ namespace OMS.NET.Instructs { public TestInstruct() { - this.Type = "test"; + Type = "test"; } public override Task Handler(string wsid) diff --git a/Instructs/TextMessageInstruct.cs b/Instructs/TextMessageInstruct.cs index dd3a8ca..6bcfbb4 100644 --- a/Instructs/TextMessageInstruct.cs +++ b/Instructs/TextMessageInstruct.cs @@ -6,8 +6,8 @@ namespace OMS.NET.Instructs { public TextMessageInstruct() { - this.Type = "broadcast"; - this.Class = "textMessage"; + Type = "broadcast"; + Class = "textMessage"; } public override Task Handler(string wsid) diff --git a/MapServer.cs b/MapServer.cs index dac8d62..a2420af 100644 --- a/MapServer.cs +++ b/MapServer.cs @@ -12,11 +12,11 @@ namespace OMS.NET private IPEndPoint iPEndPoint = new(IPAddress.Any, 0); protected override async void OnMessage(MessageEventArgs e) { - GlobalArea.Log.Debug(this.ID + " " + this.Context.UserEndPoint.ToString() + ":" + e.Data); + GlobalArea.Log.Debug(ID + " " + Context.UserEndPoint.ToString() + ":" + e.Data); Instruct? instruct = Instruct.JsonStringParse(e.Data); if (instruct != null) { - await instruct.HandlerAndMeasure(this.ID);//传递ws连接的id,为某些需要判断ws连接状态的处理逻辑准备 + await instruct.HandlerAndMeasure(ID);//传递ws连接的id,为某些需要判断ws连接状态的处理逻辑准备 if (instruct.ResponseOrBroadcastInstructs.Count > 0) { instruct.ResponseOrBroadcastInstructs.ForEach(res => @@ -30,7 +30,7 @@ namespace OMS.NET if (res.IsBroadcast) { string str = res.ToJsonString(); - foreach (IWebSocketSession session in this.Sessions.Sessions) + foreach (IWebSocketSession session in Sessions.Sessions) { //看起来只有登录后的连接才能收到广播,这里添加下过滤 if (GlobalArea.LoginCheckByID(session.ID)) @@ -47,23 +47,23 @@ namespace OMS.NET protected override void OnOpen() { - this.iPEndPoint = this.Context.UserEndPoint; - GlobalArea.AddUserConnect(this.ID, this.iPEndPoint); - Console.WriteLine(this.ID + " " + this.iPEndPoint.ToString() + " Conection Open"); + iPEndPoint = Context.UserEndPoint; + GlobalArea.AddUserConnect(ID, iPEndPoint); + Console.WriteLine(ID + " " + iPEndPoint.ToString() + " Conection Open"); Console.WriteLine($"当前连接客户端数量: {GlobalArea.ConnectClientsCount}"); } protected override void OnClose(CloseEventArgs e) { - GlobalArea.RemoveUserConnectByID(this.ID); - Console.WriteLine(this.ID + " " + this.iPEndPoint.ToString() + " Conection Close" + e.Reason); + GlobalArea.RemoveUserConnectByID(ID); + Console.WriteLine(ID + " " + iPEndPoint.ToString() + " Conection Close" + e.Reason); Console.WriteLine($"当前连接客户端数量: {GlobalArea.ConnectClientsCount}"); } protected override void OnError(ErrorEventArgs e) { - GlobalArea.RemoveUserConnectByID(this.ID); - Console.WriteLine(this.ID + " " + this.iPEndPoint.ToString() + " Conection Error Close" + e.Message); + GlobalArea.RemoveUserConnectByID(ID); + Console.WriteLine(ID + " " + iPEndPoint.ToString() + " Conection Error Close" + e.Message); Console.WriteLine($"当前连接客户端数量: {GlobalArea.ConnectClientsCount}"); } }