コード例 #1
0
        private void ApplyMutation(MutationEvent mutation)
        {
            var versions = Versions;

            State    = ApplyMutation(State, mutation, DetalizationLevel, ref versions);
            Versions = versions;
        }
コード例 #2
0
 public VersionConsistencyException(Resource resource, MutationEvent mutation, ulong aggregateVersion)
     : base($"Версия агрегата для ресурса {resource.ToFullString()} {aggregateVersion} не соответствует базовой версии для события ${mutation}")
 {
     Resource         = resource;
     Mutation         = mutation;
     AggregateVersion = aggregateVersion;
 }
コード例 #3
0
 public void Mutate(MutationEvent mutation)
 {
     mutation.BaseVersion = GetVersion();
     ApplyMutation(mutation);
     if (Guid.Empty.Equals(mutation.Id))
     {
         repo.PushEvent(Resource, mutation);
     }
 }
コード例 #4
0
        private TState ApplyMutation(TState state, MutationEvent mutation, byte detalizationLevel, ref List <ulong> versions)
        {
            if (mutation.DetalizationLevel > detalizationLevel)
            {
                throw new ArgumentException("Попытка применить событие с более высокой степенью детализации");
            }

            var version = GetVersion(versions, mutation.DetalizationLevel);

            if (mutation.BaseVersion != version)
            {
                throw new VersionConsistencyException(Resource, mutation, version);
            }

            var newState = (TState)((dynamic)this).Apply(State, (dynamic)mutation);

            IncrementVersion(ref versions, mutation.DetalizationLevel);
            return(newState);
        }