Example #1
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);
        }
Example #2
0
        public static async Task SendAsync <TIn>(this Dataflow <TIn> dataflow, TIn item)
        {
            bool success = await dataflow.InputBlock.SendAsync(item).ConfigureAwait(false);

            if (!success)
            {
                ThrowSendFailedException(dataflow);
            }
        }
Example #3
0
        public DataflowMerger(Dataflow <T1, T2> b1, Dataflow <T2, T3> b2, DataflowOptions options) : base(options)
        {
            m_b1 = b1;
            m_b2 = b2;

            m_b1.GoTo(m_b2);

            RegisterChild(m_b1);
            RegisterChild(m_b2);
        }
Example #4
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="copyFunc">The copy function</param>
        /// <param name="outs">The target dataflows</param>
        public static void LinkToMultiple <TIn, TOut>(this Dataflow <TIn, TOut> dataflow, Func <TOut, TOut> copyFunc, params IDataflow <TOut>[] outs)
        {
            var brancher = new DataBroadcaster <TOut>(copyFunc, DataflowOptions.Default);

            dataflow.GoTo(brancher);

            foreach (var output in outs)
            {
                brancher.LinkTo(output);
            }
        }
Example #5
0
        /// <summary>
        /// Register a sub dataflow as child. Also make sure the dataflow will fail if the registered dataflow fails.
        /// </summary>
        public void RegisterChild(Dataflow childFlow, Action <Task> dataflowCompletionCallback = null, bool allowDuplicate = false)
        {
            if (childFlow == null)
            {
                throw new ArgumentNullException("childFlow");
            }

            if (childFlow.IsMyChild(this))
            {
                throw new ArgumentException(
                          string.Format("{0} Cannot register a child {1} who is already my ancestor", this.FullName, childFlow.FullName));
            }

            RegisterChild(new DataflowDependency(childFlow, this, DependencyKind.Internal, dataflowCompletionCallback), allowDuplicate);
        }
Example #6
0
        private static void ThrowSendFailedException <TIn>(Dataflow <TIn> dataflow)
        {
            if (dataflow.InputBlock.Completion.IsCompleted)
            {
                string msg = string.Format(
                    "SendAsync to {0} failed as its input block is {1}",
                    dataflow.FullName,
                    dataflow.InputBlock.Completion.Status);

                throw new PostToBlockFailedException(msg);
            }
            else
            {
                var    bufferStatus = dataflow.BufferStatus;
                string msg          = string.Format(
                    "SendAsync to {0} failed. Its buffer state is (in:{1}, out:{2})",
                    dataflow.FullName,
                    bufferStatus.Item1,
                    bufferStatus.Item2);
                throw new PostToBlockFailedException(msg);
            }
        }
Example #7
0
 public DataflowMerger(Dataflow <T1, T2> b1, Dataflow <T2, T3> b2) : this(b1, b2, b1.DataflowOptions)
 {
 }
 protected DependencyBase(Dataflow host, Action <Task> completionCallback, DependencyKind kind)
 {
     m_host = host;
     m_completionCallback = completionCallback;
     this.Kind            = kind;
 }
 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);
 }
 public BlockDependency(IDataflowBlock block, Dataflow host, DependencyKind kind, Action <Task> completionCallback = null, string displayName = null) : base(host, completionCallback, kind)
 {
     m_block            = block;
     this.m_displayName = displayName;
     m_completion       = GetWrappedCompletion(m_block.Completion);
 }
Example #11
0
 /// <summary>
 /// Synchronously post an item to a dataflow
 /// </summary>
 /// <typeparam name="TIn">The input type of the dataflow</typeparam>
 /// <param name="dataflow">The dataflow to accept message</param>
 /// <param name="item">The message to post</param>
 /// <returns>Whether the post operation succeeds</returns>
 public static bool Post <TIn>(this Dataflow <TIn> dataflow, TIn item)
 {
     return(dataflow.InputBlock.Post(item));
 }
Example #12
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="outs">The target dataflows</param>
 public static void LinkToMultiple <TIn, TOut>(this Dataflow <TIn, TOut> dataflow, params Dataflow <TOut>[] outs)
 {
     LinkToMultiple(dataflow, null, outs);
 }
Example #13
0
 /// <summary>
 /// Wraps an existing dataflow with auto complete feature
 /// </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 inner dataflow to wrap</param>
 /// <param name="timeout">The last-survival-timeout value for auto complete to trigger</param>
 /// <returns></returns>
 public static Dataflow <TIn, TOut> AutoComplete <TIn, TOut>(this Dataflow <TIn, TOut> dataflow, TimeSpan timeout)
     where TIn : ITracableItem
     where TOut : ITracableItem
 {
     return(new AutoCompleteWrapper <TIn, TOut>(dataflow, timeout, dataflow.DataflowOptions));
 }