2024-09-30 17:10:43 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using TouchSocket.Core;
|
|
|
|
|
|
using TouchSocket.Sockets;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Core.Services
|
|
|
|
|
|
{
|
2024-10-22 20:57:26 +08:00
|
|
|
|
public partial class BusService : PluginBase
|
2024-09-30 17:10:43 +08:00
|
|
|
|
{
|
2024-10-22 20:57:26 +08:00
|
|
|
|
[GeneratorPlugin(typeof(IServerStartedPlugin))]
|
2024-09-30 17:10:43 +08:00
|
|
|
|
public Task OnServerStarted(IServiceBase sender, ServiceStateEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (sender)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ITcpService service:
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in service.Monitors)
|
|
|
|
|
|
{
|
|
|
|
|
|
ConsoleLogger.Default.Info($"TCP {item.Option.IpHost}");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
case UdpSession session:
|
|
|
|
|
|
ConsoleLogger.Default.Info($"UDP {session.Monitor.IPHost}");
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ConsoleLogger.Default.Info(e.ServerState == ServerState.Running
|
|
|
|
|
|
? $"服务器成功启动"
|
|
|
|
|
|
: $"服务器启动失败,状态:{e.ServerState},异常:{e.Exception}");
|
|
|
|
|
|
return e.InvokeNext();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-22 20:57:26 +08:00
|
|
|
|
[GeneratorPlugin(typeof(IServerStopedPlugin))]
|
2024-09-30 17:10:43 +08:00
|
|
|
|
public Task OnServerStoped(IServiceBase sender, ServiceStateEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("服务已停止");
|
|
|
|
|
|
return e.InvokeNext();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|