|
|
|
@ -7,7 +7,6 @@ |
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Squidex.Domain.Apps.Core.Schemas; |
|
|
|
using Squidex.Domain.Apps.Events; |
|
|
|
@ -15,7 +14,6 @@ using Squidex.Domain.Apps.Events.Schemas; |
|
|
|
using Squidex.Domain.Apps.Events.Schemas.Old; |
|
|
|
using Squidex.Domain.Apps.Events.Schemas.Utils; |
|
|
|
using Squidex.Domain.Apps.Read.MongoDb.Utils; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
using Squidex.Infrastructure.CQRS.Events; |
|
|
|
using Squidex.Infrastructure.Dispatching; |
|
|
|
using Squidex.Infrastructure.Reflection; |
|
|
|
@ -26,8 +24,6 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Schemas |
|
|
|
{ |
|
|
|
public partial class MongoSchemaRepository |
|
|
|
{ |
|
|
|
private readonly List<Action<NamedId<Guid>, NamedId<Guid>>> subscribers = new List<Action<NamedId<Guid>, NamedId<Guid>>>(); |
|
|
|
|
|
|
|
public string Name |
|
|
|
{ |
|
|
|
get { return GetType().Name; } |
|
|
|
@ -38,11 +34,6 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Schemas |
|
|
|
get { return "^schema-"; } |
|
|
|
} |
|
|
|
|
|
|
|
public void SubscribeOnChanged(Action<NamedId<Guid>, NamedId<Guid>> subscriber) |
|
|
|
{ |
|
|
|
subscribers.Add(subscriber); |
|
|
|
} |
|
|
|
|
|
|
|
public Task On(Envelope<IEvent> @event) |
|
|
|
{ |
|
|
|
return this.DispatchActionAsync(@event.Payload, @event.Headers); |
|
|
|
@ -52,7 +43,7 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Schemas |
|
|
|
{ |
|
|
|
var schema = SchemaEventDispatcher.Dispatch(@event, registry); |
|
|
|
|
|
|
|
return Collection.CreateAsync(@event, headers, s => { s.SchemaDef = schema; SimpleMapper.Map(@event, s); }); |
|
|
|
return Collection.CreateAsync(@event, headers, s => { UpdateSchema(s, schema); SimpleMapper.Map(@event, s); }); |
|
|
|
} |
|
|
|
|
|
|
|
protected Task On(FieldDeleted @event, EnvelopeHeaders headers) |
|
|
|
@ -125,30 +116,29 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Schemas |
|
|
|
return Collection.UpdateAsync(@event, headers, e => e.IsDeleted = true); |
|
|
|
} |
|
|
|
|
|
|
|
protected Task On(WebhookAdded @event, EnvelopeHeaders headers) |
|
|
|
private Task UpdateSchema(SquidexEvent @event, EnvelopeHeaders headers, Func<Schema, Schema> updater) |
|
|
|
{ |
|
|
|
return Collection.UpdateAsync(@event, headers, e => { }); |
|
|
|
return Collection.UpdateAsync(@event, headers, e => UpdateSchema(e, updater)); |
|
|
|
} |
|
|
|
|
|
|
|
protected Task On(WebhookDeleted @event, EnvelopeHeaders headers) |
|
|
|
private void UpdateSchema(MongoSchemaEntity entity, Func<Schema, Schema> updater) |
|
|
|
{ |
|
|
|
return Collection.UpdateAsync(@event, headers, e => { }); |
|
|
|
entity.UpdateSchema(serializer, updater); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task UpdateSchema(SchemaEvent @event, EnvelopeHeaders headers, Func<Schema, Schema> updater = null) |
|
|
|
private void UpdateSchema(MongoSchemaEntity entity, Schema schema) |
|
|
|
{ |
|
|
|
await Collection.UpdateAsync(@event, headers, e => |
|
|
|
{ |
|
|
|
if (updater != null) |
|
|
|
{ |
|
|
|
e.SchemaDef = updater(e.SchemaDef); |
|
|
|
} |
|
|
|
}); |
|
|
|
entity.SerializeSchema(schema, serializer); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var subscriber in subscribers) |
|
|
|
{ |
|
|
|
subscriber(@event.AppId, @event.SchemaId); |
|
|
|
} |
|
|
|
protected Task On(WebhookAdded @event, EnvelopeHeaders headers) |
|
|
|
{ |
|
|
|
return Collection.UpdateAsync(@event, headers, e => { }); |
|
|
|
} |
|
|
|
|
|
|
|
protected Task On(WebhookDeleted @event, EnvelopeHeaders headers) |
|
|
|
{ |
|
|
|
return Collection.UpdateAsync(@event, headers, e => { }); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|