예제 #1
0
        //-------------------------------------------------------------------------
        private void LoadEtapesDepuisBase()
        {
            if (m_lastDateLookInDb == null ||
                ((TimeSpan)(DateTime.Now - m_lastDateLookInDb.Value)).TotalMilliseconds > c_nDelailLookInDb)
            {
                m_lastDateLookInDb = DateTime.Now;

                AssureSession();
                if (m_session != null)
                {
                    using (CContexteDonnee ctx = new CContexteDonnee(m_session.IdSession, true, false))
                    {
                        CFiltreData filtre = new CFiltreData(
                            CEtapeWorkflow.c_champEtat + "=@1",
                            (int)EEtatEtapeWorkflow.ADemarrer);
                        CListeObjetsDonnees lst = new CListeObjetsDonnees(ctx, typeof(CEtapeWorkflow));
                        lst.Filtre = filtre;
                        lst.AssureLectureFaite();
                        List <CParametresStartEtapeInPile> lstToStart = new List <CParametresStartEtapeInPile>();
                        foreach (CEtapeWorkflow etape in lst)
                        {
                            //TESTDBKEYTODO
                            CParametresStartEtapeInPile parametre = new CParametresStartEtapeInPile(
                                m_session.IdSession,
                                etape.Id,
                                etape.KeyDémarreur,
                                etape.DateDebut != null ? etape.DateDebut.Value : DateTime.Now);
                            lstToStart.Add(parametre);
                        }
                        AddEtapesADemarrer(lstToStart.ToArray());
                    }
                }
            }
        }
예제 #2
0
        //------------------------------------------------------------------------
        private void ExecuteEtape(CParametresStartEtapeInPile parametreStart)
        {
            //C2iEventLog.WriteInfo("DEBUG_TODO - ExecuteEtape()");
            List <CDonneeNotificationWorkflow> lstNotifications = new List <CDonneeNotificationWorkflow>();

            //TESTDBKEYTODO
            if (parametreStart.KeyUtilisateur != null)
            {
                m_session.ChangeUtilisateur(parametreStart.KeyUtilisateur);
            }
            try
            {
                using (CContexteDonnee ctx = new CContexteDonnee(m_session.IdSession, true, false))
                {
                    CResultAErreur result = CResultAErreur.True;
                    CEtapeWorkflow etape  = new CEtapeWorkflow(ctx);
                    //C2iEventLog.WriteInfo("DEBUG_TODO - ExecuteEtape() - etape.ReadIfExists(" + parametreStart.IdEtape + ")");
                    if (etape.ReadIfExists(parametreStart.IdEtape))
                    {
                        //C2iEventLog.WriteInfo("DEBUG_TODO - ExecuteEtape() OK étape existe Id = " + parametreStart.IdEtape);
                        result = etape.InternalSetInfosDemarrageInCurrentContext();
                        //C2iEventLog.WriteInfo("DEBUG_TODO - etape.InternalSetInfosDemarrageInCurrentContext() Id = " + parametreStart.IdEtape);
                        etape.EtatCode = (int)EEtatEtapeWorkflow.Démarrée;
                        result         = ctx.SaveAll(true);
                        //C2iEventLog.WriteInfo("DEBUG_TODO - ctx.SaveAll(true) Id = " + parametreStart.IdEtape + " - result = " + result.Result);

                        if (result)
                        {
                            //C2iEventLog.WriteInfo("DEBUG_TODO - before InternalRunAndSaveifOk() Id = " + parametreStart.IdEtape);
                            result = etape.InternalRunAndSaveifOk();
                            //C2iEventLog.WriteInfo("DEBUG_TODO - after InternalRunAndSaveifOk() Id = " + parametreStart.IdEtape);
                        }
                        else
                        {
                            C2iEventLog.WriteInfo("DEBUG_TODO - InternalRunAndSaveifOk() - Erreur : " + result.MessageErreur);
                        }
                        if (result && etape.CodeAffectations.Length > 0 && etape.DateFin == null)
                        {
                            CDonneeNotificationWorkflow donneeWorkflow = new CDonneeNotificationWorkflow(
                                m_session.IdSession,
                                etape.Id,
                                etape.Libelle,
                                etape.CodeAffectations,
                                etape.TypeEtape.ExecutionAutomatique);
                            lstNotifications.Add(donneeWorkflow);
                            // Déclenche l'evenement spécifique au démarrage de l'étape
                            result = etape.EnregistreEvenement(CEtapeWorkflow.c_codeEvenementOnRunStep, true);
                            //C2iEventLog.WriteInfo("DEBUG_TODO - ExecuteEtape() - etape.EnregistreEvenement()");
                        }
                        if (!result)
                        {
                            NoteErreurSurEtape(etape, result.MessageErreur);
                            return;
                        }
                        //C2iEventLog.WriteInfo("DEBUG_TODO - ExecuteEtape() - Fin traitement étape Id = " + parametreStart.IdEtape);
                    }
                }
            }
            catch (Exception e)
            {
                C2iEventLog.WriteErreur("DEBUG_TODO - ExecuteEtape() - Exception executing step Id  = " + parametreStart.IdEtape + Environment.NewLine + e.Message);
            }
            if (lstNotifications != null)
            {
                CEnvoyeurNotification.EnvoieNotifications(lstNotifications.ToArray());
            }
        }
