Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="aggregate"></param>
 public AggregateBStream(
     TumblingWindowBStream <TPayload> stream,
     IAggregate <TPayload, TAggState, TResult> aggregate
     ) : base(stream, stream.Period, stream.Offset)
 {
     Aggregate  = aggregate;
     Initialize = Aggregate.InitialState().Compile();
     Acc        = Aggregate.Accumulate().Compile();
     Res        = Aggregate.ComputeResult().Compile();
     Deacc      = Aggregate.Deaccumulate().Compile();
     Diff       = Aggregate.Difference().Compile();
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <param name="aggregate"></param>
        /// <typeparam name="TPayload"></typeparam>
        /// <typeparam name="TAggState"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <returns></returns>
        public static BStreamable <TResult> Aggregate <TPayload, TAggState, TResult>(
            this TumblingWindowBStream <TPayload> source,
            Func <Window <Empty, TPayload>, IAggregate <TPayload, TAggState, TResult> > aggregate
            )
        {
            Invariant.IsNotNull(source, nameof(source));
            Invariant.IsNotNull(aggregate, nameof(aggregate));
            var p = new StreamProperties <Empty, TPayload>(
                false, true, source.Period, true, source.Period, source.Offset,
                false, true, true, true,
                EqualityComparerExpression <Empty> .Default, EqualityComparerExpression <TPayload> .Default,
                ComparerExpression <Empty> .Default, ComparerExpression <TPayload> .Default, null, null, null
                );

            return(new AggregateBStream <TPayload, TAggState, TResult>(
                       source, aggregate(new Window <Empty, TPayload>(p))
                       ));
        }