private void UpdateApp(AppEvent @event, EnvelopeHeaders headers, Action <JsonAppEntity> updater = null) { App = App.Clone().Update(@event, headers, updater); }
protected Task On(SchemaUnpublished @event, EnvelopeHeaders headers) { return(UpdateSchema(@event, headers, s => SchemaEventDispatcher.Dispatch(@event, s))); }
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); }
private Task UpdateSchema(SquidexEvent @event, EnvelopeHeaders headers, Func <Schema, Schema> updater) { return(Collection.UpdateAsync(@event, headers, e => UpdateSchema(e, updater))); }
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); })); }
protected Task On(SchemaFieldsReordered @event, EnvelopeHeaders headers) { return UpdateSchema(@event, headers, s => SchemaEventDispatcher.Dispatch(@event, s)); }
protected Task On(ScriptsConfigured @event, EnvelopeHeaders headers) { return(Collection.UpdateAsync(@event, headers, e => SimpleMapper.Map(@event, e))); }
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)); }
public void On(WebhookDeleted @event, EnvelopeHeaders headers) { UpdateSchema(@event, headers); }
protected Task On(AssetDeleted @event, EnvelopeHeaders headers) { return(Collection.DeleteOneAsync(x => x.Id == @event.AssetId)); }
public void On(RuleDeleted @event, EnvelopeHeaders headers) { Rules.Remove(@event.RuleId); }
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); }
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); }
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)); }
private static void SetCreated(EnvelopeHeaders headers, IMongoEntity entity) { entity.Created = headers.Timestamp(); }
public void On(SchemaDeleted @event, EnvelopeHeaders headers) { Schemas = Schemas.Remove(@event.SchemaId.Id); }
private static void SetLastModified(EnvelopeHeaders headers, IMongoEntity entity) { entity.LastModified = headers.Timestamp(); }
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)); }
protected Task On(FieldAdded @event, EnvelopeHeaders headers) { return(UpdateSchema(@event, headers, s => SchemaEventDispatcher.Dispatch(@event, s, registry))); }
public virtual bool ApplyEvent(IEvent @event, EnvelopeHeaders headers) { return(ApplyEvent(@event)); }
protected Task On(SchemaDeleted @event, EnvelopeHeaders headers) { return(Collection.UpdateAsync(@event, headers, e => e.IsDeleted = true)); }
private bool IsTooOld(EnvelopeHeaders headers) { var now = clock.GetCurrentInstant(); return(now - headers.Timestamp() > MaxAge); }
protected Task On(WebhookDeleted @event, EnvelopeHeaders headers) { return(Collection.UpdateAsync(@event, headers, e => { })); }
public static Guid AppId(this EnvelopeHeaders headers) { return(headers[SquidexHeaders.AppId].ToGuid(CultureInfo.InvariantCulture)); }
protected Task On(FieldEnabled @event, EnvelopeHeaders headers) { return(UpdateSchema(@event, headers, s => SchemaEventDispatcher.Dispatch(@event, s))); }
protected Task On(WebhookDeleted @event, EnvelopeHeaders headers) { return(UpdateSchema(@event, headers, s => s)); }
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); }
private static void SetId(EnvelopeHeaders headers, IMongoEntity entity) { entity.Id = headers.AggregateId(); }
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); }
protected Task On(AssetDeleted @event, EnvelopeHeaders headers) { return(UpdateSizeAsync(@event.AppId.Id, headers.Timestamp().ToDateTimeUtc().Date, [email protected], -1)); }