Ejemplo n.º 1
0
        protected Task On(AddLanguage command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <AppDomainObject>(context, a =>
            {
                GuardAppLanguages.CanAdd(a.Snapshot.LanguagesConfig, command);

                a.AddLanguage(command);
            }));
        }
Ejemplo n.º 2
0
        public override Task <CommandResult> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case CreateApp create:
                return(CreateReturn(create, c =>
                {
                    GuardApp.CanCreate(c);

                    Create(c);

                    return Snapshot;
                }));

            case UpdateApp update:
                return(UpdateReturn(update, c =>
                {
                    GuardApp.CanUpdate(c);

                    Update(c);

                    return Snapshot;
                }));

            case UpdateAppSettings updateSettings:
                return(UpdateReturn(updateSettings, c =>
                {
                    GuardApp.CanUpdateSettings(c);

                    UpdateSettings(c);

                    return Snapshot;
                }));

            case UploadAppImage uploadImage:
                return(UpdateReturn(uploadImage, c =>
                {
                    GuardApp.CanUploadImage(c);

                    UploadImage(c);

                    return Snapshot;
                }));

            case RemoveAppImage removeImage:
                return(UpdateReturn(removeImage, c =>
                {
                    GuardApp.CanRemoveImage(c);

                    RemoveImage(c);

                    return Snapshot;
                }));

            case ConfigureAssetScripts configureAssetScripts:
                return(UpdateReturn(configureAssetScripts, c =>
                {
                    GuardApp.CanUpdateAssetScripts(c);

                    ConfigureAssetScripts(c);

                    return Snapshot;
                }));

            case AssignContributor assignContributor:
                return(UpdateReturnAsync(assignContributor, async c =>
                {
                    await GuardAppContributors.CanAssign(c, Snapshot, userResolver, GetPlan());

                    AssignContributor(c, !Snapshot.Contributors.ContainsKey(assignContributor.ContributorId));

                    return Snapshot;
                }));

            case RemoveContributor removeContributor:
                return(UpdateReturn(removeContributor, c =>
                {
                    GuardAppContributors.CanRemove(c, Snapshot);

                    RemoveContributor(c);

                    return Snapshot;
                }));

            case AttachClient attachClient:
                return(UpdateReturn(attachClient, c =>
                {
                    GuardAppClients.CanAttach(c, Snapshot);

                    AttachClient(c);

                    return Snapshot;
                }));

            case UpdateClient updateClient:
                return(UpdateReturn(updateClient, c =>
                {
                    GuardAppClients.CanUpdate(c, Snapshot);

                    UpdateClient(c);

                    return Snapshot;
                }));

            case RevokeClient revokeClient:
                return(UpdateReturn(revokeClient, c =>
                {
                    GuardAppClients.CanRevoke(c, Snapshot);

                    RevokeClient(c);

                    return Snapshot;
                }));

            case AddWorkflow addWorkflow:
                return(UpdateReturn(addWorkflow, c =>
                {
                    GuardAppWorkflows.CanAdd(c);

                    AddWorkflow(c);

                    return Snapshot;
                }));

            case UpdateWorkflow updateWorkflow:
                return(UpdateReturn(updateWorkflow, c =>
                {
                    GuardAppWorkflows.CanUpdate(c, Snapshot);

                    UpdateWorkflow(c);

                    return Snapshot;
                }));

            case DeleteWorkflow deleteWorkflow:
                return(UpdateReturn(deleteWorkflow, c =>
                {
                    GuardAppWorkflows.CanDelete(c, Snapshot);

                    DeleteWorkflow(c);

                    return Snapshot;
                }));

            case AddLanguage addLanguage:
                return(UpdateReturn(addLanguage, c =>
                {
                    GuardAppLanguages.CanAdd(c, Snapshot);

                    AddLanguage(c);

                    return Snapshot;
                }));

            case RemoveLanguage removeLanguage:
                return(UpdateReturn(removeLanguage, c =>
                {
                    GuardAppLanguages.CanRemove(c, Snapshot);

                    RemoveLanguage(c);

                    return Snapshot;
                }));

            case UpdateLanguage updateLanguage:
                return(UpdateReturn(updateLanguage, c =>
                {
                    GuardAppLanguages.CanUpdate(c, Snapshot);

                    UpdateLanguage(c);

                    return Snapshot;
                }));

            case AddRole addRole:
                return(UpdateReturn(addRole, c =>
                {
                    GuardAppRoles.CanAdd(c, Snapshot);

                    AddRole(c);

                    return Snapshot;
                }));

            case DeleteRole deleteRole:
                return(UpdateReturn(deleteRole, c =>
                {
                    GuardAppRoles.CanDelete(c, Snapshot);

                    DeleteRole(c);

                    return Snapshot;
                }));

            case UpdateRole updateRole:
                return(UpdateReturn(updateRole, c =>
                {
                    GuardAppRoles.CanUpdate(c, Snapshot);

                    UpdateRole(c);

                    return Snapshot;
                }));

            case ChangePlan changePlan:
                return(UpdateReturnAsync(changePlan, async c =>
                {
                    GuardApp.CanChangePlan(c, Snapshot, appPlansProvider);

                    if (c.FromCallback)
                    {
                        ChangePlan(c);

                        return null;
                    }
                    else
                    {
                        var result =
                            await appPlansBillingManager.ChangePlanAsync(c.Actor.Identifier,
                                                                         Snapshot.NamedId(), c.PlanId, c.Referer);

                        switch (result)
                        {
                        case PlanChangedResult:
                            ChangePlan(c);
                            break;
                        }

                        return result;
                    }
                }));

            case DeleteApp delete:
                return(UpdateAsync(delete, async c =>
                {
                    await appPlansBillingManager.ChangePlanAsync(c.Actor.Identifier, Snapshot.NamedId(), null, null);

                    DeleteApp(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 3
0
        protected override Task <object> ExecuteAsync(IAggregateCommand command)
        {
            VerifyNotArchived();

            switch (command)
            {
            case CreateApp createApp:
                return(CreateReturn(createApp, c =>
                {
                    GuardApp.CanCreate(c);

                    Create(c);

                    return Snapshot;
                }));

            case AssignContributor assignContributor:
                return(UpdateReturnAsync(assignContributor, async c =>
                {
                    await GuardAppContributors.CanAssign(Snapshot.Contributors, Snapshot.Roles, c, userResolver, GetPlan());

                    AssignContributor(c, !Snapshot.Contributors.ContainsKey(assignContributor.ContributorId));

                    return Snapshot;
                }));

            case RemoveContributor removeContributor:
                return(UpdateReturn(removeContributor, c =>
                {
                    GuardAppContributors.CanRemove(Snapshot.Contributors, c);

                    RemoveContributor(c);

                    return Snapshot;
                }));

            case AttachClient attachClient:
                return(UpdateReturn(attachClient, c =>
                {
                    GuardAppClients.CanAttach(Snapshot.Clients, c);

                    AttachClient(c);

                    return Snapshot;
                }));

            case UpdateClient updateClient:
                return(UpdateReturn(updateClient, c =>
                {
                    GuardAppClients.CanUpdate(Snapshot.Clients, c, Snapshot.Roles);

                    UpdateClient(c);

                    return Snapshot;
                }));

            case RevokeClient revokeClient:
                return(UpdateReturn(revokeClient, c =>
                {
                    GuardAppClients.CanRevoke(Snapshot.Clients, c);

                    RevokeClient(c);

                    return Snapshot;
                }));

            case AddLanguage addLanguage:
                return(UpdateReturn(addLanguage, c =>
                {
                    GuardAppLanguages.CanAdd(Snapshot.LanguagesConfig, c);

                    AddLanguage(c);

                    return Snapshot;
                }));

            case RemoveLanguage removeLanguage:
                return(UpdateReturn(removeLanguage, c =>
                {
                    GuardAppLanguages.CanRemove(Snapshot.LanguagesConfig, c);

                    RemoveLanguage(c);

                    return Snapshot;
                }));

            case UpdateLanguage updateLanguage:
                return(UpdateReturn(updateLanguage, c =>
                {
                    GuardAppLanguages.CanUpdate(Snapshot.LanguagesConfig, c);

                    UpdateLanguage(c);

                    return Snapshot;
                }));

            case AddRole addRole:
                return(UpdateReturn(addRole, c =>
                {
                    GuardAppRoles.CanAdd(Snapshot.Roles, c);

                    AddRole(c);

                    return Snapshot;
                }));

            case DeleteRole deleteRole:
                return(UpdateReturn(deleteRole, c =>
                {
                    GuardAppRoles.CanDelete(Snapshot.Roles, c, Snapshot.Contributors, Snapshot.Clients);

                    DeleteRole(c);

                    return Snapshot;
                }));

            case UpdateRole updateRole:
                return(UpdateReturn(updateRole, c =>
                {
                    GuardAppRoles.CanUpdate(Snapshot.Roles, c);

                    UpdateRole(c);

                    return Snapshot;
                }));

            case AddPattern addPattern:
                return(UpdateReturn(addPattern, c =>
                {
                    GuardAppPatterns.CanAdd(Snapshot.Patterns, c);

                    AddPattern(c);

                    return Snapshot;
                }));

            case DeletePattern deletePattern:
                return(UpdateReturn(deletePattern, c =>
                {
                    GuardAppPatterns.CanDelete(Snapshot.Patterns, c);

                    DeletePattern(c);

                    return Snapshot;
                }));

            case UpdatePattern updatePattern:
                return(UpdateReturn(updatePattern, c =>
                {
                    GuardAppPatterns.CanUpdate(Snapshot.Patterns, c);

                    UpdatePattern(c);

                    return Snapshot;
                }));

            case ChangePlan changePlan:
                return(UpdateReturnAsync(changePlan, async c =>
                {
                    GuardApp.CanChangePlan(c, Snapshot.Plan, appPlansProvider);

                    if (c.FromCallback)
                    {
                        ChangePlan(c);

                        return null;
                    }
                    else
                    {
                        var result = await appPlansBillingManager.ChangePlanAsync(c.Actor.Identifier, Snapshot.NamedId(), c.PlanId);

                        switch (result)
                        {
                        case PlanChangedResult _:
                            ChangePlan(c);
                            break;

                        case PlanResetResult _:
                            ResetPlan(c);
                            break;
                        }

                        return result;
                    }
                }));

            case ArchiveApp archiveApp:
                return(UpdateAsync(archiveApp, async c =>
                {
                    await appPlansBillingManager.ChangePlanAsync(c.Actor.Identifier, Snapshot.NamedId(), null);

                    ArchiveApp(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 4
0
        public override Task <object> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case CreateApp createApp:
                return(CreateAsync(createApp, async c =>
                {
                    await GuardApp.CanCreate(c, appProvider);

                    Create(c);
                }));

            case AssignContributor assigneContributor:
                return(UpdateAsync(assigneContributor, async c =>
                {
                    await GuardAppContributors.CanAssign(Snapshot.Contributors, c, userResolver, appPlansProvider.GetPlan(Snapshot.Plan?.PlanId));

                    AssignContributor(c);
                }));

            case RemoveContributor removeContributor:
                return(UpdateAsync(removeContributor, c =>
                {
                    GuardAppContributors.CanRemove(Snapshot.Contributors, c);

                    RemoveContributor(c);
                }));

            case AttachClient attachClient:
                return(UpdateAsync(attachClient, c =>
                {
                    GuardAppClients.CanAttach(Snapshot.Clients, c);

                    AttachClient(c);
                }));

            case UpdateClient updateClient:
                return(UpdateAsync(updateClient, c =>
                {
                    GuardAppClients.CanUpdate(Snapshot.Clients, c);

                    UpdateClient(c);
                }));

            case RevokeClient revokeClient:
                return(UpdateAsync(revokeClient, c =>
                {
                    GuardAppClients.CanRevoke(Snapshot.Clients, c);

                    RevokeClient(c);
                }));

            case AddLanguage addLanguage:
                return(UpdateAsync(addLanguage, c =>
                {
                    GuardAppLanguages.CanAdd(Snapshot.LanguagesConfig, c);

                    AddLanguage(c);
                }));

            case RemoveLanguage removeLanguage:
                return(UpdateAsync(removeLanguage, c =>
                {
                    GuardAppLanguages.CanRemove(Snapshot.LanguagesConfig, c);

                    RemoveLanguage(c);
                }));

            case UpdateLanguage updateLanguage:
                return(UpdateAsync(updateLanguage, c =>
                {
                    GuardAppLanguages.CanUpdate(Snapshot.LanguagesConfig, c);

                    UpdateLanguage(c);
                }));

            case AddPattern addPattern:
                return(UpdateAsync(addPattern, c =>
                {
                    GuardAppPattern.CanAdd(Snapshot.Patterns, c);

                    AddPattern(c);
                }));

            case DeletePattern deletePattern:
                return(UpdateAsync(deletePattern, c =>
                {
                    GuardAppPattern.CanDelete(Snapshot.Patterns, c);

                    DeletePattern(c);
                }));

            case UpdatePattern updatePattern:
                return(UpdateAsync(updatePattern, c =>
                {
                    GuardAppPattern.CanUpdate(Snapshot.Patterns, c);

                    UpdatePattern(c);
                }));

            case ChangePlan changePlan:
                return(UpdateReturnAsync(changePlan, async c =>
                {
                    GuardApp.CanChangePlan(c, Snapshot.Plan, appPlansProvider);

                    if (c.FromCallback)
                    {
                        ChangePlan(c);

                        return null;
                    }
                    else
                    {
                        var result = await appPlansBillingManager.ChangePlanAsync(c.Actor.Identifier, Snapshot.Id, Snapshot.Name, c.PlanId);

                        if (result is PlanChangedResult)
                        {
                            ChangePlan(c);
                        }

                        return result;
                    }
                }));

            default:
                throw new NotSupportedException();
            }
        }