2019-05-29 10:52:46 +02:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2019-05-29 10:52:46 +02:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-06-06 15:44:03 +02:00
|
|
|
|
using System;
|
2019-05-29 10:52:46 +02:00
|
|
|
|
using System.ServiceProcess;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Service
|
|
|
|
|
{
|
|
|
|
|
public class Service : ServiceBase
|
|
|
|
|
{
|
|
|
|
|
private CompositionRoot instances;
|
|
|
|
|
|
|
|
|
|
public Service()
|
|
|
|
|
{
|
|
|
|
|
CanPauseAndContinue = false;
|
2019-06-07 15:26:03 +02:00
|
|
|
|
ServiceName = nameof(SafeExamBrowser);
|
2019-05-29 10:52:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Main()
|
|
|
|
|
{
|
|
|
|
|
Run(new Service());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStart(string[] args)
|
|
|
|
|
{
|
2019-06-06 15:44:03 +02:00
|
|
|
|
instances = new CompositionRoot();
|
|
|
|
|
instances.BuildObjectGraph();
|
|
|
|
|
instances.LogStartupInformation();
|
2019-05-29 10:52:46 +02:00
|
|
|
|
|
2019-06-06 15:44:03 +02:00
|
|
|
|
var success = instances.ServiceController.TryStart();
|
2019-05-29 10:52:46 +02:00
|
|
|
|
|
2019-06-06 15:44:03 +02:00
|
|
|
|
if (!success)
|
|
|
|
|
{
|
|
|
|
|
Environment.Exit(-1);
|
|
|
|
|
}
|
2019-05-29 10:52:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStop()
|
|
|
|
|
{
|
2019-06-06 15:44:03 +02:00
|
|
|
|
instances?.ServiceController?.Terminate();
|
|
|
|
|
instances?.LogShutdownInformation();
|
2019-05-29 10:52:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|