-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
79 lines (68 loc) · 2.04 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
77
78
79
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Mono.Options;
using IqFeed.Model;
using IqFeed.Commanders;
namespace IqFeed {
class MainClass {
static CommanderBase commander;
private static Admin admin;
private static string infile;
private static string ignored;
private static bool help;
public static void Main(string[] args) {
ProcessArgs(args);
admin = new Admin();
Task<bool> t = Task.Run(() => admin.Launch());
t.Wait();
if (t.Result == true) {
if (infile != null) {
commander = new FileCommander(infile);
} else {
commander = new ReadExecPrint();
commander.Responses.Subscribe(
(line) => Console.WriteLine($"data: {line}"),
() => Console.WriteLine("Sequence Completed.")
);
}
try {
Task.Run(() => commander.Run(admin)).Wait();
} catch (Exception e) {
Console.WriteLine(e.Message);
if(e.InnerException != null) {
Console.WriteLine(e.InnerException.Message);
}
}
} else {
Console.WriteLine("bad admin");
}
}
private static void ProcessArgs(string[] args) {
List<string> options;
OptionSet option_set = new OptionSet()
.Add("?|help|h", "Prints out the options.", option => help = option != null)
.Add("i=|input-file=",
"File with list of commands to execute.",
option => infile = option)
.Add("s=|server=|servername=|instance=|instancename=",
option => ignored = option);
try {
options = option_set.Parse(args);
if (options.Contains("--infile") && infile == null) {
show_help("no file specified for infile", option_set);
}
if (help) {
show_help("help yourself", option_set);
}
} catch (OptionException e) {
show_help(e.Message, option_set);
}
}
public static void show_help(string message, OptionSet option_set) {
Console.Error.WriteLine(message);
option_set.WriteOptionDescriptions(Console.Error);
Environment.Exit(-1);
}
}
}