37 lines
996 B
C#
37 lines
996 B
C#
using Microsoft.Extensions.Options;
|
|
|
|
using MongoDB.Entities;
|
|
|
|
using PrivaPub.Models;
|
|
using PrivaPub.StaticServices;
|
|
|
|
namespace PrivaPub.Services
|
|
{
|
|
public class AppConfigurationService
|
|
{
|
|
public AppConfiguration AppConfiguration;
|
|
readonly DbEntities _dbEntities;
|
|
AppConfiguration _appConfigurationFromFile;
|
|
public AppConfigurationService(DbEntities dbEntities, IOptionsMonitor<AppConfiguration> appConfiguration)
|
|
{
|
|
_dbEntities = dbEntities;
|
|
_appConfigurationFromFile = appConfiguration.CurrentValue;
|
|
}
|
|
|
|
public async Task Init()
|
|
{
|
|
var dbAppConfiguration = await _dbEntities.AppConfiguration.ExecuteFirstAsync();
|
|
if (dbAppConfiguration != default)
|
|
{
|
|
if (AppConfiguration == default || AppConfiguration.LastUpdateDate != dbAppConfiguration.LastUpdateDate)
|
|
AppConfiguration = dbAppConfiguration;
|
|
return;
|
|
}
|
|
|
|
dbAppConfiguration = _appConfigurationFromFile;
|
|
await dbAppConfiguration.SaveAsync();
|
|
AppConfiguration = dbAppConfiguration;
|
|
}
|
|
}
|
|
}
|