コード例 #1
0
 private void UpdateApp(AppEvent @event, EnvelopeHeaders headers, Action <JsonAppEntity> updater = null)
 {
     App = App.Clone().Update(@event, headers, updater);
 }
コード例 #2
0
 protected Task On(SchemaUnpublished @event, EnvelopeHeaders headers)
 {
     return(UpdateSchema(@event, headers, s => SchemaEventDispatcher.Dispatch(@event, s)));
 }
コード例 #3
0
        public static async Task UpdateAsync <T>(this IMongoCollection <T> collection, SquidexEvent @event, EnvelopeHeaders headers, Action <T> updater) where T : MongoEntity, new()
        {
            var entity = await collection.Find(t => t.Id == headers.AggregateId()).FirstOrDefaultAsync();

            if (entity == null)
            {
                throw new DomainObjectNotFoundException(headers.AggregateId().ToString(), typeof(T));
            }

            EntityMapper.Update(@event, headers, entity);

            updater(entity);

            await collection.ReplaceOneAsync(t => t.Id == entity.Id, entity);
        }
コード例 #4
0
 private Task UpdateSchema(SquidexEvent @event, EnvelopeHeaders headers, Func <Schema, Schema> updater)
 {
     return(Collection.UpdateAsync(@event, headers, e => UpdateSchema(e, updater)));
 }
コード例 #5
0
        protected Task On(SchemaCreated @event, EnvelopeHeaders headers)
        {
            var schema = SchemaEventDispatcher.Dispatch(@event, registry);

            return(Collection.CreateAsync(@event, headers, s => { UpdateSchema(s, schema); SimpleMapper.Map(@event, s); }));
        }
コード例 #6
0
 protected Task On(SchemaFieldsReordered @event, EnvelopeHeaders headers)
 {
     return UpdateSchema(@event, headers, s => SchemaEventDispatcher.Dispatch(@event, s));
 }
コード例 #7
0
 protected Task On(ScriptsConfigured @event, EnvelopeHeaders headers)
 {
     return(Collection.UpdateAsync(@event, headers, e => SimpleMapper.Map(@event, e)));
 }
コード例 #8
0
        private void UpdateRule(RuleEvent @event, EnvelopeHeaders headers, Action <JsonRuleEntity> updater = null)
        {
            var id = @event.RuleId;

            Rules = Rules.SetItem(id, x => x.Clone().Update(@event, headers, updater));
        }
コード例 #9
0
 public void On(WebhookDeleted @event, EnvelopeHeaders headers)
 {
     UpdateSchema(@event, headers);
 }
コード例 #10
0
 protected Task On(AssetDeleted @event, EnvelopeHeaders headers)
 {
     return(Collection.DeleteOneAsync(x => x.Id == @event.AssetId));
 }
コード例 #11
0
 public void On(RuleDeleted @event, EnvelopeHeaders headers)
 {
     Rules.Remove(@event.RuleId);
 }
コード例 #12
0
        private static async Task UpdateAsync <T>(this IMongoCollection <T> collection, SquidexEvent @event, EnvelopeHeaders headers, T entity, Action <T> updater) where T : class, IEntity, new()
        {
            entity.Update(@event, headers, updater);

            await collection.ReplaceOneAsync(t => t.Id == entity.Id, entity);
        }
コード例 #13
0
        public static async Task <bool> TryUpdateAsync <T>(this IMongoCollection <T> collection, SquidexEvent @event, EnvelopeHeaders headers, Action <T> updater) where T : class, IEntity, new()
        {
            var entity =
                await collection.Find(t => t.Id == headers.AggregateId())
                .FirstOrDefaultAsync();

            if (entity != null)
            {
                if (entity is IEntityWithVersion withVersion)
                {
                    var eventVersion = headers.EventStreamNumber();

                    if (eventVersion <= withVersion.Version)
                    {
                        return(false);
                    }
                }

                await collection.UpdateAsync(@event, headers, entity, updater);

                return(true);
            }

            return(false);
        }
コード例 #14
0
        public static Task CreateAsync <T>(this IMongoCollection <T> collection, SquidexEvent @event, EnvelopeHeaders headers, Action <T> updater) where T : class, IEntity, new()
        {
            var entity = new T().Update(@event, headers, updater);

            return(collection.InsertOneIfNotExistsAsync(entity));
        }
コード例 #15
0
 private static void SetCreated(EnvelopeHeaders headers, IMongoEntity entity)
 {
     entity.Created = headers.Timestamp();
 }
コード例 #16
0
 public void On(SchemaDeleted @event, EnvelopeHeaders headers)
 {
     Schemas = Schemas.Remove(@event.SchemaId.Id);
 }
