-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartup.cs
105 lines (83 loc) · 3.43 KB
/
Startup.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Api.Architecture.Console.Extensions;
using Api.Architecture.ServiceLayer;
using Api.Architecture.DomainLayer.ApiModels;
using System.Threading.Tasks;
using Api.Architecture.Console;
namespace Api
{
public class Startup
{
private static readonly IServiceProvider services;
private static readonly string path = $@"{Environment.GetFolderPath(
Environment.SpecialFolder.CommonApplicationData)}\Clean Water Services\Terratrak\Logs";
#region Constructor:
static Startup() => services = Configure();
#endregion
public static async Task Main()
{
try
{
IDataRetrievalService api = services.GetService<IDataRetrievalService>();
AuthenticationModel authenticated = await api.GetToken();
#region Web Request:
var budget = api.GetBudgetReport(authenticated);
var site = api.GetSiteReport(authenticated);
var project = api.GetProjectReport(authenticated);
var task = api.GetTaskReport(authenticated);
var workEffort = api.GetWorkEffortReport(authenticated);
#endregion
IDatabaseCleanupService cleanup = services.GetService<IDatabaseCleanupService>();
await Task.WhenAll(
api.GetBudgetReport(authenticated),
cleanup.PurgeBudget(),
api.GetSiteReport(authenticated),
cleanup.PurgeSite(),
api.GetProjectReport(authenticated),
cleanup.PurgeProject(),
api.GetTaskReport(authenticated),
cleanup.PurgeTask(),
api.GetWorkEffortReport(authenticated),
cleanup.PurgeWorkEffort()
);
IDatabaseImporterService importer = services.GetService<IDatabaseImporterService>();
await Task.WhenAll(
importer.InsertBudget(await budget),
importer.InsertSite(await site),
importer.InsertProject(await project),
importer.InsertTask(await task),
importer.InsertWorkEffort(await workEffort)
);
}
catch (Exception exception)
{
exception.Decorate(Log.Logger);
throw;
}
}
#region Protected:
public static IServiceProvider Configure()
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("application-settings.json", false, true)
.Build();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.WriteTo.Console()
.WriteTo.File($@"{path}\log-.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
return new ServiceCollection()
.AddLogging(option => option.AddSerilog())
.AddSingleton(Log.Logger)
.AddSingleton(configure => (IConfiguration)configuration)
.Register()
.BuildServiceProvider();
}
#endregion
}
}