public override bool ApplyEvent(IEvent @event)
        {
            switch (@event)
            {
            case AssetFolderCreated e:
            {
                SimpleMapper.Map(e, this);

                return(true);
            }

            case AssetFolderRenamed e when Is.OptionalChange(FolderName, e.FolderName):
            {
                FolderName = e.FolderName;

                return(true);
            }

            case AssetFolderMoved e when Is.Change(ParentId, e.ParentId):
            {
                ParentId = e.ParentId;

                return(true);
            }

            case AssetFolderDeleted _:
            {
                IsDeleted = true;

                return(true);
            }
            }

            return(false);
        }
Example #2
0
            public override bool ApplyEvent(IEvent @event)
            {
                switch (@event)
                {
                case AppCreated e:
                {
                    Id = e.AppId.Id;

                    SimpleMapper.Map(e, this);

                    return(true);
                }

                case AppUpdated e when Is.Change(Label, e.Label) || Is.Change(Description, e.Description):
                {
                    SimpleMapper.Map(e, this);

                    return(true);
                }

                case AppSettingsUpdated e when Is.Change(Settings, e.Settings):
                    return(UpdateSettings(e.Settings));

                case AppPlanChanged e when Is.Change(Plan?.PlanId, e.PlanId):
                    return(UpdatePlan(e.ToPlan()));

                case AppAssetsScriptsConfigured e when Is.Change(e.Scripts, AssetScripts):
                    return(UpdateAssetScripts(e.Scripts));

                case AppPlanReset e when Plan != null:
                    return(UpdatePlan(null));

                case AppImageUploaded e:
                    return(UpdateImage(e.Image));

                case AppImageRemoved e when Image != null:
                    return(UpdateImage(null));

                case AppContributorAssigned e:
                    return(UpdateContributors(e, (e, c) => c.Assign(e.ContributorId, e.Role)));

                case AppContributorRemoved e:
                    return(UpdateContributors(e, (e, c) => c.Remove(e.ContributorId)));

                case AppClientAttached e:
                    return(UpdateClients(e, (e, c) => c.Add(e.Id, e.Secret)));

                case AppClientUpdated e:
                    return(UpdateClients(e, (e, c) => c.Update(e.Id, e.Name, e.Role, e.ApiCallsLimit, e.ApiTrafficLimit, e.AllowAnonymous)));

                case AppClientRevoked e:
                    return(UpdateClients(e, (e, c) => c.Revoke(e.Id)));

                case AppWorkflowAdded e:
                    return(UpdateWorkflows(e, (e, w) => w.Add(e.WorkflowId, e.Name)));

                case AppWorkflowUpdated e:
                    return(UpdateWorkflows(e, (e, w) => w.Update(e.WorkflowId, e.Workflow)));

                case AppWorkflowDeleted e:
                    return(UpdateWorkflows(e, (e, w) => w.Remove(e.WorkflowId)));

                case AppRoleAdded e:
                    return(UpdateRoles(e, (e, r) => r.Add(e.Name)));

                case AppRoleUpdated e:
                    return(UpdateRoles(e, (e, r) => r.Update(e.Name, e.ToPermissions(), e.Properties)));

                case AppRoleDeleted e:
                    return(UpdateRoles(e, (e, r) => r.Remove(e.Name)));

                case AppLanguageAdded e:
                    return(UpdateLanguages(e, (e, l) => l.Set(e.Language)));

                case AppLanguageRemoved e:
                    return(UpdateLanguages(e, (e, l) => l.Remove(e.Language)));

                case AppLanguageUpdated e:
                    return(UpdateLanguages(e, (e, l) =>
                    {
                        l = l.Set(e.Language, e.IsOptional, e.Fallback);

                        if (e.IsMaster)
                        {
                            l = Languages.MakeMaster(e.Language);
                        }

                        return l;
                    }));

                case AppDeleted:
                {
                    Plan = null;

                    IsDeleted = true;

                    return(true);
                }
                }

                return(false);
            }
