forked from DigitalRuby/IPBan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPBanServiceRunner.cs
79 lines (71 loc) · 2.09 KB
/
IPBanServiceRunner.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#region Imports
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Diagnostics.Eventing.Reader;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Management;
using System.Net;
using System.Security.Permissions;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Web.Script.Serialization;
using System.Xml;
using System.Text.RegularExpressions;
#endregion Imports
namespace IPBan
{
public class IPBanServiceRunner : ServiceBase
{
private static IPBanServiceRunner runner = new IPBanServiceRunner();
private static IPBanService service = new IPBanService();
protected override void OnStart(string[] args)
{
base.OnStart(args);
service.Start();
}
protected override void OnStop()
{
base.OnStop();
service.Stop();
}
public int RunService(string[] args)
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { this };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
return 0;
}
public int RunConsole(string[] args)
{
if (args.Contains("test", StringComparer.OrdinalIgnoreCase))
{
service.RunTestsOnStart = true;
}
service.Start();
Console.WriteLine("Press ENTER to quit");
Console.ReadLine();
service.Stop();
return 0;
}
public static int Main(string[] args)
{
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
runner = new IPBanServiceRunner();
if (args.Length != 0 && args[0] == "debug")
{
return runner.RunConsole(args);
}
else
{
return runner.RunService(args);
}
}
}
}