-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
49 lines (45 loc) · 1.87 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Runtime.InteropServices;
using SelloutReportingService.Services;
using Topshelf;
using Topshelf.Runtime.DotNetCore;
namespace SelloutReportingService
{
public static class Program
{
public static int Main()
{
return (int) HostFactory.Run(c =>
{
// Change Topshelf's environment builder on non-Windows hosts to use DotNetCoreEnvironmentBuilder.
// It defaults to WindowsHostEnvironmentBuilder, but that throws some errors when not running on Windows.
if (
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ||
RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
)
c.UseEnvironmentBuilder(hostConfigurator =>
new DotNetCoreEnvironmentBuilder(hostConfigurator));
c.SetServiceName("SelloutReportingService");
c.SetDisplayName("Sellout Reporting Service");
c.SetDescription("A Windows service that generates and sends custom reports.");
c.StartAutomatically();
c.RunAsNetworkService();
c.EnableServiceRecovery(
a => a.RestartService(TimeSpan.FromSeconds(60))
);
c.Service<ReportingServiceControl>(serviceConfigurator =>
{
// Custom service construction.
serviceConfigurator.ConstructUsing(
() => new ReportingServiceControl());
serviceConfigurator.WhenStarted(
(service, control) => service.Start(control)
);
serviceConfigurator.WhenStopped(
(service, control) => service.Stop(control)
);
});
});
}
}
}