示例#1
0
        private async Task RebuildRuleIndexes()
        {
            var rulesByApp = new Dictionary <Guid, HashSet <Guid> >();

            HashSet <Guid> Index(RuleEvent @event)
            {
                return(rulesByApp.GetOrAddNew(@event.AppId.Id));
            }

            await eventStore.QueryAsync(storedEvent =>
            {
                var @event = eventDataFormatter.Parse(storedEvent.Data);

                switch (@event.Payload)
                {
                case RuleCreated ruleCreated:
                    Index(ruleCreated).Add(ruleCreated.RuleId);
                    break;

                case RuleDeleted ruleDeleted:
                    Index(ruleDeleted).Remove(ruleDeleted.RuleId);
                    break;
                }

                return(TaskHelper.Done);
            }, "^rule\\-");

            foreach (var kvp in rulesByApp)
            {
                await indexRules.RebuildAsync(kvp.Key, kvp.Value);
            }
        }
        private async Task RebuildRuleIndexes()
        {
            var rulesByApp = new Dictionary <DomainId, HashSet <DomainId> >();

            HashSet <DomainId> Index(RuleEvent @event)
            {
                return(rulesByApp !.GetOrAddNew(@event.AppId.Id));
            }

            await foreach (var storedEvent in eventStore.QueryAllAsync("^rule\\-"))
            {
                var @event = eventDataFormatter.ParseIfKnown(storedEvent);

                if (@event != null)
                {
                    switch (@event.Payload)
                    {
                    case RuleCreated created:
                        Index(created).Add(created.RuleId);
                        break;

                    case RuleDeleted deleted:
                        Index(deleted).Remove(deleted.RuleId);
                        break;
                    }
                }
            }

            foreach (var(appId, rules) in rulesByApp)
            {
                await indexRules.RebuildAsync(appId, rules);
            }
        }
示例#3
0
        private async Task RebuildRuleIndexes()
        {
            var rulesByApp = new Dictionary <DomainId, HashSet <DomainId> >();

            HashSet <DomainId> Index(RuleEvent @event)
            {
                return(rulesByApp !.GetOrAddNew(@event.AppId.Id));
            }

            await eventStore.QueryAsync(storedEvent =>
            {
                var @event = eventDataFormatter.Parse(storedEvent.Data);

                switch (@event.Payload)
                {
                case RuleCreated created:
                    Index(created).Add(created.RuleId);
                    break;

                case RuleDeleted deleted:
                    Index(deleted).Remove(deleted.RuleId);
                    break;
                }

                return(Task.CompletedTask);
            }, "^rule\\-");

            foreach (var(appId, rules) in rulesByApp)
            {
                await indexRules.RebuildAsync(appId, rules);
            }
        }
示例#4
0
        public async Task Should_restore_indices_for_all_non_deleted_rules()
        {
            var appId = Guid.NewGuid();

            var ruleId1 = Guid.NewGuid();
            var ruleId2 = Guid.NewGuid();
            var ruleId3 = Guid.NewGuid();

            var context = new RestoreContext(appId, new UserMapping(new RefToken(RefTokenType.Subject, "123")), A.Fake <IBackupReader>());

            await sut.RestoreEventAsync(Envelope.Create(new RuleCreated
            {
                RuleId = ruleId1
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new RuleCreated
            {
                RuleId = ruleId2
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new RuleCreated
            {
                RuleId = ruleId3
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new RuleDeleted
            {
                RuleId = ruleId3
            }), context);

            HashSet <Guid>?newIndex = null;

            A.CallTo(() => index.RebuildAsync(appId, A <HashSet <Guid> > ._))
            .Invokes(new Action <Guid, HashSet <Guid> >((_, i) => newIndex = i));

            await sut.RestoreAsync(context);

            Assert.Equal(new HashSet <Guid>
            {
                ruleId1,
                ruleId2
            }, newIndex);
        }
示例#5
0
 public Task RestoreAsync(RestoreContext context)
 {
     return(indexForRules.RebuildAsync(context.AppId, ruleIds));
 }
示例#6
0
 public override Task RestoreAsync(Guid appId, BackupReader reader)
 {
     return(indexForRules.RebuildAsync(appId, ruleIds));
 }