Example #3
0
        public override Task <CommandResult> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case UpsertAsset upsert:
                return(UpsertReturnAsync(upsert, async c =>
                {
                    var operation = await AssetOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    if (Version > EtagVersion.Empty && !IsDeleted(Snapshot))
                    {
                        await UpdateCore(c.AsUpdate(), operation);
                    }
                    else
                    {
                        await CreateCore(c.AsCreate(), operation);
                    }

                    if (Is.OptionalChange(Snapshot.ParentId, c.ParentId))
                    {
                        await MoveCore(c.AsMove(c.ParentId.Value), operation);
                    }

                    return Snapshot;
                }));

            case CreateAsset c:
                return(CreateReturnAsync(c, async create =>
                {
                    var operation = await AssetOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await CreateCore(create, operation);

                    if (Is.Change(Snapshot.ParentId, c.ParentId))
                    {
                        await MoveCore(c.AsMove(), operation);
                    }

                    return Snapshot;
                }));

            case AnnotateAsset c:
                return(UpdateReturnAsync(c, async c =>
                {
                    var operation = await AssetOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await AnnotateCore(c, operation);

                    return Snapshot;
                }));

            case UpdateAsset update:
                return(UpdateReturnAsync(update, async c =>
                {
                    var operation = await AssetOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await UpdateCore(c, operation);

                    return Snapshot;
                }));

            case MoveAsset move:
                return(UpdateReturnAsync(move, async c =>
                {
                    var operation = await AssetOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await MoveCore(c, operation);

                    return Snapshot;
                }));

            case DeleteAsset delete when delete.Permanent:
                return(DeletePermanentAsync(delete, async c =>
                {
                    var operation = await AssetOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await DeleteCore(c, operation);
                }));

            case DeleteAsset delete:
                return(UpdateAsync(delete, async c =>
                {
                    var operation = await AssetOperation.CreateAsync(serviceProvider, c, () => Snapshot);

                    await DeleteCore(c, operation);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Example #4
0
        public override Task <CommandResult> ExecuteAsync(IAggregateCommand command)
        {
            switch (command)
            {
            case UpsertAsset upsert:
                return(UpsertReturnAsync(upsert, async c =>
                {
                    if (Version > EtagVersion.Empty && !IsDeleted())
                    {
                        UpdateCore(c.AsUpdate());
                    }
                    else
                    {
                        await CreateCore(c.AsCreate());
                    }

                    if (Is.OptionalChange(Snapshot.ParentId, c.ParentId))
                    {
                        await MoveCore(c.AsMove(c.ParentId.Value));
                    }

                    return Snapshot;
                }));

            case CreateAsset c:
                return(CreateReturnAsync(c, async create =>
                {
                    await CreateCore(create);

                    if (Is.Change(Snapshot.ParentId, c.ParentId))
                    {
                        await MoveCore(c.AsMove());
                    }

                    return Snapshot;
                }));

            case AnnotateAsset c:
                return(UpdateReturnAsync(c, async c =>
                {
                    GuardAsset.CanAnnotate(c);

                    if (c.Tags != null)
                    {
                        c.Tags = await NormalizeTagsAsync(Snapshot.AppId.Id, c.Tags);
                    }

                    Annotate(c);

                    return Snapshot;
                }));

            case UpdateAsset update:
                return(UpdateReturn(update, update =>
                {
                    Update(update);

                    return Snapshot;
                }));

            case MoveAsset move:
                return(UpdateReturnAsync(move, async c =>
                {
                    await MoveCore(c);

                    return Snapshot;
                }));

            case DeleteAsset delete when(delete.Permanent):
                return(DeletePermanentAsync(delete, async c =>
                {
                    await DeleteCore(c);
                }));

            case DeleteAsset delete:
                return(UpdateAsync(delete, async c =>
                {
                    await DeleteCore(c);
                }));

            default:
                throw new NotSupportedException();
            }
        }
Example #5
0
        public override bool ApplyEvent(IEvent @event)
        {
            switch (@event)
            {
            case AppCreated e:
            {
                SimpleMapper.Map(e, this);

                return(true);
            }

            case AppUpdated e when Is.Change(Label, e.Label) || Is.Change(Description, e.Description):
            {
                SimpleMapper.Map(e, this);

                return(true);
            }

            case AppImageUploaded e:
                return(UpdateImage(e, ev => ev.Image));

            case AppImageRemoved e when Image != null:
                return(UpdateImage(e, ev => null));

            case AppPlanChanged e when Is.Change(Plan?.PlanId, e.PlanId):
                return(UpdatePlan(e, ev => new AppPlan(ev.Actor, ev.PlanId)));

            case AppPlanReset e when Plan != null:
                return(UpdatePlan(e, ev => null));

            case AppContributorAssigned e:
                return(UpdateContributors(e, (ev, c) => c.Assign(ev.ContributorId, ev.Role)));

            case AppContributorRemoved e:
                return(UpdateContributors(e, (ev, c) => c.Remove(ev.ContributorId)));

            case AppClientAttached e:
                return(UpdateClients(e, (ev, c) => c.Add(ev.Id, ev.Secret)));

            case AppClientUpdated e:
                return(UpdateClients(e, (ev, c) => c.Update(ev.Id, ev.Role)));

            case AppClientRenamed e:
                return(UpdateClients(e, (ev, c) => c.Rename(ev.Id, ev.Name)));

            case AppClientRevoked e:
                return(UpdateClients(e, (ev, c) => c.Revoke(ev.Id)));

            case AppWorkflowAdded e:
                return(UpdateWorkflows(e, (ev, w) => w.Add(ev.WorkflowId, ev.Name)));

            case AppWorkflowUpdated e:
                return(UpdateWorkflows(e, (ev, w) => w.Update(ev.WorkflowId, ev.Workflow)));

            case AppWorkflowDeleted e:
                return(UpdateWorkflows(e, (ev, w) => w.Remove(ev.WorkflowId)));

            case AppPatternAdded e:
                return(UpdatePatterns(e, (ev, p) => p.Add(ev.PatternId, ev.Name, ev.Pattern, ev.Message)));

            case AppPatternDeleted e:
                return(UpdatePatterns(e, (ev, p) => p.Remove(ev.PatternId)));

            case AppPatternUpdated e:
                return(UpdatePatterns(e, (ev, p) => p.Update(ev.PatternId, ev.Name, ev.Pattern, ev.Message)));

            case AppRoleAdded e:
                return(UpdateRoles(e, (ev, r) => r.Add(ev.Name)));

            case AppRoleUpdated e:
                return(UpdateRoles(e, (ev, r) => r.Update(ev.Name, ev.Permissions)));

            case AppRoleDeleted e:
                return(UpdateRoles(e, (ev, r) => r.Remove(ev.Name)));

            case AppLanguageAdded e:
                return(UpdateLanguages(e, (ev, l) => l.Set(ev.Language)));

            case AppLanguageRemoved e:
                return(UpdateLanguages(e, (ev, l) => l.Remove(ev.Language)));

            case AppLanguageUpdated e:
                return(UpdateLanguages(e, (ev, l) =>
                {
                    l = l.Set(ev.Language, ev.IsOptional, ev.Fallback?.ToArray());

                    if (ev.IsMaster)
                    {
                        l = LanguagesConfig.MakeMaster(ev.Language);
                    }

                    return l;
                }));

            case AppArchived _:
            {
                Plan = null;

                IsArchived = true;

                return(true);
            }
            }

            return(false);
        }