-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
75 lines (68 loc) · 2.37 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
using CommandLine;
using System.IO;
using System.Globalization;
namespace StandardImportToolPlugin
{
public class CommandLineOptions {
[Option(
shortName: 'c',
longName: "config_path",
Required = true,
HelpText = "Path to a json formatted file specifying SIT import configuration"
)]
public string ConfigPath { get; set; }
[Option(
shortName: 'a',
longName: "append_mode",
Required = false,
HelpText = "If append_mode is set to false (default) sit import, "+
"then run the usual SIT import process. If set to true, " +
"append the yield curve, disturbance event and transition rule data " +
"as new CBM assumptions in the existing project."
)]
public bool AppendMode { get; set; }
[Option(
shortName: 'l',
longName: "culture_info",
Required= false,
Default=null,
HelpText = "A culture info name for one of the languages " +
"supported by the SIT for error and log feedback. " +
"For example (en-CA, fr-CA, es-MX, pl-PL or ru-RU)"
)]
public string CultureInfoName { get; set; }
}
class Program
{
static string ReadFile(string path)
{
using (StreamReader reader = new StreamReader(File.OpenRead(path)))
{
return reader.ReadToEnd();
}
}
static void Main(string[] args)
{
var options = new CommandLineOptions();
var result = Parser.Default.ParseArguments<CommandLineOptions>(args);
result.WithParsed(a => {
if(a.CultureInfoName != null){
Global.StringUtilities.ci = new CultureInfo(a.CultureInfoName, true);
}
string json = ReadFile(a.ConfigPath);
JsonConfigLoader jsonConfigLoader = new JsonConfigLoader();
Sitplugin sitplugin = jsonConfigLoader.Load(json);
try
{
sitplugin.Import(a.AppendMode);
}
catch(CBMSIT.ProjectCreation.ProjectCreationException ex)
{
System.Console.WriteLine(ex.Message);
throw ex;
}
});
}
}
}