示例#1
0
        public override void AddOperation <TOperation>(ICheckConstraint constraint)
        {
            var operation     = Activator.CreateInstance <TOperation>() as BasicOperation <T>;
            var operationPair = new OperationDuplex <T>(new OperationInvoker <T>(operation), constraint);

            ParallelOperations.Add(operationPair);
        }
示例#2
0
        /// <summary>
        /// Gets a generator over Tasks and adjusts the task path as constraints
        /// fail or pass if there are branch conditions included.
        /// </summary>
        /// <returns></returns>
        public IEnumerable GenerateTaskList()
        {
            IEnumerable tasks      = Tasks;
            var         enumerator = tasks.GetEnumerator();

            for (; enumerator.MoveNext();)
            {
                var task = (OperationDuplex <T>)enumerator.Current;
                // TODO: this smells like object incest. Interface maybe??
                if (task.Constraint is BranchCondition)
                {
                    var constraint = (BranchCondition)task.Constraint;
                    var cond       = new BranchCondition(constraint, () =>
                    {
                        var enumerable = constraint.BranchPoint.GetRemainingOperations();
                        if (enumerable != null)
                        {
                            enumerator = enumerable.GetEnumerator();
                        }
                    });
                    task = new OperationDuplex <T>(task.Command, cond);
                }
                yield return(task);
            }
        }
示例#3
0
        public override void AddOperation(Func <T, T> function, ICheckConstraint constraint, IDeclaredOperation name)
        {
            InitializeDeclaredOperation(name);
            var operationPair = new OperationDuplex <T>(new FunctionInvoker <T>(function), constraint);

            taskList.Tasks.Add(operationPair);
        }
示例#4
0
        public override void AddOperation <TOperation>()
        {
            var operation     = Activator.CreateInstance <TOperation>();
            var operationPair = new OperationDuplex <T>(new OperationInvoker <T>(operation as BasicOperation <T>));

            ParallelOperations.Add(operationPair);
        }
示例#5
0
 public ThreadProxy(ref Dispatcher <T> engine, OperationDuplex <T> threadStartFunction, T parameter, ref ManualResetEvent finishedEvent)
 {
     _finishedEvent = finishedEvent;
     _function      = threadStartFunction;
     _data          = parameter;
     _engine        = engine;
 }
示例#6
0
        public override void AddOperation <TOperation>(ICheckConstraint constraint)
        {
            var operation = Activator.CreateInstance <TOperation>();

            var operationPair = new OperationDuplex <T>(new OperationInvoker <T>(operation as BasicOperation <T>), constraint);

            taskList.Tasks.Add(operationPair);
        }
示例#7
0
        public override void AddOperation <TType>()
        {
            var operation = Activator.CreateInstance <TType>();

            var operationPair = new OperationDuplex <T>(new OperationInvoker <T>(operation as BasicOperation <T>));

            taskList.Tasks.Add(operationPair);
        }
示例#8
0
        private ManualResetEvent QueueOperation(OperationDuplex <T> function, T data, ManualResetEvent finishedEvent)
        {
            var threadContainer = new ThreadProxy(ref _engine, function, data, ref finishedEvent);

            ThreadPool.QueueUserWorkItem(a => threadContainer.Start());

            return(finishedEvent);
        }
示例#9
0
        public ParallelSplitBuilder(TaskList <T> taskList) : base(taskList)
        {
            ParallelOperations = new ParallelInvoker <T>();

            if (null != taskList.Tasks && 0 != taskList.Tasks.Count)
            {
                OperationDuplex <T> leftOver =
                    taskList.Tasks[taskList.Tasks.Count - 1];
                taskList.Tasks.RemoveAt(taskList.Tasks.Count - 1);
                ParallelOperations.Add(leftOver);
            }
        }
示例#10
0
        public virtual T Execute(OperationDuplex <T> operationPair, T current)
        {
            if (ConstraintResult(operationPair.Constraint))
            {
                try
                {
                    current = operationPair.Command.Execute(current);
                    LastOperationSucceeded = true;
                }
                catch (Exception ex)
                {
                    while (ex is System.Reflection.TargetInvocationException)
                    {
                        ex = ex.InnerException;
                    }

                    switch (ErrorHandler.Handle(ex, current))
                    {
                    case ErrorLevel.Ignored:
                        LastOperationSucceeded = true;
                        break;

                    case ErrorLevel.Handled:
                        LastOperationSucceeded = false;
                        break;

                    case ErrorLevel.Fatal:
                        LastOperationSucceeded = false;
                        throw ex;

                    default:
                        // This line should theoretically be dead code.
                        throw new ArgumentOutOfRangeException("invalid member of ErrorLevel enum");
                    }
                }

                current = ExecutePolicies(operationPair.Command, current);
            }

            Context = current;

            return(Context);
        }
示例#11
0
        public override void AddOperation(IOperation <T> operation, ICheckConstraint constraint)
        {
            var operationPair = new OperationDuplex <T>(new OperationInvoker <T>(operation as BasicOperation <T>), constraint);

            ParallelOperations.Add(operationPair);
        }
示例#12
0
        public override void AddOperation(IWorkflow <T> workflow)
        {
            var operationPair = new OperationDuplex <T>(new WorkflowInvoker <T>(workflow));

            taskList.Tasks.Add(operationPair);
        }
示例#13
0
        public override void AddOperation(IOperation <T> operation)
        {
            var operationPair = new OperationDuplex <T>(new OperationInvoker <T>(operation as BasicOperation <T>));

            ParallelOperations.Add(operationPair);
        }
示例#14
0
        public override void AddOperation(IWorkflow <T> workflow, ICheckConstraint constraint)
        {
            var operationPair = new OperationDuplex <T>(new WorkflowInvoker <T>(workflow), constraint);

            ParallelOperations.Add(operationPair);
        }
示例#15
0
        public override void AddOperation(IWorkflow <T> workflow)
        {
            var operationPair = new OperationDuplex <T>(new WorkflowInvoker <T>(workflow));

            ParallelOperations.Add(operationPair);
        }
示例#16
0
        public override void AddOperation(Func <T, T> function)
        {
            var operationPair = new OperationDuplex <T>(new FunctionInvoker <T>(function));

            taskList.Tasks.Add(operationPair);
        }
示例#17
0
 public void Add(OperationDuplex <T> operation)
 {
     RegisteredOperations.Add(operation);
 }
示例#18
0
        public override void AddOperation(Func <T, T> function)
        {
            var operationPair = new OperationDuplex <T>(new FunctionInvoker <T>(function));

            ParallelOperations.Add(operationPair);
        }
示例#19
0
        public override void AddOperation(Func <T, T> function, ICheckConstraint constraint)
        {
            var operationPair = new OperationDuplex <T>(new FunctionInvoker <T>(function), constraint);

            ParallelOperations.Add(operationPair);
        }
示例#20
0
 public virtual T Execute(OperationDuplex <T> operationPair)
 {
     return(Execute(operationPair, default(T)));
 }
示例#21
0
        public override void AddOperation(IOperation <T> operation)
        {
            var operationPair = new OperationDuplex <T>(new OperationInvoker <T>(operation as BasicOperation <T>));

            taskList.Tasks.Add(operationPair);
        }