-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
36 lines (34 loc) · 1.41 KB
/
Program.cs
File metadata and controls
36 lines (34 loc) · 1.41 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
using dotenv.net;
using CommandLine;
using Microsoft.Extensions.Configuration;
using Oracle.ManagedDataAccess.Client;
DotEnv.Load();
IConfiguration config = new ConfigurationBuilder().AddEnvironmentVariables().Build();
var parser = new Parser(settings =>
{
settings.AutoHelp = true;
settings.CaseInsensitiveEnumValues = true;
settings.HelpWriter = Console.Error;
});
await parser.ParseArguments<Options>(args).WithParsedAsync(async options =>
{
try
{
var libInsightClient = new LibInsightClient();
await libInsightClient.Authorize(config["LIBINSIGHT_CLIENT_ID"], config["LIBINSIGHT_CLIENT_SECRET"]);
using var conn = new OracleConnection(config["ORACLE_CONNECTION_STRING"]);
Dataset dataset = options.DatasetId switch {
DatasetId.InstructionOutreach => new InstructionOutreachDataset(conn, libInsightClient),
DatasetId.HillHeadCounts => new HeadCountsDataset(conn, libInsightClient),
_ => throw new Exception("Dataset not recognized"),
};
await dataset.ProcessDateRange(options.FromDate ?? StartOfFiscalYear(), options.ToDate ?? DateTime.Today);
}
catch (Exception exception)
{
Console.Error.WriteLine(exception);
throw;
}
});
// Returns the first day of the previous July
DateTime StartOfFiscalYear() => new DateTime(DateTime.Today.Month > 7 ? DateTime.Today.Year : DateTime.Today.Year - 1, 7, 1);