forked from siteserver/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram2.cs
More file actions
135 lines (115 loc) · 4.28 KB
/
Program2.cs
File metadata and controls
135 lines (115 loc) · 4.28 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using CommandLine;
using SiteServer.CMS.Core;
namespace siteserver
{
internal class Program
{
private static CommandRun _commandRun;
private static void Main(string[] args)
{
if (!EnvironmentManager.IsSiteServerDir)
{
Console.Write("当前文件夹不是正确的SiteServer系统根目录");
Console.ReadLine();
}
else if (!EnvironmentManager.IsInitialized)
{
Console.Write("SiteServer系统未安装或数据库无法正确连接");
Console.ReadLine();
}
var invokedVerb = string.Empty;
object invokedVerbInstance = null;
if (args.Length == 0)
{
invokedVerb = "run";
}
else
{
var options = new Options();
if (!Parser.Default.ParseArguments(args, options,
(verb, subOptions) =>
{
invokedVerb = verb;
invokedVerbInstance = subOptions;
}))
{
Console.WriteLine(options.GetUsage());
return;
}
}
if (invokedVerb == "build")
{
var commitSubOptions = (BuildSubOptions)invokedVerbInstance;
var isAll = commitSubOptions != null && commitSubOptions.All;
Console.WriteLine(isAll);
Console.WriteLine("build site...");
}
else if (invokedVerb == "test")
{
var i = 0;
while (true)
{
Console.WriteLine("Application thread ID: {0}, I:{1}",
Thread.CurrentThread.ManagedThreadId, i++);
var t = Task.Run(() => {
Console.WriteLine("Task thread ID: {0}",
Thread.CurrentThread.ManagedThreadId);
});
t.Wait();
Thread.Sleep(5000);
}
}
else if (invokedVerb == "run")
{
// Some biolerplate to react to close window event, CTRL-C, kill, etc
_handler += Handler;
SetConsoleCtrlHandler(_handler, true);
Console.WriteLine("SiteServer Service is running...");
//Console.CancelKeyPress += CurrentDomain_ProcessExit;
_commandRun = new CommandRun();
_commandRun.StartService();
//var manager = new ExecutionManager();
//while (!_exitSystem)
//{
// ServiceManager.SetServiceOnline(true);
// manager.ExecutePendingCreate();
// manager.ExecuteTask();
// Thread.Sleep(1000);
//}
}
}
//protected static void CurrentDomain_ProcessExit(object sender, ConsoleCancelEventArgs args)
//{
// Console.WriteLine("CurrentDomain_ProcessExit");
// Thread.Sleep(750);
// if (args.SpecialKey == ConsoleSpecialKey.ControlC)
// {
// ServiceManager.SetServiceOnline(false);
// Console.WriteLine("Shutting down...");
// Thread.Sleep(750);
// }
//}
//private static bool _exitSystem;
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);
private delegate bool EventHandler(CtrlType sig);
private static EventHandler _handler;
private enum CtrlType{ }
private static bool Handler(CtrlType sig)
{
//do your cleanup here
ServiceManager.SetServiceOnline(false);
Console.WriteLine("SiteServer Service is shutting down...");
//allow main to run off
//_exitSystem = true;
_commandRun?.EndService();
//shutdown right away so there are no lingering threads
Environment.Exit(-1);
return true;
}
}
}