mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.7 KiB
52 lines
1.7 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Squidex.Domain.Apps.Entities.Backup;
|
|
using Squidex.Domain.Apps.Entities.Rules.Indexes;
|
|
using Squidex.Domain.Apps.Events.Rules;
|
|
using Squidex.Infrastructure;
|
|
using Squidex.Infrastructure.EventSourcing;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Rules
|
|
{
|
|
public sealed class BackupRules : IBackupHandler
|
|
{
|
|
private readonly HashSet<DomainId> ruleIds = new HashSet<DomainId>();
|
|
private readonly IRulesIndex indexForRules;
|
|
|
|
public string Name { get; } = "Rules";
|
|
|
|
public BackupRules(IRulesIndex indexForRules)
|
|
{
|
|
Guard.NotNull(indexForRules, nameof(indexForRules));
|
|
|
|
this.indexForRules = indexForRules;
|
|
}
|
|
|
|
public Task<bool> RestoreEventAsync(Envelope<IEvent> @event, RestoreContext context)
|
|
{
|
|
switch (@event.Payload)
|
|
{
|
|
case RuleCreated ruleCreated:
|
|
ruleIds.Add(ruleCreated.RuleId);
|
|
break;
|
|
case RuleDeleted ruleDeleted:
|
|
ruleIds.Remove(ruleDeleted.RuleId);
|
|
break;
|
|
}
|
|
|
|
return Task.FromResult(true);
|
|
}
|
|
|
|
public Task RestoreAsync(RestoreContext context)
|
|
{
|
|
return indexForRules.RebuildAsync(context.AppId, ruleIds);
|
|
}
|
|
}
|
|
}
|
|
|