Example #1
0
        //-----------------------------------------------------------------------------------------------------
        private void m_menuCreateStep_Click(object sender, EventArgs e)
        {
            CEtapeWorkflow etape = EtapeSelectionnee;

            if (etape == null)
            {
                using (CContexteDonnee ctx = new CContexteDonnee(m_workflowRacine.ContexteDonnee.IdSession, true, false))
                {
                    CWorkflow wkf = m_stackWorkflows.Peek();
                    if (wkf != null)
                    {
                        wkf = wkf.GetObjetInContexte(ctx) as CWorkflow;
                        CResultAErreurType <CEtapeWorkflow> res = wkf.CreateOrGetEtapeInCurrentContexte(TypeEtapeSelectionnee);
                        if (!res)
                        {
                            CFormAlerte.Afficher(res.Erreur);
                            return;
                        }
                        CResultAErreur result = ctx.SaveAll(true);
                        if (!result)
                        {
                            CFormAlerte.Afficher(result.Erreur);
                            return;
                        }
                    }
                }
            }
        }
Example #2
0
        //-----------------------------------------------------------------------------------------------------
        private void m_menuStartStep_Click(object sender, EventArgs e)
        {
            CEtapeWorkflow etape = EtapeSelectionnee;
            CWorkflow      wkf   = m_stackWorkflows.Peek();

            using (CContexteDonnee ctx = new CContexteDonnee(wkf.ContexteDonnee.IdSession, true, false))
            {
                wkf = wkf.GetObjetInContexte(ctx) as CWorkflow;
                CTypeEtapeWorkflow typeEtape = TypeEtapeSelectionnee;
                if (etape != null)
                {
                    typeEtape = etape.TypeEtape;
                }

                CResultAErreurType <CEtapeWorkflow> resEtape = wkf.CreateOrGetEtapeInCurrentContexte(typeEtape);
                if (!resEtape)
                {
                    CFormAlerte.Afficher(resEtape.Erreur);
                    return;
                }
                etape = resEtape.DataType;



                etape = etape.GetObjetInContexte(ctx) as CEtapeWorkflow;
                etape.InternalSetInfosDemarrageInCurrentContext();
                CResultAErreur result = ctx.SaveAll(true);
                if (!result)
                {
                    CFormAlerte.Afficher(result.Erreur);
                }
                Refresh();
            }
        }
        //--------------------------------------------------------------------------
        public static CResultAErreur LinkProjetToWorkflowStep(CProjet projet,
                                                              CWorkflow workflow,
                                                              string strTypeEtape,
                                                              bool bSynchronizeStarts)
        {
            CResultAErreur     result    = CResultAErreur.True;
            CTypeEtapeWorkflow typeEtape = new CTypeEtapeWorkflow(projet.ContexteDonnee);

            if (!typeEtape.ReadIfExists(new CFiltreData(CObjetDonnee.c_champIdUniversel + "=@1",
                                                        strTypeEtape)))
            {
                result.EmpileErreur(I.T("Workflow step type @1 doesn't exists|20196", strTypeEtape));
                return(result);
            }
            if (typeEtape.Workflow.Id != workflow.TypeWorkflow.Id)
            {
                result.EmpileErreur(I.T("Workflow step type @1 doesn't belong to workflow type @2|20197"),
                                    strTypeEtape, workflow.TypeWorkflow.Libelle);
                return(result);
            }
            CBlocWorkflowProjet blocProjet = typeEtape.Bloc as CBlocWorkflowProjet;

            if (blocProjet == null)
            {
                result.EmpileErreur(I.T("Step type @1 is not a valid project step|20198",
                                        typeEtape.Libelle));
                return(result);
            }
            CResultAErreurType <CEtapeWorkflow> resEtape = workflow.CreateOrGetEtapeInCurrentContexte(typeEtape);

            if (!resEtape)
            {
                result.EmpileErreur(resEtape.Erreur);
                return(result);
            }
            if (resEtape.DataType == null)
            {
                result.EmpileErreur(I.T("Erreur while creating step for type '@1'|20199",
                                        typeEtape.Libelle));
                return(result);
            }
            CWorkflow sousWkf = blocProjet.GetOrCreateWorkflowInCurrentContexte(resEtape.DataType);

            if (sousWkf == null)
            {
                result.EmpileErreur(I.T("Erreur while creating workflow for stef @1|20200",
                                        resEtape.DataType.Libelle));
                return(result);
            }
            sousWkf.SetValeurChamp(blocProjet.IdChampProjet.Value, projet);
            projet.GanttId = blocProjet.GetGanttId(resEtape.DataType);
            return(SynchroniseWorkflow(
                       sousWkf,
                       projet,
                       projet.DateDebutReel != null && projet.DateFinRelle == null,
                       bSynchronizeStarts));
        }
        //-------------------------------------------------------------------------------------
        private static CResultAErreur CreateProjets(CWorkflow workflow, CTypeEtapeWorkflow typeEtape, CProjet projetParent)
        {
            CResultAErreur result = CResultAErreur.True;

            if (workflow == null || typeEtape == null)
            {
                return(result);
            }
            CBlocWorkflowProjet blocProjet = typeEtape.Bloc as CBlocWorkflowProjet;

            if (blocProjet != null)
            {
                CResultAErreurType <CEtapeWorkflow> resEtape = workflow.CreateOrGetEtapeInCurrentContexte(typeEtape);
                if (!resEtape)
                {
                    result.EmpileErreur(resEtape.Erreur);
                    return(result);
                }
                if (resEtape.DataType != null)
                {
                    CResultAErreurType <CProjet> resProjet = blocProjet.GetOrCreateProjetInCurrentContexte(resEtape.DataType, projetParent, FindPredecesseurs(resEtape.DataType));
                    if (!resProjet)
                    {
                        result.EmpileErreur(resProjet.Erreur);
                        return(result);
                    }
                    CWorkflow workflowDuProjet = blocProjet.GetOrCreateWorkflowInCurrentContexte(resEtape.DataType);
                    result = CreateSqueletteProjetsInCurrentContext(workflowDuProjet, null, resProjet.DataType);
                    if (!result)
                    {
                        return(result);
                    }
                }
            }
            foreach (CLienEtapesWorkflow lien in LiensSuivantsPourProjet(typeEtape))
            {
                result += CreateProjets(workflow, lien.EtapeDestination, projetParent);
            }
            return(result);
        }
        //--------------------------------------------------------------------------
        /// <summary>
        /// Resynchronise un workflow avec un projet
        /// </summary>
        /// <param name="wkf"></param>
        /// <param name="projetRacine"></param>
        public static CResultAErreur SynchroniseWorkflow(
            CWorkflow wkf,
            CProjet projetParent,
            bool bShouldStartWorkflow,
            bool bSynchroniserStarts)
        {
            CResultAErreur result = CResultAErreur.True;
            //Identifie toutes les étapes BlocWorkflowWorkflow
            List <CTypeEtapeWorkflow> lstTypeWkfWkf = new List <CTypeEtapeWorkflow>();

            foreach (CTypeEtapeWorkflow typeEtape in wkf.TypeWorkflow.Etapes)
            {
                if (typeEtape.Bloc is CBlocWorkflowWorkflow)
                {
                    lstTypeWkfWkf.Add(typeEtape);
                }
            }
            foreach (CTypeEtapeWorkflow typeEtape in lstTypeWkfWkf)
            {
                CResultAErreurType <CEtapeWorkflow> resEtape = wkf.CreateOrGetEtapeInCurrentContexte(typeEtape);
                if (!resEtape || resEtape.DataType == null)
                {
                    result.EmpileErreur(I.T("Error while creating step '@1'", typeEtape.Libelle));
                    result.EmpileErreur(resEtape.Erreur);
                    return(result);
                }

                CBlocWorkflowWorkflow blocWkfWkf = typeEtape.Bloc as CBlocWorkflowWorkflow;

                CEtapeWorkflow etape = resEtape.DataType;

                CWorkflow sousWorkflow = blocWkfWkf.GetOrCreateWorkflowInCurrentContexte(etape);


                //Trouve le projet associé à l'étape
                CBlocWorkflowProjet blocProjet = blocWkfWkf as CBlocWorkflowProjet;
                if (blocProjet != null)
                {
                    CProjet projetEtape = FindProjetPourRattrapage(
                        projetParent, etape, blocProjet);

                    if (projetEtape != null)
                    {
                        if (blocProjet.IdChampProjet == null)
                        {
                            result.EmpileErreur(I.T("Workflow step @1 doesn't define a field to store associated project|20142", etape.Libelle));
                            return(result);
                        }
                        sousWorkflow.SetValeurChamp(blocProjet.IdChampProjet.Value, projetEtape);
                        bool bShouldStartSousWorkflow = projetEtape.DateDebutReel != null &&
                                                        projetEtape.DateFinRelle == null;
                        DateTime?oldDateDebut = projetEtape.DateDebutReel;
                        result = SynchroniseWorkflow(sousWorkflow, projetEtape, bShouldStartSousWorkflow, bSynchroniserStarts);
                        if (!result)
                        {
                            return(result);
                        }
                        if (bShouldStartSousWorkflow && oldDateDebut != null)//Remet les dates
                        {
                            etape.DateDebut           = oldDateDebut;
                            projetEtape.DateDebutReel = oldDateDebut;
                        }
                    }
                }
                else
                {
                    result = SynchroniseWorkflow(sousWorkflow, projetParent, false, bSynchroniserStarts);
                }
            }
            if (bShouldStartWorkflow && !wkf.IsRunning && bSynchroniserStarts)
            {
                wkf.StartWorkflow(null);
            }
            return(result);
        }