forked from jci-metasys/historian
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
90 lines (80 loc) · 2.94 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
80
81
82
83
84
85
86
87
88
89
90
using CommandLine;
using HistoricalDataFetcher.Classes.Controller;
using HistoricalDataFetcher.Classes.StartOptions;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config")]
namespace HistoricalDataFetcher.Discovery
{
class Program
{
private static Controller _con;
static void Main(string[] args)
{
_con = new Controller();
CommandLine.Parser.Default.ParseArguments<StartOptions>(args).WithParsed(opts => RunOptionsAsync(opts).Wait()).WithNotParsed<StartOptions>((errs) => HandleParseError(errs));
Console.WriteLine("Done!");
}
/// <summary>
/// Run parsed Options
/// </summary>
/// <param name="opts">Start Options parsed from the arguments</param>
/// <returns></returns>
private static async Task RunOptionsAsync(StartOptions opts)
{
if (!await _con.SetDBSettingsAsync(opts))
{
Console.WriteLine(@"Could not log in:
The Host, Username, and Password combination did not work, please try again!");
return;
}
else if (!await _con.InitApiRequestAsync(opts))
{
Console.WriteLine(@"Could not log in:
The Host, Username, and Password combination did not work, please try again!");
return;
}
try
{
//Load CSV to DB
await _con.RunDiscoveryEnumSetAsync();
}
catch
{
Console.WriteLine(@"Failed to run Discovery Enumset!");
return;
}
//Load the EnumFile
if (!await _con.InitStartEnumDownloadAsync())
{
Console.WriteLine(@"Failed to load Enumset!");
return;
}
//Initialize TaskEnumUtility
_con.SetEndPoints(opts);
if (!string.IsNullOrWhiteSpace(opts.FqrPath))
{
try
{
//Load CSV to DB
await _con.ReadFqrsFromFileAsync(opts.FqrPath);
}
catch
{
Console.WriteLine($"Failed to Read FQRs from the file provided! file path: {opts.FqrPath}");
return;
}
}
return;
}
/// <summary>
/// Handle the parsing error from the arguments passed in
/// </summary>
/// <param name="error">List of errors from pasring the arguemnts</param>
private static void HandleParseError(IEnumerable<Error> error)
{
System.Console.WriteLine(@"There was an error with the arguments: re-enter the arguments based on the usage output, please try again!");
}
}
}