2020-07-07 07:33:52 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-07-08 03:03:20 +02:00
|
|
|
|
using BirdsiteLive.DAL.Contracts;
|
2020-07-07 07:33:52 +02:00
|
|
|
|
using BirdsiteLive.Domain;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
namespace BirdsiteLive.Services
|
|
|
|
|
{
|
|
|
|
|
public class FederationService : BackgroundService
|
|
|
|
|
{
|
2020-07-08 03:03:20 +02:00
|
|
|
|
private readonly IDbInitializerDal _dbInitializerDal;
|
2020-07-07 07:33:52 +02:00
|
|
|
|
private readonly IUserService _userService;
|
|
|
|
|
|
|
|
|
|
#region Ctor
|
2020-07-08 03:03:20 +02:00
|
|
|
|
public FederationService(IDbInitializerDal dbInitializerDal, IUserService userService)
|
2020-07-07 07:33:52 +02:00
|
|
|
|
{
|
2020-07-08 03:03:20 +02:00
|
|
|
|
_dbInitializerDal = dbInitializerDal;
|
2020-07-07 07:33:52 +02:00
|
|
|
|
_userService = userService;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
|
|
{
|
2020-07-08 03:03:20 +02:00
|
|
|
|
await DbInitAsync();
|
|
|
|
|
|
2020-07-07 07:33:52 +02:00
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("RUNNING SERVICE");
|
|
|
|
|
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-08 03:03:20 +02:00
|
|
|
|
|
|
|
|
|
private async Task DbInitAsync()
|
|
|
|
|
{
|
|
|
|
|
var currentVersion = await _dbInitializerDal.GetCurrentDbVersionAsync();
|
|
|
|
|
var mandatoryVersion = _dbInitializerDal.GetMandatoryDbVersion();
|
|
|
|
|
|
|
|
|
|
if (currentVersion == null)
|
|
|
|
|
{
|
|
|
|
|
await _dbInitializerDal.InitDbAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (currentVersion != mandatoryVersion)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-07 07:33:52 +02:00
|
|
|
|
}
|
|
|
|
|
}
|