接受代码简化建议,移除this.

dev
nxiaoxiao 1 year ago
parent 0d7cc2df5f
commit f4006f8c7d

@ -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
};
}
}

@ -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);

@ -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

@ -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

@ -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)
{

@ -66,7 +66,7 @@ namespace OMS.NET.Instructs
{
IsBroadcast = true,
Type = "broadcast",
Class = this.Class,
Class = Class,
Conveyor = conveyor,
Time = time,
Data = mapData,

@ -6,7 +6,7 @@ namespace OMS.NET.Instructs
{
public DeleteElementInstruct()
{
this.Class = "deleteElement";
Class = "deleteElement";
}
public override Task Handler(string wsid)

@ -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",

@ -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<MapData> mapDatas = MapData.GetMapDataList().Where(m => m.Phase != 2).ToList();
this.ResponseOrBroadcastInstructs.Add(new Instruct()
ResponseOrBroadcastInstructs.Add(new Instruct()
{
IsResponse = true,
Type = "send_mapData",

@ -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<MapLayer> mapLayers = MapLayer.GetMapLayerList().Where(m => m.Phase != 2).ToList();
this.ResponseOrBroadcastInstructs.Add(new Instruct()
ResponseOrBroadcastInstructs.Add(new Instruct()
{
IsResponse = true,
Type = "send_mapLayer",

@ -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",

@ -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",

@ -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",

@ -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);
}
}
});

@ -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",

@ -142,7 +142,7 @@ namespace OMS.NET.Instructs
public Instruct()
{
this.Type = "";
Type = "";
}
/// <summary>
@ -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()

@ -42,7 +42,7 @@ namespace OMS.NET.Instructs
}
catch (Exception ex)
{
GlobalArea.Log.Warn($"处理{this.Class}广播指令出错:" + ex.Message);
GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message);
}
});
}

@ -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);
}
});
}

@ -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"

@ -42,7 +42,7 @@ namespace OMS.NET.Instructs
}
catch (Exception ex)
{
GlobalArea.Log.Warn($"处理{this.Class}广播指令出错:" + ex.Message);
GlobalArea.Log.Warn($"处理{Class}广播指令出错:" + ex.Message);
}
});
}

@ -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);
}
});
}

@ -7,7 +7,7 @@ namespace OMS.NET.Instructs
{
public TestInstruct()
{
this.Type = "test";
Type = "test";
}
public override Task Handler(string wsid)

@ -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)

@ -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}");
}
}

Loading…
Cancel
Save