// ========================================================================== // AppStateGrainState.cs // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex Group // All rights reserved. // ========================================================================== using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using Newtonsoft.Json; using Squidex.Domain.Apps.Core.Schemas; using Squidex.Domain.Apps.Read.Apps; using Squidex.Domain.Apps.Read.Rules; using Squidex.Domain.Apps.Read.Schemas; using Squidex.Infrastructure; using Squidex.Infrastructure.EventSourcing; using Squidex.Infrastructure.Dispatching; namespace Squidex.Domain.Apps.Read.State.Grains { public sealed partial class AppStateGrainState : Cloneable { private FieldRegistry registry; [JsonProperty] public JsonAppEntity App { get; set; } [JsonProperty] public ImmutableDictionary Rules { get; set; } = ImmutableDictionary.Empty; [JsonProperty] public ImmutableDictionary Schemas { get; set; } = ImmutableDictionary.Empty; public void SetRegistry(FieldRegistry registry) { this.registry = registry; } public IAppEntity GetApp() { return App; } public ISchemaEntity FindSchema(Func filter) { return Schemas?.Values.FirstOrDefault(filter); } public List FindSchemas(Func filter) { return Schemas?.Values.Where(filter).OfType().ToList() ?? new List(); } public List FindRules() { return Rules?.Values.OfType().ToList() ?? new List(); } public AppStateGrainState Apply(Envelope envelope) { return Clone(c => { c.DispatchAction(envelope.Payload, envelope.Headers); if (c.App != null) { c.App.Etag = Guid.NewGuid().ToString(); } }); } } }