コード例 #1
0
        /// <summary>
        /// Calculate a <see cref="Metric{T}"/> from a <see cref="State{T}"/>
        /// </summary>
        /// <param name="state">The <see cref="State{T}"/> to compute metrics from.</param>
        /// <param name="aggregateWith">The <see cref="IStateLoader"/> for previous states to include in the computation.</param>
        /// <param name="saveStateWith">The <see cref="IStatePersister"/>loader for previous states to include in the computation. </param>
        /// <returns></returns>
        public M CalculateMetric(Option <S> state, Option <IStateLoader> aggregateWith,
                                 Option <IStatePersister> saveStateWith)
        {
            Option <S> loadedState = aggregateWith
                                     .Select(value => value.Load <S>(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this)).Value);


            Option <S> stateToComputeMetricFrom = AnalyzersExt.Merge(loadedState, state);

            saveStateWith
            .Select(persister =>
                    persister.Persist(new Option <IAnalyzer <IMetric> >((IAnalyzer <IMetric>) this), stateToComputeMetricFrom));

            return(ComputeMetricFrom(stateToComputeMetricFrom));
        }