Пример #1
0
        /// <summary>
        /// Creates a transformation that takes one input and produces one output for each.
        /// </summary>
        /// <typeparam name="TIn"></typeparam>
        /// <typeparam name="TOut"></typeparam>
        /// <param name="transformation"></param>
        /// <param name="boundedCapacity"></param>
        /// <returns></returns>
        public TransformBlock <IDataflowMessage <TIn>, IDataflowMessage <TOut> > CreateTransform <TIn, TOut>(ITransformation <TIn, TOut> transformation, int boundedCapacity = -1)
        {
            TransformBlock <IDataflowMessage <TIn>, IDataflowMessage <TOut> > block = null;

            ITransformationFunctor <TIn, TOut> transFunc = transformation
                                                           .WithExceptionHandler(m_LogAgent, this)
                                                           .WithLogging(m_LogAgent)
                                                           .WithWorkloadStatistics(boundedCapacity, () => block.InputCount, () => block.OutputCount, m_ctx, this.m_DfnGuid, m_Cts.Token);// x() f(), functionPointer())// MsgInFunc(), MsgInFunc())// m_MsgInFunc, m_MsgOutFunc)

            if (m_LogStatistics)
            {
                transFunc = transFunc.WithStatistics(m_LogAgent);
                m_StatisticsLoggers.Add((IStatisticsLogger)transFunc);
            }

            block = new TransformBlock <IDataflowMessage <TIn>, IDataflowMessage <TOut> >(
                transFunc
                .AsFunction(), CreateDefaultExecutionOptions(boundedCapacity));

            return(block);
        }