You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OMS.NET/Instructs/TextMessageInstruct.cs

45 lines
1.6 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Text.Json;
namespace OMS.NET.Instructs
{
public class TextMessageInstruct : Instruct
{
public TextMessageInstruct()
{
Type = "broadcast";
Class = "textMessage";
}
public override Task Handler(string wsid)
{
return Task.Run(() =>
{
if (!GlobalArea.LoginCheckByID(wsid)) return;//登录检查不通过则直接退出
if (Data?.GetType() != typeof(JsonElement)) return;//Data 非空和JsonElement类型检查
try
{
string message = Data.GetProperty("message").GetString();
string conveyor = GlobalArea.GetLoginEmailByID(wsid);
string time = GlobalArea.GetCurrentTime();
GlobalArea.Log.Info($"[{time}] {conveyor}:{message}");
ResponseOrBroadcastInstructs.Add(new TextMessageInstruct()
{
IsBroadcast = true,
Conveyor = conveyor,
Time = time,
Data = new
{
message,
headColor = Data.GetProperty("headColor").GetString(),
name = Data.GetProperty("name").GetString()
}
});
}
catch (Exception ex)
{
GlobalArea.Log.Warn("处理textMessage发生问题" + ex.Message);
}
});
}
}
}