示例#1
0
        public bool visit(SWLWorkflowIterate <bool> node)
        {
            Console.WriteLine("ITERATE");
            Debug.Assert(node != null); Console.WriteLine(node != null);
            Debug.Assert(node.iterate_action != null); Console.WriteLine(node.iterate_action != null);

            bool breaking_flag = false;

            while (!breaking_flag)
            {
                try
                {
                    node.iterate_action.accept(this);
                }
                catch (SWLContinueException e)
                {
                    // DO NOTHING ! Proceed to the next iteration.
                }
                catch (SWLBreakException e)
                {
                    breaking_flag = true;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            return(true);
        }
        public bool visit(SWLWorkflowIterate <bool> node)
        {
            // TODO: Take "node.until_clause" into consideration

            Console.WriteLine("ITERATE");

            Debug.Assert(node != null); Console.WriteLine(node != null);
            Debug.Assert(node.iterate_action != null); Console.WriteLine(node.iterate_action != null);

            bool breaking_flag = false;

            while (!Terminate(node) && !breaking_flag)
            {
                try
                {
                    node.iterate_action.accept(this);
                }
                catch (SWLContinueException e)
                {
                    // DO NOTHING ! Proceed to the next iteration.
                }
                catch (SWLBreakException e)
                {
                    breaking_flag = true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(e.InnerException.Message);
                        Console.WriteLine(e.InnerException.StackTrace);
                    }
                    throw e;
                }
            }

            return(true);
        }
        private bool Terminate(SWLWorkflowIterate <bool> node)
        {
            if (node.exit_clause == null && node.enter_clause == null)
            {
                return(false);
            }

            Console.WriteLine("TERMINATE 1");

            IActionFutureSet fs = new ActionFutureSet();

            IActionFuture[] future_list       = new IActionFuture[node.exit_clause.Length];
            string[]        enter_action_list = new string[node.exit_clause.Length];
            string[]        exit_action_list  = new string[node.exit_clause.Length];

            for (int i = 0; i < node.exit_clause.Length; i++)
            {
                Console.WriteLine("TERMINATE 2 {0}", i);

                string exit_action = node.exit_clause[i].action;
                string exit_port   = node.exit_clause[i].id_port;

                string enter_action = node.enter_clause[i].action;
                string enter_port   = node.enter_clause[i].id_port;

                Console.WriteLine("TERMINATE 3 {0} / {1}.{2} -- {3}.{4}", i, exit_port, exit_action, enter_port, enter_action);

                // It is supposed that both exit and enter action ports are the same;
                ITaskBindingKind action_port_exit  = port(exit_port);
                ITaskBindingKind action_port_enter = port(enter_port);

                Debug.Assert(action_port_exit == action_port_enter, "ITERATION: EXIT and ENTER action ports are distinct ! Check !");

                Console.WriteLine("TERMINATE 4 {0} {1}", action_port_exit == null, action_port_enter == null);

                IActionFuture f;
                action_port_enter.invoke(new string[2] {
                    exit_action, enter_action
                }, out f);
                fs.addAction(f);

                Console.WriteLine("TERMINATE 5 {0}", i);

                future_list[i]       = f;
                enter_action_list[i] = enter_action;
                exit_action_list[i]  = exit_action;
            }

            Console.WriteLine("TERMINATE 6 -- BEFORE WAIT ALL");
            fs.waitAll();
            Console.WriteLine("TERMINATE 7 -- AFTER WAIT ALL");

            int end_iteration = 0;             //unknown=0; enter=1; exit=2

            for (int i = 0; i < future_list.Length; i++)
            {
                string action_result = (string)future_list[i].Action;

                Console.WriteLine("TERMINATE 8 i={0} -- result={1}", i, action_result);

                if (action_result.Equals(enter_action_list[i]) && end_iteration == 0)
                {
                    end_iteration = 1;
                }

                else if (action_result.Equals(exit_action_list[i]) && end_iteration == 0)
                {
                    end_iteration = 2;
                }

                else if (action_result.Equals(enter_action_list[i]) && end_iteration == 2)
                {
                    throw new Exception("ITERATE: Conflict in termination clause !");
                }

                else if (action_result.Equals(exit_action_list[i]) && end_iteration == 1)
                {
                    throw new Exception("ITERATE: Conflict in termination clause !");
                }

                Console.WriteLine("TERMINATE 9 i={0} -- end_iteration={1}", i, end_iteration);
            }

            return(end_iteration == 2);
        }