Refactor server initialization for service support
This commit is contained in:
@@ -14,13 +14,15 @@ namespace Torch.Server
|
||||
{
|
||||
public const string Name = "Torch (SEDS)";
|
||||
private TorchServer _server;
|
||||
private static Logger _log = LogManager.GetLogger("Torch");
|
||||
private Initializer _initializer;
|
||||
|
||||
public TorchService()
|
||||
{
|
||||
ServiceName = Name;
|
||||
var workingDir = new FileInfo(typeof(TorchService).Assembly.Location).Directory.ToString();
|
||||
Directory.SetCurrentDirectory(workingDir);
|
||||
_initializer = new Initializer(workingDir);
|
||||
|
||||
CanHandlePowerEvent = true;
|
||||
ServiceName = Name;
|
||||
CanHandleSessionChangeEvent = false;
|
||||
CanPauseAndContinue = false;
|
||||
CanStop = true;
|
||||
@@ -31,17 +33,8 @@ namespace Torch.Server
|
||||
{
|
||||
base.OnStart(args);
|
||||
|
||||
string configName = args.Length > 0 ? args[0] : "Torch.cfg";
|
||||
var options = new TorchConfig("Torch");
|
||||
if (File.Exists(configName))
|
||||
options = TorchConfig.LoadFrom(configName);
|
||||
else
|
||||
options.Save(configName);
|
||||
|
||||
_server = new TorchServer(options);
|
||||
_server.Init();
|
||||
_server.RunArgs = args;
|
||||
Task.Run(() => _server.Start());
|
||||
_initializer.Initialize(args);
|
||||
_initializer.Run();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -50,17 +43,5 @@ namespace Torch.Server
|
||||
_server.Stop();
|
||||
base.OnStop();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnShutdown()
|
||||
{
|
||||
base.OnShutdown();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
|
||||
{
|
||||
return base.OnPowerEvent(powerStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user