Ejemplo n.º 1
0
        /// <summary>
        ///     apply a single <see cref="ReplayedEvent" /> to this object,
        ///     in order to modify its state to a more current one.
        /// </summary>
        /// <param name="replayedEvent"></param>
        public virtual void ApplyEvent(ReplayedEvent replayedEvent)
        {
            // ReSharper disable once UseNullPropagation
            if (replayedEvent is null)
            {
                return;
            }

            if (replayedEvent.DomainEvent is null)
            {
                return;
            }

            if (replayedEvent.Version <= MetaVersion)
            {
                return;
            }

            // if there is a handler for the given DomainEvent, call it
            // if that handler returns true we know the event was meant for this object and
            // we can update CurrentVersion
            if (HandlerMapping.TryGetValue(replayedEvent.DomainEvent.GetType(), out var handler) &&
                handler.Invoke(replayedEvent))
            {
                CurrentVersion = replayedEvent.Version;
            }
            MetaVersion = replayedEvent.Version;
        }
Ejemplo n.º 2
0
        private bool HandleEnvironmentKeysModifiedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is EnvironmentKeysModified modified) || modified.Identifier != Identifier)
            {
                return(false);
            }

            foreach (var deletion in modified.ModifiedKeys.Where(action => action.Type == ConfigKeyActionType.Delete))
            {
                if (Keys.ContainsKey(deletion.Key))
                {
                    Keys.Remove(deletion.Key);
                }
            }

            foreach (var change in modified.ModifiedKeys.Where(action => action.Type == ConfigKeyActionType.Set))
            {
                Keys[change.Key] = new ConfigEnvironmentKey(change.Key,
                                                            change.Value,
                                                            change.ValueType,
                                                            change.Description,
                                                            (long)DateTime.UtcNow
                                                            .Subtract(_unixEpoch)
                                                            .TotalSeconds);
            }

            _keyPaths = null;
            return(true);
        }
        private bool HandleEnvironmentKeysImportedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is EnvironmentKeysImported imported))
            {
                return(false);
            }

            Identifiers.Add(imported.Identifier);
            return(true);
        }
        private bool HandleDefaultEnvironmentCreatedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is DefaultEnvironmentCreated created))
            {
                return(false);
            }

            Identifiers.Add(created.Identifier);
            return(true);
        }
Ejemplo n.º 5
0
        private bool HandleStructureCreatedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is StructureCreated created))
            {
                return(false);
            }

            Identifiers.Add(created.Identifier);
            return(true);
        }
Ejemplo n.º 6
0
        private bool HandleEnvironmentDeletedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is EnvironmentDeleted deleted) || deleted.Identifier != Identifier)
            {
                return(false);
            }

            Created = false;
            Deleted = true;
            return(true);
        }
Ejemplo n.º 7
0
        private bool HandleEnvironmentCreatedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is EnvironmentCreated created) || created.Identifier != Identifier)
            {
                return(false);
            }

            IsDefault = false;
            Created   = true;
            return(true);
        }
        private bool HandleEnvironmentDeletedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is EnvironmentDeleted deleted))
            {
                return(false);
            }

            if (Identifiers.Contains(deleted.Identifier))
            {
                Identifiers.Remove(deleted.Identifier);
            }
            return(true);
        }
        private bool HandleStructureDeletedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is StructureDeleted deleted) || deleted.Identifier != Identifier)
            {
                return(false);
            }

            Created = false;
            Deleted = true;
            Keys.Clear();
            Variables.Clear();
            return(true);
        }
        private bool HandleStructureCreatedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is StructureCreated created) || created.Identifier != Identifier)
            {
                return(false);
            }

            Created   = true;
            Deleted   = false;
            Keys      = created.Keys;
            Variables = created.Variables;
            return(true);
        }
        // ReSharper restore ParameterOnlyUsedForPreconditionCheck.Local

        private bool HandleConfigurationBuiltEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is ConfigurationBuilt built) || built.Identifier != Identifier)
            {
                return(false);
            }

            Created              = true;
            ValidFrom            = built.ValidFrom;
            ValidTo              = built.ValidTo;
            Built                = false;
            Keys                 = new Dictionary <string, string>();
            Json                 = null;
            ConfigurationVersion = (long)replayedEvent.UtcTime
                                   .Subtract(_unixEpoch)
                                   .TotalSeconds;
            return(true);
        }
        private bool HandleStructureVariablesModifiedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is StructureVariablesModified modified) || modified.Identifier != Identifier)
            {
                return(false);
            }

            foreach (var deletion in modified.ModifiedKeys.Where(action => action.Type == ConfigKeyActionType.Delete))
            {
                if (Variables.ContainsKey(deletion.Key))
                {
                    Variables.Remove(deletion.Key);
                }
            }

            foreach (var change in modified.ModifiedKeys.Where(action => action.Type == ConfigKeyActionType.Set))
            {
                Variables[change.Key] = change.Value;
            }

            return(true);
        }
Ejemplo n.º 13
0
        private bool HandleEnvironmentKeysImportedEvent(ReplayedEvent replayedEvent)
        {
            if (!(replayedEvent.DomainEvent is EnvironmentKeysImported imported) || imported.Identifier != Identifier)
            {
                return(false);
            }

            Created = true;
            Keys    = imported.ModifiedKeys
                      .Where(action => action.Type == ConfigKeyActionType.Set)
                      .ToDictionary(
                action => action.Key,
                action => new ConfigEnvironmentKey(action.Key,
                                                   action.Value,
                                                   action.ValueType,
                                                   action.Description,
                                                   (long)DateTime.UtcNow
                                                   .Subtract(_unixEpoch)
                                                   .TotalSeconds));

            _keyPaths = null;
            return(true);
        }