/// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message (variables are parsed)</returns>
        protected override String DoIt()
        {
            MWFProcess process = new MWFProcess(GetCtx(), p_AD_WF_Process_ID, Get_Trx());

            log.Info("doIt - " + process);

            MUser user = MUser.Get(GetCtx(), GetAD_User_ID());

            //	Abort
            if (p_IsAbort)
            {
                msg = user.GetName() + ": Abort";
                process.SetTextMsg(msg);
                process.SetAD_User_ID(GetAD_User_ID());
                process.SetWFState(StateEngine.STATE_ABORTED);

                //JID_0278 : To mark processing checkbox false.
                // Mohit
                // Date : 22 May 2019
                MTable table = new MTable(GetCtx(), process.GetAD_Table_ID(), null);
                PO     po    = MTable.GetPO(GetCtx(), table.GetTableName(), process.GetRecord_ID(), Get_Trx());
                if (po != null && po.Get_ColumnIndex("Processing") >= 0)
                {
                    po.Set_Value("Processing", false);
                    po.Save();
                }
                return(msg);
            }

            //	Change User
            if (p_AD_User_ID != 0 && process.GetAD_User_ID() != p_AD_User_ID)
            {
                MUser from = MUser.Get(GetCtx(), process.GetAD_User_ID());
                MUser to   = MUser.Get(GetCtx(), p_AD_User_ID);
                msg = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                process.SetTextMsg(msg);
                process.SetAD_User_ID(p_AD_User_ID);
            }
            //	Change Responsible
            if (p_AD_WF_Responsible_ID != 0 && process.GetAD_WF_Responsible_ID() != p_AD_WF_Responsible_ID)
            {
                MWFResponsible from = MWFResponsible.Get(GetCtx(), process.GetAD_WF_Responsible_ID());
                MWFResponsible to   = MWFResponsible.Get(GetCtx(), p_AD_WF_Responsible_ID);
                String         msg1 = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                process.SetTextMsg(msg1);
                process.SetAD_WF_Responsible_ID(p_AD_WF_Responsible_ID);
                if (msg == null)
                {
                    msg = msg1;
                }
                else
                {
                    msg += " - " + msg1;
                }
            }
            process.Save();

            return("OK");
        }
        /// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns>Message (variables are parsed)</returns>
        protected override String DoIt()
        {
            MWFProcess process = new MWFProcess(GetCtx(), p_AD_WF_Process_ID, Get_Trx());

            log.Info("doIt - " + process);

            MUser user = MUser.Get(GetCtx(), GetAD_User_ID());

            //	Abort
            if (p_IsAbort)
            {
                msg = user.GetName() + ": Abort";
                process.SetTextMsg(msg);
                process.SetAD_User_ID(GetAD_User_ID());
                process.SetWFState(StateEngine.STATE_ABORTED);
                return(msg);
            }

            //	Change User
            if (p_AD_User_ID != 0 && process.GetAD_User_ID() != p_AD_User_ID)
            {
                MUser from = MUser.Get(GetCtx(), process.GetAD_User_ID());
                MUser to   = MUser.Get(GetCtx(), p_AD_User_ID);
                msg = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                process.SetTextMsg(msg);
                process.SetAD_User_ID(p_AD_User_ID);
            }
            //	Change Responsible
            if (p_AD_WF_Responsible_ID != 0 && process.GetAD_WF_Responsible_ID() != p_AD_WF_Responsible_ID)
            {
                MWFResponsible from = MWFResponsible.Get(GetCtx(), process.GetAD_WF_Responsible_ID());
                MWFResponsible to   = MWFResponsible.Get(GetCtx(), p_AD_WF_Responsible_ID);
                String         msg1 = user.GetName() + ": " + from.GetName() + " -> " + to.GetName();
                process.SetTextMsg(msg1);
                process.SetAD_WF_Responsible_ID(p_AD_WF_Responsible_ID);
                if (msg == null)
                {
                    msg = msg1;
                }
                else
                {
                    msg += " - " + msg1;
                }
            }
            process.Save();

            return("OK");
        }
Beispiel #3
0
        /// <summary>
        /// Start Workflow.
        /// </summary>
        /// <param name="pi">Info (Record_ID)</param>
        /// <returns>process</returns>
        public MWFProcess Start(ProcessInfo pi)
        {
            MWFProcess retValue = null;

            try
            {
                retValue = new MWFProcess(this, pi);
                retValue.Save();
                retValue.StartWork();
                pi.SetSummary(Msg.GetMsg(GetCtx(), "Processing", true));
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, e.Message, e);
                pi.SetSummary(e.Message, true);
                retValue = null;
            }
            return(retValue);
        }
Beispiel #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() && !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);
        }
Beispiel #5
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);
        }