Refactor server initialization for service support

This commit is contained in:
John Gross
2017-08-24 17:30:38 -07:00
parent ddf465d8c9
commit c0be9c25da
9 changed files with 222 additions and 274 deletions

View File

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