37 lines
999 B
C#
37 lines
999 B
C#
|
using Microsoft.Extensions.Options;
|
|||
|
|
|||
|
using MongoDB.Entities;
|
|||
|
|
|||
|
using SocialPub.Models;
|
|||
|
using SocialPub.StaticServices;
|
|||
|
|
|||
|
namespace SocialPub.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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|