Пример #1
0
        /// <summary>
        /// Aggregates two states loaded by the state loader and saves the resulting aggregation using the target state
        /// persister.
        /// </summary>
        /// <param name="sourceA">The first state to load <see cref="IStateLoader"/></param>
        /// <param name="sourceB">The second state to load <see cref="IStateLoader"/></param>
        /// <param name="target">The target persister <see cref="IStatePersister"/></param>
        public void AggregateStateTo(IStateLoader sourceA, IStateLoader sourceB, IStatePersister target)
        {
            Option <S> maybeStateA = sourceA.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this));
            Option <S> maybeStateB = sourceB.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this));

            S aggregated = (maybeStateA.HasValue, maybeStateB.HasValue) switch
            {
                (true, true) => maybeStateA.Value.Sum(maybeStateB.Value),
                (true, false) => maybeStateA.Value,
                (false, true) => maybeStateB.Value,
                _ => null
            };

            target.Persist(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this), new Option <S>(aggregated));
        }
Пример #2
0
 /// <summary>
 /// Copy the state from source to target.
 /// </summary>
 /// <param name="source">The <see cref="IStateLoader"/> to read from.</param>
 /// <param name="target">The <see cref="IStatePersister"/> to write to.</param>
 public void CopyStateTo(IStateLoader source, IStatePersister target) =>
 target.Persist(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this), source.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this)));