Пример #1
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);
            }
        }