-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathQuartzServer.cs
158 lines (140 loc) · 3.71 KB
/
QuartzServer.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using Autofac;
using BusinessObjects;
using log4net;
using Microsoft.Extensions.Hosting;
using Topshelf;
namespace FinCore;
/// <summary>
/// The main server logic.
/// </summary>
public class QuartzServer : ServiceControl, IQuartzServer
{
private static readonly ILog Log = LogManager.GetLogger(typeof(QuartzServer));
private static QuartzServer server;
private IHost webapi;
private IMainService xtradeServer;
private QuartzServer()
{
}
public static QuartzServer Server
{
get
{
if (server == null)
{
server = new QuartzServer();
return server;
}
return server;
}
}
/// <summary>
/// Starts this instance, delegates to scheduler.
/// </summary>
public virtual void Start()
{
try
{
string[] args = {""};
webapi = Program.CreateHostBuilder(args).Build();
webapi.StartAsync();
}
catch (Exception ex)
{
Log.Fatal(string.Format("Quaetz Server start failed: {0}", ex.Message), ex);
throw;
}
}
/// <summary>
/// Stops this instance, delegates to scheduler.
/// </summary>
public virtual void Stop()
{
try
{
if (xtradeServer != null)
xtradeServer.Dispose();
if (webapi != null)
webapi.Dispose();
}
catch (Exception ex)
{
Log.Error(string.Format("Scheduler stop failed: {0}", ex.Message), ex);
throw;
}
Log.Info("Scheduler shutdown complete");
}
/// <summary>
/// Pauses all activity in scheduler.
/// </summary>
public virtual void Pause()
{
xtradeServer.PauseScheduler();
}
/// <summary>
/// Resumes all activity in server.
/// </summary>
public void Resume()
{
xtradeServer.ResumeScheduler();
}
/// <summary>
/// TopShelf's method delegated to <see cref="Start()" />.
/// </summary>
public bool Start(HostControl hostControl)
{
Start();
return true;
}
/// <summary>
/// TopShelf's method delegated to <see cref="Stop()" />.
/// </summary>
public bool Stop(HostControl hostControl)
{
Stop();
return true;
}
/// <summary>
/// Initializes the instance of the <see cref="QuartzServer" /> class.
/// </summary>
public virtual void Initialize(string angularFolder, string envName)
{
try
{
// XTradeConfig config = Program.Container.Resolve<XTradeConfig>();
xtradeServer = Program.Container.Resolve<IMainService>();
xtradeServer.Init(Program.Container);
Log.Info(string.Format("Inited with AngularFolder: {0}, Env: {1}", angularFolder, envName));
}
catch (Exception e)
{
Log.Error("Server initialization failed:" + e.Message, e);
throw;
}
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public virtual void Dispose()
{
//base.Dispose();
xtradeServer.Dispose(); // no-op for now
}
/// <summary>
/// TopShelf's method delegated to <see cref="Pause()" />.
/// </summary>
public bool Pause(HostControl hostControl)
{
Pause();
return true;
}
/// <summary>
/// TopShelf's method delegated to <see cref="Resume()" />.
/// </summary>
public bool Continue(HostControl hostControl)
{
Resume();
return true;
}
}