예제 #3
0
        //------------------------------------------------------------------------
        //Démarre la prochaine étape de la liste
        private void StartNextEtape()
        {
            //C2iEventLog.WriteInfo("DEBUG_TODO - StartNextEtape()");
            CParametresStartEtapeInPile parametreToRun = null;

            lock (typeof(CLockerEtapes))
            {
                if (m_listeEtapes.Count == 0)
                {
                    return;
                }
                m_listeEtapes.Sort((x, y) => x.DateStart.CompareTo(y.DateStart));
                Dictionary <int, bool?> dicSessionsPrets = new Dictionary <int, bool?>();
                foreach (CParametresStartEtapeInPile parametre in m_listeEtapes)
                {
                    bool?bIsPrete = null;
                    if (parametre.IdSessionMain != null)
                    {
                        if (!dicSessionsPrets.TryGetValue(parametre.IdSessionMain.Value, out bIsPrete))
                        {
                            bIsPrete = IsTransactionTerminee(parametre.IdSessionMain.Value);
                            dicSessionsPrets[parametre.IdSessionMain.Value] = bIsPrete;
                        }
                    }
                    else
                    {
                        bIsPrete = true;
                    }
                    if (bIsPrete.Value)
                    {
                        //Vérifie que l'étape existe
                        C2iRequeteAvancee req = new C2iRequeteAvancee();
                        req.TableInterrogee = CEtapeWorkflow.c_nomTable;
                        req.ListeChamps.Add(new C2iChampDeRequete("ID",
                                                                  new CSourceDeChampDeRequete(CEtapeWorkflow.c_champId),
                                                                  typeof(int),
                                                                  OperationsAgregation.None,
                                                                  true));
                        req.FiltreAAppliquer = new CFiltreData(CEtapeWorkflow.c_champId + "=@1",
                                                               parametre.IdEtape);
                        //C2iEventLog.WriteInfo("DEBUG_TODO - StartNextEtape() - Vérifie que l'étape existe Id = " + parametre.IdEtape);

                        CResultAErreur result = req.ExecuteRequete(m_session.IdSession);
                        if (result && result.Data is DataTable && ((DataTable)result.Data).Rows.Count > 0)
                        {
                            //C2iEventLog.WriteInfo("DEBUG_TODO - StartNextEtape() - OK l'étape existe Id = " + parametre.IdEtape);
                            parametreToRun = parametre;
                            break;
                        }
                    }
                }
                if (parametreToRun != null)
                {
                    m_listeEtapes.Remove(parametreToRun);
                }
            }
            if (parametreToRun != null)
            {
                ExecuteEtape(parametreToRun);
            }
        }