-
Notifications
You must be signed in to change notification settings - Fork 5
/
Program.cs
76 lines (69 loc) · 2.56 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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using CommandLine;
using MemcachedService64.Service;
using NLog;
namespace MemcachedService64
{
static class Program
{
private static Logger _logger;
/// <summary>
/// Point d'entrée.
/// </summary>
static void Main(string[] args)
{
_logger = LogManager.GetLogger("Program");
if (!Environment.UserInteractive)
{
#region Considère un contexte de service
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service.MemcachedService()
};
ServiceBase.Run(ServicesToRun);
#endregion
}
else
{
#region Considère un contexte utilisateur (interactif)
_logger.Trace("Mode interactif");
int exitCode = 0;
try
{
#region Parse la ligne de commande
Options options = new Options();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(false, true, Console.Error));
bool parserSucceed = parser.ParseArguments(args, options);
#endregion
if (options.Install || options.Uninstall)
{
if (!parserSucceed)
throw new ArgumentException("Ligne de commande invalide.");
Service.MemcachedServiceInstaller.Install(options.Uninstall, args);
return;
}
using (var service = new Service.MemcachedService())
{
service.SetUp(!parserSucceed ? args.Length != 0 ? args : AppSettings.GetMemcachedArguments() : AppSettings.GetMemcachedArguments());
_logger.Info("Service démarré. Appuyez sur ECHAP pour mettre fin au service...");
while (!NativeMethods.PeekEscapeKey()) { }
_logger.Info("[ESC]");
service.TearDown();
}
}
catch (Exception ex)
{
_logger.Fatal(ex.ToString());
exitCode = -1;
}
Environment.Exit(exitCode);
#endregion
}
}
}
}