/// //////////////////////////////////////////////////////////////////
        protected static CResultAErreur AffecteVariablesToProcess(CActionSur2iLinkExecuterProcess action,
                                                                  CProcess process,
                                                                  object cible)
        {
            CResultAErreur result             = CResultAErreur.True;
            CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(cible);

            foreach (CFormuleNommee formule in action.FormulesPourParametres)
            {
                if (formule.Formule != null)
                {
                    result = formule.Formule.Eval(ctx);
                    if (!result)
                    {
                        result.EmpileErreur(I.T("Error while evaluating parameter @1|20128", formule.Libelle));
                        return(result);
                    }
                    bool bVariableFound = false;
                    foreach (CVariableDynamique variable in process.ListeVariables)
                    {
                        if (variable.Nom == formule.Libelle)
                        {
                            process.SetValeurChamp(variable.IdVariable, result.Data);
                            bVariableFound = true;
                            break;
                        }
                    }
                    if (!bVariableFound)
                    {
                        result.EmpileErreur(I.T("Process variable @1 doesn't exists|20129", formule.Libelle));
                        return(result);
                    }
                }
            }
            return(result);
        }
示例#2
0
        /* les parametres sont passés dans le table de paramètres :
         * Id de la variable, suivi de sa valeur( en texte ),...
         *
         */
        public string StartAction(int nIdAction, string[] strParametres)
        {
            DataSet ds = new DataSet();

            if (!AssureSession())
            {
                return("ERROR : " + I.T("Session error|30002"));
            }
            if ((strParametres.Length % 2) != 0)
            {
                return("ERROR : " + I.T("The parameters are not passed correctly|30003"));
            }

            using (CContexteDonnee contexte = new CContexteDonnee(m_session.IdSession, true, false))
            {
                CProcessInDb processInDb = new CProcessInDb(contexte);
                if (!processInDb.ReadIfExists(nIdAction))
                {
                    return("ERROR : " + I.T("The action @1 does not exist|30004", nIdAction.ToString()));
                }

                CProcess process = processInDb.Process;
                #region Affectation des variables du process
                for (int nVariable = 0; nVariable < strParametres.Length; nVariable += 2)
                {
                    string             strVariable = strParametres[nVariable];
                    IVariableDynamique variable    = null;
                    try
                    {
                        variable = process.GetVariable(strVariable);
                    }
                    catch
                    {
                        foreach (CVariableDynamique varTest in process.ListeVariables)
                        {
                            if (varTest.Nom.ToUpper() == strVariable.ToUpper())
                            {
                                variable = varTest;
                                break;
                            }
                        }
                        if (variable == null)
                        {
                            return("ERROR : " + I.T("@1 is not a valid variable id|30005", strVariable));
                        }
                    }
                    if (!(variable is CVariableDynamiqueSaisie))
                    {
                        return("ERROR : " + I.T("The variable @1 is not valid or does not exist|30006", strVariable));
                    }

                    try
                    {
                        object valeur = ((CVariableDynamiqueSaisie)variable).TypeDonnee2i.StringToType(strParametres[nVariable + 1], null);
                        process.SetValeurChamp(variable, valeur);
                    }
                    catch
                    {
                        return("ERROR : " + I.T("Error in affectation of variable @1|30007", variable.Nom));
                    }
                }
                #endregion

                //Note : le service web ne sait pas lancer un process dans une version
                CResultAErreur result = CProcessEnExecutionInDb.StartProcess(process, new CInfoDeclencheurProcess(TypeEvenement.Manuel), m_session.IdSession, null, null);
                if (!result)
                {
                    return("ERROR : " + result.Erreur.ToString());
                }
                if (result.Data != null)
                {
                    return(result.Data.ToString());
                }
                return(null);
            }
        }
示例#3
0
        //-----------------------------------------------------------
        public static CResultAErreur RunProcess(int nIdProcess, Dictionary <string, string> valeursParametres)
        {
            AssureTimerNettoyage();
            CResultAErreur result = GetSession();

            if (!result)
            {
                return(result);
            }
            CDonneeSessionProcess donneeSession = result.Data as CDonneeSessionProcess;

            result = CResultAErreur.True;
            try
            {
                CSessionClient session = donneeSession.SessionClient;
                using (CContexteDonnee contexte = new CContexteDonnee(session.IdSession, true, false))
                {
                    CProcessInDb processInDb = new CProcessInDb(contexte);
                    if (!processInDb.ReadIfExists(nIdProcess))
                    {
                        result.EmpileErreur(I.T("The process @1 doesn't exist|30008", nIdProcess.ToString()));
                        result.Data = (int)EErreurs.ProcessDoesntExists;
                        return(result);
                    }
                    CProcess process = processInDb.Process;
                    foreach (KeyValuePair <string, string> parametre in valeursParametres)
                    {
                        string strParametre = parametre.Key;
                        string strValeur    = parametre.Value;
                        bool   bTrouvee     = false;
                        foreach (IVariableDynamique variable in process.ListeVariables)
                        {
                            if (strParametre.ToUpper() == variable.Nom.ToUpper())
                            {
                                if (!variable.TypeDonnee.TypeDotNetNatif.IsValueType && variable.TypeDonnee.TypeDotNetNatif != typeof(string))
                                {
                                    result.EmpileErreur(I.T("Variable @1 cannot be set by TimosProcess. Only simple values can be used|30009", variable.Nom));
                                    result.Data = (int)EErreurs.InvalidVariableValueOnlySimpleValuesAreAccepted;
                                    return(result);
                                }
                                try
                                {
                                    object valeur = CUtilTexte.FromUniversalString(strValeur, variable.TypeDonnee.TypeDotNetNatif);
                                }
                                catch
                                {
                                }
                                process.SetValeurChamp(variable.IdVariable, strValeur);
                                bTrouvee = true;
                                break;
                            }
                        }
                        if (!bTrouvee)
                        {
                            result = ShowHelp(process);
                            result.EmpileErreur(I.T("Unknown variable @1|30010", strParametre));
                            result.Data = (int)EErreurs.UnknownVariable;
                            return(result);
                        }
                    }
                    result = CProcessEnExecutionInDb.StartProcess(process, new CInfoDeclencheurProcess(TypeEvenement.Manuel), session.IdSession, null, null);
                    if (!result)
                    {
                        result.Data = (int)EErreurs.ErrorWhileRunningProcess;
                        return(result);
                    }
                    if (result.Data != null)
                    {
                        try
                        {
                            result.Data = Convert.ToInt32(result.Data);
                        }
                        catch
                        {
                        }
                        return(result);
                    }
                    else
                    {
                        result.Data = 0;
                    }
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
                result.Data = (int)EErreurs.ErrorWhileRunningProcess;
                return(result);
            }
            finally
            {
                lock (typeof(CLanceurProcessCommandLine))
                {
                    donneeSession.EndUsing();
                }
            }
            return(result);
        }