Пример #1
0
 /// <summary>
 /// Set Process State and update Actions
 /// </summary>
 /// <param name="WFState">WFState</param>
 public new void   SetWFState(String WFState)
 {
     if (_state == null)
     {
         _state = new StateEngine(GetWFState());
         _state.SetCtx(GetCtx());
     }
     if (_state.IsClosed())
     {
         return;
     }
     if (GetWFState().Equals(WFState))
     {
         return;
     }
     //
     if (_state.IsValidNewState(WFState))
     {
         log.Fine(ToString() + " => " + WFState);
         base.SetWFState(WFState);
         _state = new StateEngine(GetWFState());
         _state.SetCtx(GetCtx());
         if (_state.IsClosed() || _state.IsBackground())
         {
             SetProcessed(true);
         }
         Save();
         //	Force close to all Activities
         if (_state.IsClosed() || _state.IsBackground())
         {
             MWFActivity[] activities = GetActivities(true, true);       //	requery only active
             for (int i = 0; i < activities.Length; i++)
             {
                 if (!activities[i].IsClosed())
                 {
                     activities[i].SetTextMsg("Process:" + WFState);
                     activities[i].SetWFState(WFState);
                 }
                 if (!activities[i].IsProcessed())
                 {
                     activities[i].SetProcessed(true);
                 }
                 activities[i].Save();
             }
         }       //	closed
     }
     else
     {
         log.Log(Level.SEVERE, "Ignored Invalid Transformation " + ToString() + " => " + WFState);
     }
 }
Пример #2
0
        //Thread worker = null;
        /// <summary>
        /// Start Workflow and Wait for completion.
        /// </summary>
        /// <param name="pi">process info with Record_ID record for the workflow</param>
        /// <returns>process</returns>
        public MWFProcess StartWait(ProcessInfo pi)
        {
            const int SLEEP    = 500; //	1/2 sec
            const int MAXLOOPS = 160; // 50;// 30;		//	15 sec
            //
            MWFProcess process = Start(pi);

            if (process == null)
            {
                return(null);
            }

            //Causes the currently executing thread object to temporarily pause
            //and allow other threads to execute.
            //Thread.yield();
            Thread.Sleep(0);

            StateEngine state = process.GetState();
            //worker = new Thread(new ThreadStart(process.Run));
            //worker.Start();
            int loops = 0;

            while (!state.IsClosed() && !state.IsSuspended() && !state.IsBackground())
            {
                if (loops > MAXLOOPS)
                {
                    // MessageBox.Show("Timeout after sec " + ((SLEEP * MAXLOOPS) / 1000));
                    pi.SetSummary(Msg.GetMsg(GetCtx(), "ProcessRunning", true));
                    pi.SetIsTimeout(true);
                    return(process);
                }
                try
                {
                    Thread.Sleep(SLEEP);
                    loops++;
                }
                catch (Exception e)
                {
                    log.Log(Level.SEVERE, "Interrupted", e);
                    pi.SetSummary("Interrupted");
                    return(process);
                }
                //Thread.yield();
                Thread.Sleep(0);
                state = process.GetState();
            }
            String summary = process.GetProcessMsg();

            // Change to get the Error Message and Display the Message
            ValueNamePair vp = VLogger.RetrieveAdvDocNoError();

            if (vp != null)
            {
                summary = vp.GetValue();
            }
            // Change to get the Error Message and Display the Message

            if (summary == null || summary.Trim().Length == 0)
            {
                // in case of Suspend (User Approval) show the workflow node on which it is suspended for approval
                if (state != null && state.GetState() == StateEngine.STATE_SUSPENDED)
                {
                    string node = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT n.Name FROM AD_WF_Activity ac INNER JOIN AD_WF_Node n ON ac.AD_WF_Node_ID = n.AD_WF_Node_ID WHERE
                                  ac.AD_WF_Process_ID = " + process.Get_ID() + " AND ac.WFState = '" + StateEngine.STATE_SUSPENDED + "'"));
                    if (!String.IsNullOrEmpty(node))
                    {
                        summary = state.ToString() + " " + Msg.GetMsg(GetCtx(), "For") + " " + node;
                    }
                }
                else
                {
                    summary = state.ToString();
                }
            }

            pi.SetSummary(summary, state.IsTerminated() || state.IsAborted());
            log.Fine(summary);
            return(process);
        }
Пример #3
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);
            }
        }
Пример #4
0
        //Thread worker = null;
        /// <summary>
        /// Start Workflow and Wait for completion.
        /// </summary>
        /// <param name="pi">process info with Record_ID record for the workflow</param>
        /// <returns>process</returns>
        public MWFProcess StartWait(ProcessInfo pi)
        {
            const int SLEEP    = 500; //	1/2 sec
            const int MAXLOOPS = 160; // 50;// 30;		//	15 sec
            //
            MWFProcess process = Start(pi);

            if (process == null)
            {
                return(null);
            }

            //Causes the currently executing thread object to temporarily pause
            //and allow other threads to execute.
            //Thread.yield();
            Thread.Sleep(0);

            StateEngine state = process.GetState();
            //worker = new Thread(new ThreadStart(process.Run));
            //worker.Start();
            int loops = 0;

            while (!state.IsClosed() && !state.IsSuspended())
            {
                if (loops > MAXLOOPS)
                {
                    // MessageBox.Show("Timeout after sec " + ((SLEEP * MAXLOOPS) / 1000));
                    pi.SetSummary(Msg.GetMsg(GetCtx(), "ProcessRunning", true));
                    pi.SetIsTimeout(true);
                    return(process);
                }
                try
                {
                    Thread.Sleep(SLEEP);
                    loops++;
                }
                catch (Exception e)
                {
                    log.Log(Level.SEVERE, "Interrupted", e);
                    pi.SetSummary("Interrupted");
                    return(process);
                }
                //Thread.yield();
                Thread.Sleep(0);
                state = process.GetState();
            }
            String summary = process.GetProcessMsg();

            // Change to get the Error Message and Display the Message
            ValueNamePair vp = VLogger.RetrieveAdvDocNoError();

            if (vp != null)
            {
                summary = vp.GetValue();
            }
            // Change to get the Error Message and Display the Message


            if (summary == null || summary.Trim().Length == 0)
            {
                summary = state.ToString();
            }



            pi.SetSummary(summary, state.IsTerminated() || state.IsAborted());
            log.Fine(summary);
            return(process);
        }