ColoryrServer
September 14, 2022 · View on GitHub
Service代码编写
Service分为四种类型
Normal默认服务ErrorDump异常回调服务OnlyOpen单启动结束服务Builder编译回调服务
默认服务
using System;
using ColoryrServer.SDK;
//ColoryrServer_Debug
[ServiceIN(false, ServiceType.Normal)] //true表示跟随服务器启动
public class test
{
public ServiceNextState Run(object[] args, CancellationToken token)
{
return ServiceNextState.Stop;
}
public void OnStart()
{
}
public void OnStop()
{
}
}
类必须带有ColoryrServer.SDK.DLLIN的属性
且type=ServiceType.Normal
Run表示任务内容回调OnStart表示Service启动的回调OnStop表示Service关闭的回调
任务内容回调会有一个至少50ms的调用间隔
服务启动时会调用OnStart,之后会循环调用Run,关闭服务时会调用OnStop
默认服务有Init, Start, Ready, Going, Pause, Stop, Error, WaitArg状态
通过ServiceSDK来操作Service
Init表示服务正在初始化,完成后会转为StartStart表示服务正在调用OnStart,完成后会转为ReadyReady表示服务已初始化完成,且已启动,等待执行Going表示服务正在执行Pause表示服务正在暂停执行Stop表示服务正在调用OnStop,完成后会转为Init需要重新启动Error表示服务运行出错WaitArg等待运行参数设置后继续运行
异常回调服务
using System;
using ColoryrServer.SDK;
//ColoryrServer_Debug
[ServiceIN(type: ServiceType.ErrorDump)]
public class test
{
public bool OnError(Exception e)
{
return false; //true表示处理结束
}
}
异常回调服务没有状态
类必须带有ColoryrServer.SDK.DLLIN的属性
且type=ServiceType.ErrorDump
OnError表示服务器异常回调
返回true表示处理结束,不会继续传播事件
单启动结束服务
using System;
using ColoryrServer.SDK;
//ColoryrServer_Debug
[ServiceIN(false, ServiceType.OnlyOpen)] //true表示跟随服务器启动
public class test
{
public void OnStart()
{
}
public void OnStop()
{
}
}
单启动结束服务只有启动和关闭两种操作
编译回调服务
using System;
using ColoryrServer.SDK;
//ColoryrServer_Debug
[ServiceIN(type: ServiceType.Builder)] //true表示跟随服务器启动
public class test
{
public bool OnBuild(PerBuildArg arg)
{
return false; //true表示处理结束
}
public bool OnBuild(PostBuildArg arg)
{
return false;
}
}
OnBuild编译回调PerBuildArg编译前回调PostBuildArg编译后回调