Esempio n. 1
0
        /// <summary>
        /// Start Workflow.
        /// </summary>
        /// <param name="AD_Workflow_ID">AD_Workflow_ID </param>
        /// <returns>true if started</returns>
        private bool StartWorkflow(int AD_Workflow_ID)
        {
            //Remote process not implemented
            //Only local process is implemented
            //log.Fine(AD_Workflow_ID + " - " + _pi.ToString());
            bool started = false;

            //	Run locally
            if (!started)
            {
                MWorkflow  WF        = new MWorkflow(_ctx, AD_Workflow_ID, null);
                MWFProcess wfProcess = null;
                if (_pi.IsBatch())
                {
                    wfProcess = WF.Start(_pi);          //	may return null
                }
                else
                {
                    wfProcess = WF.StartWait(_pi);      //	may return null
                }
                started = wfProcess != null;
            }

            return(started);
        }
Esempio n. 2
0
        /// <summary>
        /// Run Workflow (and wait) on Server
        /// @ejb.interface-method view-type="both"
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="pi"></param>
        /// <param name="AD_Workflow_ID"></param>
        /// <returns></returns>
        public ProcessInfo Workflow(Ctx ctx, ProcessInfo pi, int AD_Workflow_ID)
        {
            log.Info("[" + _no + "] " + AD_Workflow_ID);
            _workflowCount++;
            MWorkflow  wf        = MWorkflow.Get(ctx, AD_Workflow_ID);
            MWFProcess wfProcess = null;

            if (pi.IsBatch())
            {
                wfProcess = wf.Start(pi);       //	may return null
            }
            else
            {
                wfProcess = wf.StartWait(pi);   //	may return null
            }
            log.Fine(pi.ToString());
            return(pi);
        }
Esempio n. 3
0
        }   //  sendAlert

        private int sendAlertToResponsible(MWFResponsible responsible, List <int> list, MWFProcess process, String subject, String message, FileInfo pdf)
        {
            int counter = 0;

            if (responsible.IsInvoker())
            {
                ;
            }
            //	Human
            else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Human.Equals(responsible.GetResponsibleType()) &&
                     responsible.GetAD_User_ID() != 0 &&
                     !list.Contains(responsible.GetAD_User_ID()))
            {
                if (m_client.SendEMail(responsible.GetAD_User_ID(), subject, message, pdf))
                {
                    counter++;
                }
                list.Add(responsible.GetAD_User_ID());
            }
            //	Org of the Document
            else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Organization.Equals(responsible.GetResponsibleType()))
            {
                PO document = process.GetPO();
                if (document != null)
                {
                    MOrgInfo org = MOrgInfo.Get(GetCtx(), document.GetAD_Org_ID(), null);
                    if (org.GetSupervisor_ID() != 0 &&
                        !list.Contains(org.GetSupervisor_ID()))
                    {
                        if (m_client.SendEMail(org.GetSupervisor_ID(), subject, message, pdf))
                        {
                            counter++;
                        }
                        list.Add(org.GetSupervisor_ID());
                    }
                }
            }
            //	Role
            else if (X_AD_WF_Responsible.RESPONSIBLETYPE_Role.Equals(responsible.GetResponsibleType()) &&
                     responsible.GetAD_Role_ID() != 0)
            {
                MUserRoles[] userRoles = MUserRoles.GetOfRole(GetCtx(), responsible.GetAD_Role_ID());
                for (int i = 0; i < userRoles.Length; i++)
                {
                    MUserRoles roles = userRoles[i];
                    if (!roles.IsActive())
                    {
                        continue;
                    }
                    int AD_User_ID = roles.GetAD_User_ID();
                    if (!list.Contains(AD_User_ID))
                    {
                        if (m_client.SendEMail(AD_User_ID, subject, message, pdf))
                        {
                            counter++;
                        }
                        list.Add(AD_User_ID);
                    }
                }
            }
            return(counter);
        }       //	sendAlertToResponsible
Esempio n. 4
0
        }       //	sendAlerts

        private int SendEmail(MWFActivity activity, String AD_Message, bool toProcess, bool toSupervisor)
        {
            if (m_client == null || m_client.GetAD_Client_ID() != activity.GetAD_Client_ID())
            {
                m_client = MClient.Get(GetCtx(), activity.GetAD_Client_ID());
            }

            MWFProcess process = new MWFProcess(GetCtx(), activity.GetAD_WF_Process_ID(), null);

            String subjectVar = activity.GetNode().GetName();
            String message    = activity.GetTextMsg();

            if (message == null || message.Length == 0)
            {
                message = process.GetTextMsg();
            }
            FileInfo pdf = null;
            PO       po  = activity.GetPO();

            if (po is DocAction)
            {
                message = ((DocAction)po).GetDocumentInfo() + "\n" + message;
                pdf     = ((DocAction)po).CreatePDF();
            }

            //  Inactivity Alert: Workflow Activity {0}
            String subject = Msg.GetMsg(m_client.GetAD_Language(), AD_Message,
                                        new Object[] { subjectVar });

            //	Prevent duplicates
            List <int> list    = new List <int>();
            int        counter = 0;

            //	To Activity Owner
            if (m_client.SendEMail(activity.GetAD_User_ID(), subject, message, pdf))
            {
                counter++;
            }
            list.Add(activity.GetAD_User_ID());

            //	To Process Owner
            if (toProcess &&
                process.GetAD_User_ID() != activity.GetAD_User_ID())
            {
                if (m_client.SendEMail(process.GetAD_User_ID(), subject, message, pdf))
                {
                    counter++;
                }
                list.Add(process.GetAD_User_ID());
            }

            //	To Activity Responsible
            MWFResponsible responsible = MWFResponsible.Get(GetCtx(), activity.GetAD_WF_Responsible_ID());

            counter += sendAlertToResponsible(responsible, list, process, subject, message, pdf);

            //	To Process Responsible
            if (toProcess &&
                process.GetAD_WF_Responsible_ID() != activity.GetAD_WF_Responsible_ID())
            {
                responsible = MWFResponsible.Get(GetCtx(), process.GetAD_WF_Responsible_ID());
                counter    += sendAlertToResponsible(responsible, list, process, subject, message, pdf);
            }

            //	Processor SuperVisor
            if (toSupervisor && m_model.GetSupervisor_ID() != 0 &&
                !list.Contains(m_model.GetSupervisor_ID()))
            {
                if (m_client.SendEMail(m_model.GetSupervisor_ID(), subject, message, pdf))
                {
                    counter++;
                }
                list.Add(m_model.GetSupervisor_ID());
            }

            return(counter);
        }   //  sendAlert