protected void On(AppLanguageUpdated @event) { LanguagesConfig = LanguagesConfig.Set(@event.Language, @event.IsOptional, @event.Fallback); if (@event.IsMaster) { LanguagesConfig = LanguagesConfig.MakeMaster(@event.Language); } }
private LanguagesConfig CreateLanguagesConfig() { languagesConfig = LanguagesConfig.Create(Languages?.Select(ToLanguageConfig).ToList() ?? new List <LanguageConfig>()); if (MasterLanguage != null) { languagesConfig = languagesConfig.MakeMaster(MasterLanguage); } return(languagesConfig); }
public static void Apply(this LanguagesConfig languagesConfig, AppLanguageUpdated @event) { var fallback = @event.Fallback; if (fallback != null && fallback.Count > 0) { var existingLangauges = languagesConfig.OfType <LanguageConfig>().Select(x => x.Language); fallback = fallback.Intersect(existingLangauges).ToList(); } languagesConfig.Set(new LanguageConfig(@event.Language, @event.IsOptional, fallback)); if (@event.IsMaster) { languagesConfig.MakeMaster(@event.Language); } }
public override bool ApplyEvent(IEvent @event) { switch (@event) { case AppCreated e: { SimpleMapper.Map(e, this); return(true); } case AppUpdated e when !string.Equals(e.Label, Label) || !string.Equals(e.Description, 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 !string.Equals(Plan?.PlanId, e.PlanId): return(UpdatePlan(e, ev => AppPlan.Build(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); if (ev.IsMaster) { LanguagesConfig = LanguagesConfig.MakeMaster(ev.Language); } return l; })); case AppArchived _: { Plan = null; IsArchived = true; return(true); } } return(false); }
public void ApplyEvent(IEvent @event) { switch (@event) { case AppCreated e: { Roles = Roles.CreateDefaults(e.Name); SimpleMapper.Map(e, this); break; } case AppUpdated e: { SimpleMapper.Map(e, this); break; } case AppImageUploaded e: { Image = e.Image; break; } case AppImageRemoved _: { Image = null; break; } case AppPlanChanged e: { Plan = AppPlan.Build(e.Actor, e.PlanId); break; } case AppPlanReset _: { Plan = null; break; } case AppContributorAssigned e: { Contributors = Contributors.Assign(e.ContributorId, e.Role); break; } case AppContributorRemoved e: { Contributors = Contributors.Remove(e.ContributorId); break; } case AppClientAttached e: { Clients = Clients.Add(e.Id, e.Secret); break; } case AppClientUpdated e: { Clients = Clients.Update(e.Id, e.Role); break; } case AppClientRenamed e: { Clients = Clients.Rename(e.Id, e.Name); break; } case AppClientRevoked e: { Clients = Clients.Revoke(e.Id); break; } case AppWorkflowAdded e: { Workflows = Workflows.Add(e.WorkflowId, e.Name); break; } case AppWorkflowUpdated e: { Workflows = Workflows.Update(e.WorkflowId, e.Workflow); break; } case AppWorkflowDeleted e: { Workflows = Workflows.Remove(e.WorkflowId); break; } case AppPatternAdded e: { Patterns = Patterns.Add(e.PatternId, e.Name, e.Pattern, e.Message); break; } case AppPatternDeleted e: { Patterns = Patterns.Remove(e.PatternId); break; } case AppPatternUpdated e: { Patterns = Patterns.Update(e.PatternId, e.Name, e.Pattern, e.Message); break; } case AppRoleAdded e: { Roles = Roles.Add(e.Name); break; } case AppRoleDeleted e: { Roles = Roles.Remove(e.Name); break; } case AppRoleUpdated e: { Roles = Roles.Update(e.Name, e.Permissions.Prefix(Name)); break; } case AppLanguageAdded e: { LanguagesConfig = LanguagesConfig.Set(e.Language); break; } case AppLanguageRemoved e: { LanguagesConfig = LanguagesConfig.Remove(e.Language); break; } case AppLanguageUpdated e: { LanguagesConfig = LanguagesConfig.Set(e.Language, e.IsOptional, e.Fallback); if (e.IsMaster) { LanguagesConfig = LanguagesConfig.MakeMaster(e.Language); } break; } case AppArchived _: { Plan = null; IsArchived = true; break; } } }