-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
89 lines (80 loc) · 3.33 KB
/
Program.cs
File metadata and controls
89 lines (80 loc) · 3.33 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
using QuantframeLib.LogParser;
using QuantframeLib.Model;
using QuantframeLib.HttpServer;
using System;
using System.Linq;
using QuantframeLib.Utils;
using System.Diagnostics;
using System.Threading;
using System.Collections.Generic;
namespace QuantframeLib
{
internal class Program
{
private static string GetArgByName(string name)
{
string[] args = Environment.GetCommandLineArgs();
for (int i = 0; i < args.Length; i++)
if (args[i] == name && args.Length > i + 1)
return args[i + 1];
return null;
}
private static List<string> GetArgsByName(string name)
{
string[] args = Environment.GetCommandLineArgs();
List<string> values = new List<string>();
for (int i = 0; i < args.Length; i++)
{
if (args[i] == name && args.Length > i + 1)
{
values.Add(args[i + 1]);
i++; // Skip the value we just added to avoid redundant checks
}
}
return values;
}
// Args 1:StoragePath, 2:SocketHost, 3:HttpServer
static void Main(string[] args)
{
// Will Add receiver --receiver <HOST>|<Events use comma separated>
string storagePath = GetArgByName("--storage") ?? "storage";
// Initialize the static data
StaticData.Initializer(storagePath);
List<string> receivers = GetArgsByName("--receiver").Count == 0 ?new List<string>() { "http://localhost:8080|OnConversationEvent:/new_conversation|OnTradeEvent:/trading/progress" }: GetArgsByName("--receiver");
foreach (Event receiver in receivers.SelectMany(x=> Event.ParseEvents(x)).ToList())
StaticData.AddListener(receiver.Host, receiver.EventName,receiver.Path);
Tuple<string, int> HttpServer = SpiltHost(GetArgByName("--httpServer")) ?? new Tuple<string, int>("localhost", 9998);
string keepAliveProcessName = GetArgByName("--keepAlive");
Logger.Info("Main", $"StoragePath: {storagePath} | HttpServer: {HttpServer.Item1}:{HttpServer.Item2} | KeepAlive: {keepAliveProcessName ?? "N/A"}");
// Initialize the log parser
LogParserClient.Initializer();
// Initialize the http server
HttpServerClient.Initializer(HttpServer.Item1, HttpServer.Item2);
new Thread(() =>
{
while (true)
{
if (!string.IsNullOrEmpty(keepAliveProcessName) && Process.GetProcessesByName(keepAliveProcessName).Length == 0)
{
Logger.Critical("Main", "Keep alive process is not running. Exiting...");
Environment.Exit(0);
}
Thread.Sleep(3000);
}
})
{
IsBackground = true
}.Start();
while (true) ;
}
public static Tuple<string, int> SpiltHost(string host)
{
if (host == null)
return null;
if (!host.Contains(":"))
return null;
string[] hostParts = host.Split(':');
return new Tuple<string, int>(hostParts[0], int.Parse(hostParts[1]));
}
}
}