forked from dotnet/machinelearning-samples
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProgram.vb
More file actions
173 lines (167 loc) · 5.21 KB
/
Program.vb
File metadata and controls
173 lines (167 loc) · 5.21 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
Imports eShopDashboard.Infrastructure.Data.Catalog
Imports eShopDashboard.Infrastructure.Data.Ordering
Imports eShopDashboard.Infrastructure.Setup
Imports Microsoft.AspNetCore
Imports Microsoft.AspNetCore.Hosting
Imports Microsoft.EntityFrameworkCore
Imports Microsoft.Extensions.Configuration
Imports Microsoft.Extensions.DependencyInjection
Imports Serilog
Imports Serilog.Events
Imports System
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.IO
Imports System.Threading
Imports System.Threading.Tasks
Namespace eShopDashboard
Public Class Program
Private Shared _seedingProgress As Integer = 100
Public Shared Function BuildWebHost(args() As String) As IWebHost
Return WebHost.CreateDefaultBuilder(args).UseContentRoot(Directory.GetCurrentDirectory()).UseStartup(Of Startup)().UseSerilog().ConfigureAppConfiguration(Sub(builderContext, config)
End Sub
If True Then
config.AddEnvironmentVariables()
End If).Build()
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
' public static int GetSeedingProgress()
' {
' Return _seedingProgress;
' }
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
' public static int Main(string[] args)
' {
' Log.Logger = New LoggerConfiguration().MinimumLevel.Debug().MinimumLevel.Override("Microsoft", LogEventLevel.Information).Enrich.FromLogContext().WriteTo.Console().WriteTo.Seq("http://localhost:5341/").CreateLogger();
'
' Log.Information("----- Starting web host");
'
' try
' {
' var host = BuildWebHost(args);
'
' Log.Information("----- Seeding Database");
'
' Task seeding = Task.Run(async() =>
' {
' await ConfigureDatabaseAsync(host);
' }
' );
'
' Log.Information("----- Running Host");
'
' host.Run();
'
' Log.Information("----- Web host stopped");
'
' Return 0;
' }
' catch (Exception ex)
' {
' Log.Fatal(ex, "----- Host terminated unexpectedly");
'
' Return 1;
' }
' finally
' {
' Log.CloseAndFlush();
' }
' }
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
' private static async Task ConfigureDatabaseAsync(IWebHost host)
' {
' _seedingProgress = 0;
'
' using (var scope = host.Services.CreateScope())
' {
' var services = scope.ServiceProvider;
'
' var catalogContext = services.GetService<CatalogContext>();
' await catalogContext.Database.MigrateAsync();
'
' var orderingContext = services.GetService<OrderingContext>();
' await orderingContext.Database.MigrateAsync();
' }
'
' await SeedDatabaseAsync(host);
'
' _seedingProgress = 100;
' }
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
' private static async Task SeedDatabaseAsync(IWebHost host)
' {
' try
' {
' using (var scope = host.Services.CreateScope())
' {
' IServiceProvider services = scope.ServiceProvider;
'
' Log.Information("----- Checking seeding status");
'
' var catalogContextSetup = services.GetService<CatalogContextSetup>();
' var orderingContextSetup = services.GetService<OrderingContextSetup>();
'
' var catalogSeedingStatus = await catalogContextSetup.GetSeedingStatusAsync();
' Log.Information("----- SeedingStatus ({Context}): {@SeedingStatus}", "Catalog", catalogSeedingStatus);
'
' var orderingSeedingStatus = await orderingContextSetup.GetSeedingStatusAsync();
' Log.Information("----- SeedingStatus ({Context}): {@SeedingStatus}", "Ordering", orderingSeedingStatus);
'
' var seedingStatus = New SeedingStatus(catalogSeedingStatus, orderingSeedingStatus);
' Log.Information("----- SeedingStatus ({Context}): {@SeedingStatus}", "Aggregated", seedingStatus);
'
' if (!seedingStatus.NeedsSeeding)
' {
' Log.Information("----- No seeding needed");
'
' Return;
' }
'
' Log.Information("----- Seeding database");
'
' var sw = New Stopwatch();
' sw.Start();
'
' void ProgressAggregator()
' {
' seedingStatus.RecordsLoaded = catalogSeedingStatus.RecordsLoaded + orderingSeedingStatus.RecordsLoaded;
'
' Log.Debug("----- Seeding {SeedingPercentComplete}% complete", seedingStatus.PercentComplete);
' _seedingProgress = seedingStatus.PercentComplete;
' }
'
' var catalogProgressHandler = New Progress<int>(value =>
' {
' catalogSeedingStatus.RecordsLoaded = value;
' ProgressAggregator();
' }
' );
'
' var orderingProgressHandler = New Progress<int>(value =>
' {
' orderingSeedingStatus.RecordsLoaded = value;
' ProgressAggregator();
' }
' );
'
' Log.Information("----- Seeding CatalogContext");
' Task catalogSeedingTask = Task.Run(async() => await catalogContextSetup.SeedAsync(catalogProgressHandler));
'
' Log.Information("----- Seeding OrderingContext");
' Task orderingSeedingTask = Task.Run(async() => await orderingContextSetup.SeedAsync(orderingProgressHandler));
'
' await Task.WhenAll(catalogSeedingTask, orderingSeedingTask);
'
' seedingStatus.SetAsComplete();
' _seedingProgress = seedingStatus.PercentComplete;
'
' Log.Information("----- Database Seeded ({ElapsedTime:n3}s)", sw.Elapsed.TotalSeconds);
' }
'
' }
' catch (Exception ex)
' {
' Log.@Error(ex, "----- Exception seeding database");
' }
' }
End Function
End Class