Browse Source

Simplified grains.

pull/363/head
Sebastian Stehle 7 years ago
parent
commit
540e7ee043
  1. 61
      src/Squidex.Domain.Apps.Entities/Apps/AppGrain.cs
  2. 13
      src/Squidex.Domain.Apps.Entities/Assets/AssetGrain.cs
  3. 6
      src/Squidex.Domain.Apps.Entities/Comments/CommentsGrain.cs
  4. 29
      src/Squidex.Domain.Apps.Entities/Contents/ContentGrain.cs
  5. 19
      src/Squidex.Domain.Apps.Entities/Rules/RuleGrain.cs
  6. 71
      src/Squidex.Domain.Apps.Entities/Schemas/SchemaGrain.cs
  7. 12
      src/Squidex.Infrastructure/Commands/DomainObjectGrainBase.cs
  8. 8
      tests/Squidex.Infrastructure.Tests/Commands/DomainObjectGrainTests.cs
  9. 8
      tests/Squidex.Infrastructure.Tests/Commands/LogSnapshotDomainObjectGrainTests.cs
  10. 8
      tests/Squidex.Infrastructure.Tests/TestHelpers/MyDomainObject.cs

61
src/Squidex.Domain.Apps.Entities/Apps/AppGrain.cs

@ -66,7 +66,7 @@ namespace Squidex.Domain.Apps.Entities.Apps
Create(c);
return await GetRawStateAsync();
return Snapshot;
});
case AssignContributor assignContributor:
@ -76,137 +76,137 @@ namespace Squidex.Domain.Apps.Entities.Apps
AssignContributor(c, !Snapshot.Contributors.ContainsKey(assignContributor.ContributorId));
return await GetRawStateAsync();
return Snapshot;
});
case RemoveContributor removeContributor:
return UpdateReturnAsync(removeContributor, async c =>
return UpdateReturn(removeContributor, c =>
{
GuardAppContributors.CanRemove(Snapshot.Contributors, c);
RemoveContributor(c);
return await GetRawStateAsync();
return Snapshot;
});
case AttachClient attachClient:
return UpdateReturnAsync(attachClient, async c =>
return UpdateReturn(attachClient, c =>
{
GuardAppClients.CanAttach(Snapshot.Clients, c);
AttachClient(c);
return await GetRawStateAsync();
return Snapshot;
});
case UpdateClient updateClient:
return UpdateReturnAsync(updateClient, async c =>
return UpdateReturn(updateClient, c =>
{
GuardAppClients.CanUpdate(Snapshot.Clients, c, Snapshot.Roles);
UpdateClient(c);
return await GetRawStateAsync();
return Snapshot;
});
case RevokeClient revokeClient:
return UpdateReturnAsync(revokeClient, async c =>
return UpdateReturn(revokeClient, c =>
{
GuardAppClients.CanRevoke(Snapshot.Clients, c);
RevokeClient(c);
return await GetRawStateAsync();
return Snapshot;
});
case AddLanguage addLanguage:
return UpdateReturnAsync(addLanguage, async c =>
return UpdateReturn(addLanguage, c =>
{
GuardAppLanguages.CanAdd(Snapshot.LanguagesConfig, c);
AddLanguage(c);
return await GetRawStateAsync();
return Snapshot;
});
case RemoveLanguage removeLanguage:
return UpdateReturnAsync(removeLanguage, async c =>
return UpdateReturn(removeLanguage, c =>
{
GuardAppLanguages.CanRemove(Snapshot.LanguagesConfig, c);
RemoveLanguage(c);
return await GetRawStateAsync();
return Snapshot;
});
case UpdateLanguage updateLanguage:
return UpdateReturnAsync(updateLanguage, async c =>
return UpdateReturn(updateLanguage, c =>
{
GuardAppLanguages.CanUpdate(Snapshot.LanguagesConfig, c);
UpdateLanguage(c);
return await GetRawStateAsync();
return Snapshot;
});
case AddRole addRole:
return UpdateReturnAsync(addRole, async c =>
return UpdateReturn(addRole, c =>
{
GuardAppRoles.CanAdd(Snapshot.Roles, c);
AddRole(c);
return await GetRawStateAsync();
return Snapshot;
});
case DeleteRole deleteRole:
return UpdateReturnAsync(deleteRole, async c =>
return UpdateReturn(deleteRole, c =>
{
GuardAppRoles.CanDelete(Snapshot.Roles, c, Snapshot.Contributors, Snapshot.Clients);
DeleteRole(c);
return await GetRawStateAsync();
return Snapshot;
});
case UpdateRole updateRole:
return UpdateReturnAsync(updateRole, async c =>
return UpdateReturn(updateRole, c =>
{
GuardAppRoles.CanUpdate(Snapshot.Roles, c);
UpdateRole(c);
return await GetRawStateAsync();
return Snapshot;
});
case AddPattern addPattern:
return UpdateReturnAsync(addPattern, async c =>
return UpdateReturn(addPattern, c =>
{
GuardAppPatterns.CanAdd(Snapshot.Patterns, c);
AddPattern(c);
return await GetRawStateAsync();
return Snapshot;
});
case DeletePattern deletePattern:
return UpdateReturnAsync(deletePattern, async c =>
return UpdateReturn(deletePattern, c =>
{
GuardAppPatterns.CanDelete(Snapshot.Patterns, c);
DeletePattern(c);
return await GetRawStateAsync();
return Snapshot;
});
case UpdatePattern updatePattern:
return UpdateReturnAsync(updatePattern, async c =>
return UpdateReturn(updatePattern, c =>
{
GuardAppPatterns.CanUpdate(Snapshot.Patterns, c);
UpdatePattern(c);
return await GetRawStateAsync();
return Snapshot;
});
case ChangePlan changePlan:
@ -412,11 +412,6 @@ namespace Squidex.Domain.Apps.Entities.Apps
return new AppContributorAssigned { ContributorId = actor.Identifier, Role = Role.Owner };
}
public Task<IAppEntity> GetRawStateAsync()
{
return Task.FromResult<IAppEntity>(Snapshot);
}
public Task<J<IAppEntity>> GetStateAsync()
{
return J.AsTask<IAppEntity>(Snapshot);

13
src/Squidex.Domain.Apps.Entities/Assets/AssetGrain.cs

@ -51,16 +51,16 @@ namespace Squidex.Domain.Apps.Entities.Assets
Create(c, tagIds);
return await GetRawStateAsync();
return Snapshot;
});
case UpdateAsset updateRule:
return UpdateReturnAsync(updateRule, async c =>
return UpdateReturn(updateRule, c =>
{
GuardAsset.CanUpdate(c);
Update(c);
return await GetRawStateAsync();
return Snapshot;
});
case AnnotateAsset annotateAsset:
return UpdateReturnAsync(annotateAsset, async c =>
@ -71,7 +71,7 @@ namespace Squidex.Domain.Apps.Entities.Assets
Annotate(c, tagIds);
return await GetRawStateAsync();
return Snapshot;
});
case DeleteAsset deleteAsset:
return UpdateAsync(deleteAsset, async c =>
@ -165,11 +165,6 @@ namespace Squidex.Domain.Apps.Entities.Assets
}
}
public Task<IAssetEntity> GetRawStateAsync()
{
return Task.FromResult<IAssetEntity>(Snapshot);
}
public Task<J<IAssetEntity>> GetStateAsync(long version = EtagVersion.Any)
{
return J.AsTask<IAssetEntity>(GetSnapshot(version));

6
src/Squidex.Domain.Apps.Entities/Comments/CommentsGrain.cs

@ -73,7 +73,7 @@ namespace Squidex.Domain.Apps.Entities.Comments
switch (command)
{
case CreateComment createComment:
return UpsertAsync(createComment, c =>
return UpsertReturn(createComment, c =>
{
GuardComments.CanCreate(c);
@ -83,7 +83,7 @@ namespace Squidex.Domain.Apps.Entities.Comments
});
case UpdateComment updateComment:
return UpsertAsync(updateComment, c =>
return Upsert(updateComment, c =>
{
GuardComments.CanUpdate(events, c);
@ -91,7 +91,7 @@ namespace Squidex.Domain.Apps.Entities.Comments
});
case DeleteComment deleteComment:
return UpsertAsync(deleteComment, c =>
return Upsert(deleteComment, c =>
{
GuardComments.CanDelete(events, c);

29
src/Squidex.Domain.Apps.Entities/Contents/ContentGrain.cs

@ -81,7 +81,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
Create(c);
return await GetRawStateAsync();
return Snapshot;
});
case UpdateContent updateContent:
@ -158,7 +158,17 @@ namespace Squidex.Domain.Apps.Entities.Contents
}
}
return await GetRawStateAsync();
return Snapshot;
});
case DiscardChanges discardChanges:
return UpdateReturn(discardChanges, c =>
{
GuardContent.CanDiscardChanges(Snapshot.IsPending, c);
DiscardChanges(c);
return Snapshot;
});
case DeleteContent deleteContent:
@ -173,16 +183,6 @@ namespace Squidex.Domain.Apps.Entities.Contents
Delete(c);
});
case DiscardChanges discardChanges:
return UpdateReturnAsync(discardChanges, async c =>
{
GuardContent.CanDiscardChanges(Snapshot.IsPending, c);
DiscardChanges(c);
return await GetRawStateAsync();
});
default:
throw new NotSupportedException();
}
@ -309,11 +309,6 @@ namespace Squidex.Domain.Apps.Entities.Contents
return operationContext;
}
public Task<IContentEntity> GetRawStateAsync()
{
return Task.FromResult<IContentEntity>(Snapshot);
}
public Task<J<IContentEntity>> GetStateAsync(long version = EtagVersion.Any)
{
return J.AsTask<IContentEntity>(GetSnapshot(version));

19
src/Squidex.Domain.Apps.Entities/Rules/RuleGrain.cs

@ -47,7 +47,7 @@ namespace Squidex.Domain.Apps.Entities.Rules
Create(c);
return await GetRawStateAsync();
return Snapshot;
});
case UpdateRule updateRule:
return UpdateReturnAsync(updateRule, async c =>
@ -56,28 +56,28 @@ namespace Squidex.Domain.Apps.Entities.Rules
Update(c);
return await GetRawStateAsync();
return Snapshot;
});
case EnableRule enableRule:
return UpdateReturnAsync(enableRule, async c =>
return UpdateReturn(enableRule, c =>
{
GuardRule.CanEnable(c, Snapshot.RuleDef);
Enable(c);
return await GetRawStateAsync();
return Snapshot;
});
case DisableRule disableRule:
return UpdateReturnAsync(disableRule, async c =>
return UpdateReturn(disableRule, c =>
{
GuardRule.CanDisable(c, Snapshot.RuleDef);
Disable(c);
return await GetRawStateAsync();
return Snapshot;
});
case DeleteRule deleteRule:
return UpdateAsync(deleteRule, c =>
return Update(deleteRule, c =>
{
GuardRule.CanDelete(deleteRule);
@ -131,11 +131,6 @@ namespace Squidex.Domain.Apps.Entities.Rules
}
}
public Task<IRuleEntity> GetRawStateAsync()
{
return Task.FromResult<IRuleEntity>(Snapshot);
}
public Task<J<IRuleEntity>> GetStateAsync()
{
return J.AsTask<IRuleEntity>(Snapshot);

71
src/Squidex.Domain.Apps.Entities/Schemas/SchemaGrain.cs

@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas
id = ((IArrayField)Snapshot.SchemaDef.FieldsById[c.ParentFieldId.Value]).FieldsByName[c.Name].Id;
}
return await GetRawStateAsync();
return Snapshot;
});
case CreateSchema createSchema:
@ -75,161 +75,161 @@ namespace Squidex.Domain.Apps.Entities.Schemas
Create(c);
return await GetRawStateAsync();
return Snapshot;
});
case SynchronizeSchema synchronizeSchema:
return UpdateReturnAsync(synchronizeSchema, async c =>
return UpdateReturn(synchronizeSchema, c =>
{
GuardSchema.CanSynchronize(c);
Synchronize(c);
return await GetRawStateAsync();
return Snapshot;
});
case DeleteField deleteField:
return UpdateReturnAsync(deleteField, async c =>
return UpdateReturn(deleteField, c =>
{
GuardSchemaField.CanDelete(Snapshot.SchemaDef, deleteField);
DeleteField(c);
return await GetRawStateAsync();
return Snapshot;
});
case LockField lockField:
return UpdateReturnAsync(lockField, async c =>
return UpdateReturn(lockField, c =>
{
GuardSchemaField.CanLock(Snapshot.SchemaDef, lockField);
LockField(c);
return await GetRawStateAsync();
return Snapshot;
});
case HideField hideField:
return UpdateReturnAsync(hideField, async c =>
return UpdateReturn(hideField, c =>
{
GuardSchemaField.CanHide(Snapshot.SchemaDef, c);
HideField(c);
return await GetRawStateAsync();
return Snapshot;
});
case ShowField showField:
return UpdateReturnAsync(showField, async c =>
return UpdateReturn(showField, c =>
{
GuardSchemaField.CanShow(Snapshot.SchemaDef, c);
ShowField(c);
return await GetRawStateAsync();
return Snapshot;
});
case DisableField disableField:
return UpdateReturnAsync(disableField, async c =>
return UpdateReturn(disableField, c =>
{
GuardSchemaField.CanDisable(Snapshot.SchemaDef, c);
DisableField(c);
return await GetRawStateAsync();
return Snapshot;
});
case EnableField enableField:
return UpdateReturnAsync(enableField, async c =>
return UpdateReturn(enableField, c =>
{
GuardSchemaField.CanEnable(Snapshot.SchemaDef, c);
EnableField(c);
return await GetRawStateAsync();
return Snapshot;
});
case UpdateField updateField:
return UpdateReturnAsync(updateField, async c =>
return UpdateReturn(updateField, c =>
{
GuardSchemaField.CanUpdate(Snapshot.SchemaDef, c);
UpdateField(c);
return await GetRawStateAsync();
return Snapshot;
});
case ReorderFields reorderFields:
return UpdateReturnAsync(reorderFields, async c =>
return UpdateReturn(reorderFields, c =>
{
GuardSchema.CanReorder(Snapshot.SchemaDef, c);
Reorder(c);
return await GetRawStateAsync();
return Snapshot;
});
case UpdateSchema updateSchema:
return UpdateReturnAsync(updateSchema, async c =>
return UpdateReturn(updateSchema, c =>
{
GuardSchema.CanUpdate(Snapshot.SchemaDef, c);
Update(c);
return await GetRawStateAsync();
return Snapshot;
});
case PublishSchema publishSchema:
return UpdateReturnAsync(publishSchema, async c =>
return UpdateReturn(publishSchema, c =>
{
GuardSchema.CanPublish(Snapshot.SchemaDef, c);
Publish(c);
return await GetRawStateAsync();
return Snapshot;
});
case UnpublishSchema unpublishSchema:
return UpdateReturnAsync(unpublishSchema, async c =>
return UpdateReturn(unpublishSchema, c =>
{
GuardSchema.CanUnpublish(Snapshot.SchemaDef, c);
Unpublish(c);
return await GetRawStateAsync();
return Snapshot;
});
case ConfigureScripts configureScripts:
return UpdateReturnAsync(configureScripts, async c =>
return UpdateReturn(configureScripts, c =>
{
GuardSchema.CanConfigureScripts(Snapshot.SchemaDef, c);
ConfigureScripts(c);
return await GetRawStateAsync();
return Snapshot;
});
case ChangeCategory changeCategory:
return UpdateReturnAsync(changeCategory, async c =>
return UpdateReturn(changeCategory, c =>
{
GuardSchema.CanChangeCategory(Snapshot.SchemaDef, c);
ChangeCategory(c);
return await GetRawStateAsync();
return Snapshot;
});
case ConfigurePreviewUrls configurePreviewUrls:
return UpdateReturnAsync(configurePreviewUrls, async c =>
return UpdateReturn(configurePreviewUrls, c =>
{
GuardSchema.CanConfigurePreviewUrls(c);
ConfigurePreviewUrls(c);
return await GetRawStateAsync();
return Snapshot;
});
case DeleteSchema deleteSchema:
return UpdateAsync(deleteSchema, c =>
return Update(deleteSchema, c =>
{
GuardSchema.CanDelete(Snapshot.SchemaDef, c);
@ -413,11 +413,6 @@ namespace Squidex.Domain.Apps.Entities.Schemas
}
}
public Task<ISchemaEntity> GetRawStateAsync()
{
return Task.FromResult<ISchemaEntity>(Snapshot);
}
public Task<J<ISchemaEntity>> GetStateAsync()
{
return J.AsTask<ISchemaEntity>(Snapshot);

12
src/Squidex.Infrastructure/Commands/DomainObjectGrainBase.cs

@ -93,7 +93,7 @@ namespace Squidex.Infrastructure.Commands
return InvokeAsync(command, handler, Mode.Create);
}
protected Task<object> CreateReturnAsync<TCommand>(TCommand command, Func<TCommand, object> handler) where TCommand : class, IAggregateCommand
protected Task<object> CreateReturn<TCommand>(TCommand command, Func<TCommand, object> handler) where TCommand : class, IAggregateCommand
{
return InvokeAsync(command, handler?.ToAsync(), Mode.Create);
}
@ -103,7 +103,7 @@ namespace Squidex.Infrastructure.Commands
return InvokeAsync(command, handler.ToDefault<TCommand, object>(), Mode.Create);
}
protected Task<object> CreateAsync<TCommand>(TCommand command, Action<TCommand> handler) where TCommand : class, IAggregateCommand
protected Task<object> Create<TCommand>(TCommand command, Action<TCommand> handler) where TCommand : class, IAggregateCommand
{
return InvokeAsync(command, handler?.ToDefault<TCommand, object>()?.ToAsync(), Mode.Create);
}
@ -113,7 +113,7 @@ namespace Squidex.Infrastructure.Commands
return InvokeAsync(command, handler, Mode.Update);
}
protected Task<object> UpdateAsync<TCommand>(TCommand command, Func<TCommand, object> handler) where TCommand : class, IAggregateCommand
protected Task<object> UpdateReturn<TCommand>(TCommand command, Func<TCommand, object> handler) where TCommand : class, IAggregateCommand
{
return InvokeAsync(command, handler?.ToAsync(), Mode.Update);
}
@ -123,7 +123,7 @@ namespace Squidex.Infrastructure.Commands
return InvokeAsync(command, handler?.ToDefault<TCommand, object>(), Mode.Update);
}
protected Task<object> UpdateAsync<TCommand>(TCommand command, Action<TCommand> handler) where TCommand : class, IAggregateCommand
protected Task<object> Update<TCommand>(TCommand command, Action<TCommand> handler) where TCommand : class, IAggregateCommand
{
return InvokeAsync(command, handler?.ToDefault<TCommand, object>()?.ToAsync(), Mode.Update);
}
@ -133,7 +133,7 @@ namespace Squidex.Infrastructure.Commands
return InvokeAsync(command, handler, Mode.Upsert);
}
protected Task<object> UpsertAsync<TCommand>(TCommand command, Func<TCommand, object> handler) where TCommand : class, IAggregateCommand
protected Task<object> UpsertReturn<TCommand>(TCommand command, Func<TCommand, object> handler) where TCommand : class, IAggregateCommand
{
return InvokeAsync(command, handler?.ToAsync(), Mode.Upsert);
}
@ -143,7 +143,7 @@ namespace Squidex.Infrastructure.Commands
return InvokeAsync(command, handler?.ToDefault<TCommand, object>(), Mode.Upsert);
}
protected Task<object> UpsertAsync<TCommand>(TCommand command, Action<TCommand> handler) where TCommand : class, IAggregateCommand
protected Task<object> Upsert<TCommand>(TCommand command, Action<TCommand> handler) where TCommand : class, IAggregateCommand
{
return InvokeAsync(command, handler?.ToDefault<TCommand, object>()?.ToAsync(), Mode.Upsert);
}

8
tests/Squidex.Infrastructure.Tests/Commands/DomainObjectGrainTests.cs

@ -38,13 +38,13 @@ namespace Squidex.Infrastructure.Commands
switch (command)
{
case CreateAuto createAuto:
return CreateAsync(createAuto, c =>
return Create(createAuto, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });
});
case CreateCustom createCustom:
return CreateReturnAsync(createCustom, c =>
return CreateReturn(createCustom, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });
@ -52,13 +52,13 @@ namespace Squidex.Infrastructure.Commands
});
case UpdateAuto updateAuto:
return UpdateAsync(updateAuto, c =>
return Update(updateAuto, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });
});
case UpdateCustom updateCustom:
return UpdateAsync(updateCustom, c =>
return UpdateReturn(updateCustom, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });

8
tests/Squidex.Infrastructure.Tests/Commands/LogSnapshotDomainObjectGrainTests.cs

@ -40,13 +40,13 @@ namespace Squidex.Infrastructure.Commands
switch (command)
{
case CreateAuto createAuto:
return CreateAsync(createAuto, c =>
return Create(createAuto, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });
});
case CreateCustom createCustom:
return CreateReturnAsync(createCustom, c =>
return CreateReturn(createCustom, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });
@ -54,13 +54,13 @@ namespace Squidex.Infrastructure.Commands
});
case UpdateAuto updateAuto:
return UpdateAsync(updateAuto, c =>
return Update(updateAuto, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });
});
case UpdateCustom updateCustom:
return UpdateAsync(updateCustom, c =>
return UpdateReturn(updateCustom, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });

8
tests/Squidex.Infrastructure.Tests/TestHelpers/MyDomainObject.cs

@ -26,13 +26,13 @@ namespace Squidex.Infrastructure.TestHelpers
switch (command)
{
case CreateAuto createAuto:
return CreateAsync(createAuto, c =>
return Create(createAuto, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });
});
case CreateCustom createCustom:
return CreateReturnAsync(createCustom, c =>
return CreateReturn(createCustom, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });
@ -40,13 +40,13 @@ namespace Squidex.Infrastructure.TestHelpers
});
case UpdateAuto updateAuto:
return UpdateAsync(updateAuto, c =>
return Update(updateAuto, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });
});
case UpdateCustom updateCustom:
return UpdateAsync(updateCustom, c =>
return UpdateReturn(updateCustom, c =>
{
RaiseEvent(new ValueChanged { Value = c.Value });

Loading…
Cancel
Save