コード例 #17
0
 private static void SetLastModified(EnvelopeHeaders headers, IMongoEntity entity)
 {
     entity.LastModified = headers.Timestamp();
 }
コード例 #18
0
        private void UpdateSchema(SchemaEvent @event, EnvelopeHeaders headers, Action <JsonSchemaEntity> updater = null)
        {
            var id = @event.SchemaId.Id;

            Schemas = Schemas.SetItem(id, x => x.Clone().Update(@event, headers, updater));
        }
コード例 #19
0
 protected Task On(FieldAdded @event, EnvelopeHeaders headers)
 {
     return(UpdateSchema(@event, headers, s => SchemaEventDispatcher.Dispatch(@event, s, registry)));
 }
コード例 #20
0
 public virtual bool ApplyEvent(IEvent @event, EnvelopeHeaders headers)
 {
     return(ApplyEvent(@event));
 }
コード例 #21
0
 protected Task On(SchemaDeleted @event, EnvelopeHeaders headers)
 {
     return(Collection.UpdateAsync(@event, headers, e => e.IsDeleted = true));
 }
コード例 #22
0
        private bool IsTooOld(EnvelopeHeaders headers)
        {
            var now = clock.GetCurrentInstant();

            return(now - headers.Timestamp() > MaxAge);
        }
コード例 #23
0
 protected Task On(WebhookDeleted @event, EnvelopeHeaders headers)
 {
     return(Collection.UpdateAsync(@event, headers, e => { }));
 }
コード例 #24
0
 public static Guid AppId(this EnvelopeHeaders headers)
 {
     return(headers[SquidexHeaders.AppId].ToGuid(CultureInfo.InvariantCulture));
 }
コード例 #25
0
 protected Task On(FieldEnabled @event, EnvelopeHeaders headers)
 {
     return(UpdateSchema(@event, headers, s => SchemaEventDispatcher.Dispatch(@event, s)));
 }
コード例 #26
0
 protected Task On(WebhookDeleted @event, EnvelopeHeaders headers)
 {
     return(UpdateSchema(@event, headers, s => s));
 }
コード例 #27
0
        public static async Task CreateAsync <T>(this IMongoCollection <T> collection, SquidexEvent @event, EnvelopeHeaders headers, Func <T, Task> updater) where T : MongoEntity, new()
        {
            var entity = EntityMapper.Create <T>(@event, headers);

            await updater(entity);

            await collection.InsertOneIfNotExistsAsync(entity);
        }
コード例 #28
0
 private static void SetId(EnvelopeHeaders headers, IMongoEntity entity)
 {
     entity.Id = headers.AggregateId();
 }
コード例 #29
0
        public override bool ApplyEvent(IEvent @event, EnvelopeHeaders headers)
        {
            switch (@event)
            {
            case ContentCreated e:
            {
                Id = e.ContentId;

                SimpleMapper.Map(e, this);

                CurrentVersion = new ContentVersion(e.Status, e.Data);

                break;
            }

            case ContentDraftCreated e:
            {
                NewVersion = new ContentVersion(e.Status, e.MigratedData ?? CurrentVersion.Data);

                ScheduleJob = null;

                break;
            }

            case ContentDraftDeleted _:
            {
                NewVersion = null;

                ScheduleJob = null;

                break;
            }

            case ContentStatusChanged e:
            {
                ScheduleJob = null;

                if (NewVersion != null)
                {
                    if (e.Status == Status.Published)
                    {
                        CurrentVersion = new ContentVersion(e.Status, NewVersion.Data);

                        NewVersion = null;
                    }
                    else
                    {
                        NewVersion = NewVersion.WithStatus(e.Status);
                    }
                }
                else
                {
                    CurrentVersion = CurrentVersion.WithStatus(e.Status);
                }

                break;
            }

            case ContentSchedulingCancelled _:
            {
                ScheduleJob = null;

                break;
            }

            case ContentStatusScheduled e:
            {
                ScheduleJob = ScheduleJob.Build(e.Status, e.Actor, e.DueTime);

                break;
            }

            case ContentUpdated e:
            {
                if (NewVersion != null)
                {
                    NewVersion = NewVersion.WithData(e.Data);
                }
                else
                {
                    CurrentVersion = CurrentVersion.WithData(e.Data);
                }

                break;
            }

            case ContentDeleted _:
            {
                IsDeleted = true;

                break;
            }
            }

            return(true);
        }
コード例 #30
0
 protected Task On(AssetDeleted @event, EnvelopeHeaders headers)
 {
     return(UpdateSizeAsync(@event.AppId.Id, headers.Timestamp().ToDateTimeUtc().Date, [email protected], -1));
 }