oqtane.framework/Oqtane.Server/Infrastructure/SyncManager.cs
Shaun Walker 02fde9cec3
rolled back change creating an Infrastructure.Interfaces namespace, modified IModule interface to be strongly typed (#343)
* upgrade to .NET Core 3.2 Preview 3 and fixes for issues created by #314

* Components based on Bootstrap4 for Sections and  TabStrip to increase productivity and promote uniformity in Module UIs

* rolled back change creating an Infrastructure.Interfaces namespace, modified IModule interface to be strongly typed
2020-04-05 14:39:08 -04:00

46 lines
1.4 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using Oqtane.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using Oqtane.Infrastructure;
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));
}
}
}