/// <summary>
        /// Start Next Activity
        /// </summary>
        /// <param name="last">last activity</param>
        /// <param name="activities">all activities</param>
        /// <returns>true if there is a next activity</returns>
        private bool StartNext(MWFActivity last, MWFActivity[] activities)
        {
            log.Config("Last=" + last);
            //	transitions from the last processed node
            MWFNodeNext[] transitions = GetWorkflow().GetNodeNexts(last.GetAD_WF_Node_ID(), last.GetAD_Client_ID());
            if (transitions == null || transitions.Length == 0)
            {
                log.Config("none");
                return(false);   //	done
            }

            //	We need to wait for last activity
            if (MWFNode.JOINELEMENT_AND.Equals(last.GetNode().GetJoinElement()))
            {
                //	get previous nodes
                //	check if all have closed activities
                //	return false for all but the last
            }
            //	eliminate from active processed
            //last.SetProcessed(true);
            last.Set_ValueNoCheck("Processed", true);
            last.Save();

            //	Start next activity
            String split = last.GetNode().GetSplitElement();

            for (int i = 0; i < transitions.Length; i++)
            {
                //	Is this a valid transition?
                if (!transitions[i].IsValidFor(last))
                {
                    continue;
                }

                //	Start new Activity
                MWFActivity activity = new MWFActivity(this, transitions[i].GetAD_WF_Next_ID());
                // set Last Activity ID property in current WF Activity
                activity.SetLastActivity(last.GetAD_WF_Activity_ID());
                // new Thread(activity).Start();
                //thred = new Thread(new ThreadStart(activity.Run));
                //thred.CurrentCulture = Utility.Env.GetLanguage(Utility.Env.GetContext()).GetCulture(Utility.Env.GetLoginLanguage(Utility.Env.GetContext()).GetAD_Language());
                //thred.CurrentUICulture = Utility.Env.GetLanguage(Utility.Env.GetContext()).GetCulture(Utility.Env.GetLoginLanguage(Utility.Env.GetContext()).GetAD_Language());
                activity.Run();
                // thred.Start();

                //	only the first valid if XOR
                if (MWFNode.SPLITELEMENT_XOR.Equals(split))
                {
                    return(true);
                }
            }   //	for all transitions
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Check Status of Activities.
        /// - update Process if required
        /// - start new activity
        /// </summary>
        public void CheckActivities()
        {
            log.Info(ToString());
            if (_state.IsClosed())
            {
                return;
            }
            //
            MWFActivity[] activities  = GetActivities(true, true);      //	requery active
            String        closedState = null;
            bool          suspended   = false;
            bool          running     = false;

            for (int i = 0; i < activities.Length; i++)
            {
                MWFActivity activity = activities[i];
                activity.SetAD_Window_ID(GetAD_Window_ID());
                StateEngine activityState = activity.GetState();

                //	Completed - Start Next
                if (activityState.IsCompleted() || activityState.IsBackground())
                {
                    if (StartNext(activity, activities))
                    {
                        continue;
                    }
                }
                //
                String activityWFState = activity.GetWFState();
                if (activityState.IsClosed() || activityState.IsBackground())
                {
                    //	eliminate from active processed
                    //activity.SetProcessed(true);
                    activity.Set_ValueNoCheck("Processed", true);
                    //activities
                    activity.Save();
                    //
                    if (closedState == null)
                    {
                        closedState = activityWFState;
                    }
                    else if (!closedState.Equals(activityState))
                    {
                        //	Overwrite if terminated
                        if (WFSTATE_Terminated.Equals(activityState))
                        {
                            closedState = activityWFState;
                        }
                        //	Overwrite if activity aborted and no other terminated
                        else if (WFSTATE_Aborted.Equals(activityState) && !WFSTATE_Terminated.Equals(closedState))
                        {
                            closedState = activityWFState;
                        }
                    }
                }
                else                    //	not closed
                {
                    closedState = null; //	all need to be closed
                    if (activityState.IsSuspended())
                    {
                        suspended = true;
                    }
                    if (activityState.IsRunning())
                    {
                        running = true;
                    }
                }
            }   //	for all activities
            if (activities.Length == 0)
            {
                SetTextMsg("No Active Processed found");
                closedState = WFSTATE_Terminated;
            }
            if (closedState != null)
            {
                if (closedState == StateEngine.STATE_BACKGROUND)
                {
                    _state.SetState(StateEngine.STATE_BACKGROUND);
                }
                SetWFState(closedState);
                GetPO();
                if (_po != null)
                {
                    _po.Unlock(Get_TrxName());
                }
            }
            else if (suspended)
            {
                SetWFState(WFSTATE_Suspended);
            }
            else if (running)
            {
                SetWFState(WFSTATE_Running);
            }
        }