2022-01-17 15:33:00 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
2022-12-02 17:18:16 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.DetectOperations;
|
|
|
|
|
using AsbCloudInfrastructure.Services.Subsystems;
|
|
|
|
|
using AsbCloudInfrastructure.Services;
|
2022-01-17 15:33:00 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using System;
|
2022-12-02 17:18:16 +05:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Threading;
|
2022-01-17 15:33:00 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure
|
|
|
|
|
{
|
2022-04-11 18:00:34 +05:00
|
|
|
|
public class Startup
|
2022-01-17 15:33:00 +05:00
|
|
|
|
{
|
2022-12-02 14:49:00 +05:00
|
|
|
|
public static void BeforeRunHandler(IHost host)
|
2022-04-11 18:00:34 +05:00
|
|
|
|
{
|
2022-01-17 15:33:00 +05:00
|
|
|
|
using var scope = host.Services.CreateScope();
|
2022-12-02 17:18:16 +05:00
|
|
|
|
var provider = scope.ServiceProvider;
|
2022-01-17 15:33:00 +05:00
|
|
|
|
|
2022-12-02 17:18:16 +05:00
|
|
|
|
var context = provider.GetService<IAsbCloudDbContext>();
|
|
|
|
|
context.Database.SetCommandTimeout(TimeSpan.FromSeconds(2 * 60));
|
2022-01-17 15:33:00 +05:00
|
|
|
|
context.Database.Migrate();
|
|
|
|
|
|
2022-12-02 17:18:16 +05:00
|
|
|
|
var wellService = provider.GetRequiredService<IWellService>();
|
|
|
|
|
wellService.EnshureTimezonesIsSetAsync(CancellationToken.None).Wait();// TODO: make this background work
|
|
|
|
|
|
|
|
|
|
var backgroundWorker = provider.GetRequiredService<Background.BackgroundWorker>();
|
|
|
|
|
backgroundWorker.Push(OperationDetectionWorkFactory.MakeWork());
|
|
|
|
|
backgroundWorker.Push(SubsystemOperationTimeCalcWorkFactory.MakeWork());
|
|
|
|
|
backgroundWorker.Push(LimitingParameterCalcWorkFactory.MakeWork());
|
|
|
|
|
|
|
|
|
|
Task.Delay(1_000)
|
|
|
|
|
.ContinueWith(async (_) => await backgroundWorker.StartAsync(CancellationToken.None));
|
2022-01-17 15:33:00 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|