This repository has been archived on 2025-05-14. You can view files and clone it, but cannot push or open issues or pull requests.
Pavel Vesely 5b3feaf26f Server naming fixes and cleanup
Server is now completely cleaned up and without warnings
2020-03-15 11:53:24 +01:00

46 lines
1.5 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using Oqtane.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using Oqtane.Infrastructure.Interfaces;
using Oqtane.Repository;
namespace Oqtane.Infrastructure
{
public class SyncManager : ISyncManager
{
private readonly IServiceScopeFactory _serviceScopeFactory;
private List<SyncEvent> SyncEvents { get; set; }
public SyncManager(IServiceScopeFactory serviceScopeFactory)
{
this._serviceScopeFactory = serviceScopeFactory;
SyncEvents = new List<SyncEvent>();
}
private int TenantId
{
get
{
using (var scope = _serviceScopeFactory.CreateScope())
{
return scope.ServiceProvider.GetRequiredService<ITenantResolver>().GetTenant().TenantId;
}
}
}
public List<SyncEvent> GetSyncEvents(DateTime lastSyncDate)
{
return SyncEvents.Where(item => item.TenantId == TenantId && item.ModifiedOn >= lastSyncDate).ToList();
}
public void AddSyncEvent(string entityName, int entityId)
{
SyncEvents.Add(new SyncEvent { TenantId = TenantId, EntityName = entityName, EntityId = entityId, ModifiedOn = DateTime.UtcNow });
// trim sync events
SyncEvents.RemoveAll(item => item.ModifiedOn < DateTime.UtcNow.AddHours(-1));
}
}
}