2020-07-07 01:33:52 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-07-07 21:03:20 -04:00
|
|
|
|
using BirdsiteLive.DAL.Contracts;
|
2020-07-16 01:19:41 -04:00
|
|
|
|
using BirdsiteLive.Pipeline;
|
2020-07-07 01:33:52 -04:00
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
|
|
|
|
namespace BirdsiteLive.Services
|
|
|
|
|
{
|
|
|
|
|
public class FederationService : BackgroundService
|
|
|
|
|
{
|
2020-07-07 21:03:20 -04:00
|
|
|
|
private readonly IDbInitializerDal _dbInitializerDal;
|
2020-07-16 01:19:41 -04:00
|
|
|
|
private readonly IStatusPublicationPipeline _statusPublicationPipeline;
|
2020-07-07 01:33:52 -04:00
|
|
|
|
|
|
|
|
|
#region Ctor
|
2020-07-16 01:19:41 -04:00
|
|
|
|
public FederationService(IDbInitializerDal dbInitializerDal, IStatusPublicationPipeline statusPublicationPipeline)
|
2020-07-07 01:33:52 -04:00
|
|
|
|
{
|
2020-07-07 21:03:20 -04:00
|
|
|
|
_dbInitializerDal = dbInitializerDal;
|
2020-07-16 01:19:41 -04:00
|
|
|
|
_statusPublicationPipeline = statusPublicationPipeline;
|
2020-07-07 01:33:52 -04:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
|
|
{
|
2020-07-07 21:03:20 -04:00
|
|
|
|
await DbInitAsync();
|
2020-07-16 01:19:41 -04:00
|
|
|
|
await _statusPublicationPipeline.ExecuteAsync(stoppingToken);
|
2020-07-07 01:33:52 -04:00
|
|
|
|
}
|
2020-07-07 21:03:20 -04: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 01:33:52 -04:00
|
|
|
|
}
|
|
|
|
|
}
|