public static IDataflow <Either <TLeft, TRightOutput> > SelectManySafe
 <TLeft, TRightInput, TRightMedium, TRightOutput>(
     this IDataflow <Either <TLeft, TRightInput> > source,
     Func <TRightInput, IEnumerable <Either <TLeft, TRightMedium> > > mediumSelector,
     Func <TRightInput, TRightMedium, TRightOutput> resultSelector)
 {
     return(source.SelectMany(item => item.SelectManySafe(mediumSelector, resultSelector)));
 }
 public static IDataflow <TOutput> SelectMany <TInput, TMedium, TOutput>(this IDataflow <TInput> dataflow,
                                                                         Func <TInput, IEnumerable <TMedium> > mediumSelector,
                                                                         Func <TInput, TMedium, TOutput> resultSelector)
 {
     return(dataflow.SelectMany(input =>
                                mediumSelector(input)
                                .Select(medium => resultSelector(input, medium))));
 }
 public static IDataflow <TOutput> SelectMany <TInput, TMedium, TOutput>(this IDataflow <TInput> source,
                                                                         Func <TInput, IDataflow <TMedium> > mediumSelector,
                                                                         Func <TInput, TMedium, TOutput> resultSelector)
 {
     return(source.SelectMany(input =>
                              mediumSelector(input)
                              .Select(medium => resultSelector(input, medium))));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Register an external dataflow as dependency, whose completion will trigger completion of this dataflow
        /// if this dependency finishes as the last among all dependencies.
        /// i.e. Completion of this dataflow will only be triggered after ALL dependencies finish.
        /// </summary>
        public void RegisterDependency(IDataflow dependencyDataflow)
        {
            if (this.IsMyChild(dependencyDataflow))
            {
                throw new ArgumentException("Cannot register a child as dependency. Child: " + dependencyDataflow.FullName, "dependencyDataflow");
            }

            this.RegisterDependency(new DataflowDependency(dependencyDataflow, this, DependencyKind.External));
        }
Exemplo n.º 5
0
 public BaseServiceCache(string projectCode, long modelID, string modelName, string modelPath, IDataflow dataflow)
 {
     this._path         = modelPath;
     this._model_ID     = modelID;
     this._model_Name   = modelName;
     this._dataflow     = dataflow;
     this._project_Code = projectCode;
     _store             = new CacheSynchronized <TCache, TApi>(projectCode, modelID, modelName, modelPath, dataflow);
 }
 public static IDataflow <Either <TLeft, TRightOutput> > BindSafe <TLeft, TRightInput, TRightOutput>(
     this IDataflow <Either <TLeft, TRightInput> > source,
     Func <TRightInput, IDataflow <Either <TLeft, TRightOutput> > > bindFunc)
 {
     return(source.Bind(item =>
                        item.Match(
                            right => bindFunc(right),
                            left => source.Factory.Return(Left <TLeft, TRightOutput>(left)))));
 }
Exemplo n.º 7
0
        /// <summary>
        /// Link the copied data stream to another block
        /// </summary>
        private void LinkCopyTo(IDataflow <T> other)
        {
            //first, create a new copy block
            Dataflow <T, T> copyBuffer = new BufferBlock <T>(m_dataflowOptions.ToGroupingBlockOption()).ToDataflow(m_dataflowOptions);

            RegisterChild(copyBuffer);
            copyBuffer.RegisterDependency(m_transformBlock);

            m_copyBuffers   = m_copyBuffers.Add(copyBuffer);
            copyBuffer.Name = "Buffer" + m_copyBuffers.Count;
            copyBuffer.LinkTo(other);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Link the copied data stream to another block
        /// </summary>
        private void LinkCopyTo(IDataflow <T> other)
        {
            //first, create a new copy block
            Dataflow <T, T> copyBuffer = new BufferBlock <T>(m_dataflowOptions.ToGroupingBlockOption()).ToDataflow(m_dataflowOptions);

            RegisterChild(copyBuffer);
            copyBuffer.RegisterDependency(m_transformBlock);

            var afterAdd = ImmutableUtils.AddOptimistically(ref m_copyBuffers, copyBuffer);

            copyBuffer.Name = "Buffer" + afterAdd.Count;
            copyBuffer.LinkTo(other);
        }
 public static IDataflow <Either <TLeft, IGroupedDataflow <TKey, TRight> > > GroupBySafe <TLeft, TRight, TKey>(
     this IDataflow <Either <TLeft, TRight> > source, Func <TRight, TKey> keySelector)
 {
     return(source
            .GroupBy(item => item.IsRight)
            .SelectMany(
                group => group.Key
                 ? group
                .Rights()
                .GroupBy(keySelector)
                .Select(Right <TLeft, IGroupedDataflow <TKey, TRight> >)
                 : group
                .Lefts()
                .Select(Left <TLeft, IGroupedDataflow <TKey, TRight> >)));
 }
 public static IDataflow <Either <TLeft, IList <TRight> > > BufferSafe <TLeft, TRight>(
     this IDataflow <Either <TLeft, TRight> > source, TimeSpan batchTimeout, int count)
 {
     return(source
            .Buffer(batchTimeout, count)
            .SelectMany(batch => batch
                        .GroupBy(item => item.IsRight)
                        .SelectMany(group => group.Key
                 ? List(
                                        Right <TLeft, IList <TRight> >(
                                            group.Rights().ToList()))
                 : group
                                    .Lefts()
                                    .Select(Left <TLeft, IList <TRight> >))));
 }
Exemplo n.º 11
0
        /// <summary>
        /// See <see cref="Dataflow{TIn, TOut}.GoTo"/>
        /// </summary>
        public override IDataflow <T> GoTo(IDataflow <T> other, Predicate <T> predicate)
        {
            if (predicate != null)
            {
                throw new ArgumentException("DataBroadcaster does not support predicate linking", "predicate");
            }

            if (m_condBuilder.Count == 0) //not linked to any target yet
            {
                //link first output as primary output
                base.GoTo(other);
            }
            else
            {
                this.LinkCopyTo(other);
            }

            LogHelper.Logger.InfoFormat("{0} now links to its {1}th target ({2})", this.FullName, m_copyBuffers.Count + 1, other.Name);
            return(other);
        }
Exemplo n.º 12
0
        //Linkd MY block to OHTER dataflow
        protected void LinkBlockToFlow <T>(ISourceBlock <T> block, IDataflow <T> otherDataflow, Predicate <T> predicate = null)
        {
            if (!IsMyChild(block))
            {
                throw new InvalidOperationException(string.Format("{0} Cannot link block to flow as the output block is not my child.", this.FullName));
            }

            if (predicate == null)
            {
                block.LinkTo(otherDataflow.InputBlock);
            }
            else
            {
                block.LinkTo(otherDataflow.InputBlock, predicate);
            }

            otherDataflow.RegisterDependency(this);

            //Make sure other dataflow also fails me
            otherDataflow.Completion.ContinueWith(otherTask =>
            {
                if (this.Completion.IsCompleted)
                {
                    return;
                }

                if (otherTask.IsFaulted)
                {
                    LogHelper.Logger.InfoFormat("{0} Downstream dataflow faulted before I am done. Fault myself.", this.FullName);
                    this.Fault(new LinkedDataflowFailedException());
                }
                else if (otherTask.IsCanceled)
                {
                    LogHelper.Logger.InfoFormat("{0} Downstream dataflow canceled before I am done. Cancel myself.", this.FullName);
                    this.Fault(new LinkedDataflowCanceledException());
                }
            });
        }
 public static IDataflow <TLeft> Lefts <TLeft, TRight>(this IDataflow <Either <TLeft, TRight> > source)
 {
     return(source.Select(item => item.GetLeftSafe()));
 }
Exemplo n.º 14
0
 public DataflowDependency(IDataflow dependentFlow, Dataflow host, DependencyKind kind, Action <Task> completionCallback = null) : base(host, completionCallback, kind)
 {
     m_dependentFlow = (Dataflow)dependentFlow;
     m_completion    = GetWrappedCompletion(this.m_dependentFlow.CompletionTask);
 }
Exemplo n.º 15
0
 public notifyController(IDataflow dataflow)
 {
     _dataflow = dataflow;
 }
Exemplo n.º 16
0
 public CoalesceProvider(IDataflow <T1> arg1, IDataflow <T2> arg2)
 {
     this.arg1 = arg1;
     this.arg2 = arg2;
 }
Exemplo n.º 17
0
 public SameOrDefaultProvider(IDataflow <T> arg1, IDataflow <T> arg2, T defaultValue)
 {
     this.arg1         = arg1;
     this.arg2         = arg2;
     this.defaultValue = defaultValue;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Check if the flow is my child or myself
 /// </summary>
 public bool IsMyChild(IDataflow flow)
 {
     return(this.IsMyChildImpl(flow));
 }
Exemplo n.º 19
0
 public WhereProvider(IDataflow <T> arg, Predicate <T> predicate)
 {
     this.arg       = arg;
     this.predicate = predicate;
 }
Exemplo n.º 20
0
 public DistinctUntilChangedProvider(IDataflow <T> arg)
 {
     this.arg = arg;
 }
 public static IDataflow <Either <TLeft, TRightOutput> > SelectManySafe <TLeft, TRightInput, TRightOutput>(
     this IDataflow <Either <TLeft, TRightInput> > source,
     Func <TRightInput, IDataflow <Either <TLeft, TRightOutput> > > selector)
 {
     return(source.BindSafe(selector));
 }
Exemplo n.º 22
0
 public void LinkTo(IDataflow <JoinBatch <TIn> > other, Predicate <JoinBatch <TIn> > predicate = null)
 {
     this.LinkBlockToFlow(this.m_outputBuffer.OutputBlock, other, predicate);
 }
Exemplo n.º 23
0
 public Consumer(IDataflow <T> dataflow, Action <T> action)
 {
     this.dataflow = dataflow;
     this.action   = action;
 }
 public static IDataflow <Either <TLeft, TRightOutput> > SelectSafe <TLeft, TRightInput, TRightOutput>(
     this IDataflow <Either <TLeft, TRightInput> > source,
     Func <TRightInput, Either <TLeft, TRightOutput> > selector)
 {
     return(source.Select(item => item.SelectSafe(selector)));
 }
Exemplo n.º 25
0
 /// <summary>
 /// Constructs a statistics recorder instance
 /// </summary>
 /// <param name="parent">The dataflow that this recorder belongs to</param>
 public StatisticsRecorder(IDataflow parent)
 {
     this.m_parent = parent;
 }
Exemplo n.º 26
0
 public SkipProvider(IDataflow <T> arg, int count)
 {
     this.arg  = arg;
     countdown = count;
 }
 public static IDataflow <Either <TLeft, TRightOutput> > SelectManySafeAsync <TLeft, TRightInput, TRightOutput>(
     this IDataflow <Either <TLeft, TRightInput> > source,
     Func <TRightInput, Task <IEnumerable <Either <TLeft, TRightOutput> > > > selector)
 {
     return(source.SelectManyAsync(item => item.SelectManySafeAsync(selector)));
 }
Exemplo n.º 28
0
        /// <summary>
        /// Links a dataflow to multiple targets. Uses DataBroadcaster internally.
        /// </summary>
        /// <typeparam name="TIn">The input type of the Dataflow</typeparam>
        /// <typeparam name="TOut">The output type of the Dataflow</typeparam>
        /// <param name="dataflow">The source dataflow</param>
        /// <param name="out1">The first target dataflow</param>
        /// <param name="out2">The second target dataflow</param>
        /// <param name="copyFunc">The copy function</param>
        public static void LinkToMultiple <TIn, TOut>(this Dataflow <TIn, TOut> dataflow, IDataflow <TOut> out1, IDataflow <TOut> out2, Func <TOut, TOut> copyFunc = null)
        {
            var brancher = new DataBroadcaster <TOut>(copyFunc, DataflowOptions.Default);

            dataflow.GoTo(brancher);
            brancher.LinkTo(out1);
            brancher.LinkTo(out2);
        }
Exemplo n.º 29
0
 public BasicAuthenticationAttribute(IDataflow api) : base()
 {
     _api = api;
 }
Exemplo n.º 30
0
 public JobTest(IDataflow dataflow, INotifyService notify)
 {
     _dataflow = dataflow; _notify = notify;
 }