Esempio n. 1
0
        /// <summary>
        /// Create a DesultoryParallel with shared behaviors and add it to this task.
        /// </summary>
        /// <param name="actions"></param>
        /// <param name="sharedState"></param>
        /// <param name="sharedNextCondition"></param>
        /// <param name="parallelState"></param>
        /// <param name="parallelNextCondition"></param>
        /// <returns></returns>
        public DesultoryTask WithParallelBlock(IEnumerable <Action <object> > actions,
                                               object sharedState   = null, Func <DesultoryStatementBase, object, DesultoryTaskNextFunction> sharedNextCondition   = null,
                                               object parallelState = null, Func <DesultoryStatementBase, object, DesultoryTaskNextFunction> parallelNextCondition = null)
        {
            var items = new List <DesultoryBlock>();

            foreach (var action in actions)
            {
                items.Add(new DesultoryBlock(action, this.CTSource.Token)
                {
                    State         = sharedState,
                    NextCondition = sharedNextCondition
                });
            }

            var parallel = new DesultoryParallel(items)
            {
                Desultory     = this,
                Deep          = 1,
                State         = parallelState,
                NextCondition = parallelNextCondition
            };

            _items.Add(parallel);

            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Create a DesultoryParallel with multiple same DesultoryBlocks and add it to this task.
        /// </summary>
        /// <param name="count"></param>
        /// <param name="action"></param>
        /// <param name="state"></param>
        /// <param name="nextCondition"></param>
        /// <param name="parallelState"></param>
        /// <param name="parallelNextCondition"></param>
        /// <returns></returns>
        public DesultoryTask WithParallelBlock(int count, Action <object> action,
                                               object state         = null, Func <DesultoryStatementBase, object, DesultoryTaskNextFunction> nextCondition = null,
                                               object parallelState = null, Func <DesultoryStatementBase, object, DesultoryTaskNextFunction> parallelNextCondition = null)
        {
            var items = new List <DesultoryBlock>();

            for (int i = 0; i < count; i++)
            {
                items.Add(new DesultoryBlock(action, this.CTSource.Token)
                {
                    State         = state,
                    NextCondition = nextCondition
                });
            }

            var parallel = new DesultoryParallel(items)
            {
                Desultory     = this,
                Deep          = 1,
                State         = parallelState,
                NextCondition = parallelNextCondition
            };

            _items.Add(parallel);

            return(this);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a DesultoryParallel with any uncorrelated DesultoryBlocks and add it to this task.
        /// </summary>
        /// <param name="creations"></param>
        /// <param name="parallelState"></param>
        /// <param name="parallelNextCondition"></param>
        /// <returns></returns>
        public DesultoryTask WithParallelBlock(IEnumerable <DesultoryStatementCreation> creations,
                                               object parallelState = null, Func <DesultoryStatementBase, object, DesultoryTaskNextFunction> parallelNextCondition = null)
        {
            var items = new List <DesultoryBlock>();

            foreach (var c in creations)
            {
                items.Add(new DesultoryBlock(c.Statement, this.CTSource.Token)
                {
                    State         = c.State,
                    NextCondition = c.NextCondition
                });
            }

            var parallel = new DesultoryParallel(items)
            {
                Desultory     = this,
                Deep          = 1,
                State         = parallelState,
                NextCondition = parallelNextCondition
            };

            _items.Add(parallel);

            return(this);
        }