/// ////////////////////////////////////////// public override CResultAErreur VerifieParametres() { CResultAErreur result = base.VerifieParametres(); if (!result) { return(result); } C2iExpressionChamp expressionChamp = Parametres2i[0] as C2iExpressionChamp; if (expressionChamp == null) { C2iExpressionObjet expressionObjet = Parametres2i[0] as C2iExpressionObjet; while (expressionObjet != null && expressionChamp == null) { expressionChamp = expressionObjet.Parametres2i[1] as C2iExpressionChamp; expressionObjet = expressionObjet.Parametres2i[1] as C2iExpressionObjet; } } if (!(expressionChamp is C2iExpressionChamp)) { result.EmpileErreur(I.T("The 'Set' first parameter must be a variable|134")); return(result); } return(result); }
//----------------------------------------------- public CResultAErreur RefreshFormuleFinale() { m_formuleFinale = null; CResultAErreur result = CResultAErreur.True; C2iExpressionBegin formule = new C2iExpressionBegin(); foreach (CDefinitionProprieteDynamiqueVariableFormule def in m_listeVariables) { C2iExpressionVariable var = new C2iExpressionVariable(); C2iExpression exp = new C2iExpressionChamp(); ((C2iExpressionChamp)exp).DefinitionPropriete = def; var.Parametres.Add(exp); exp = new C2iExpressionConstante(def.TypeDonnee.TypeDotNetNatif.ToString()); var.Parametres.Add(exp); if (def.TypeDonnee.IsArrayOfTypeNatif) { exp = new C2iExpressionVrai(); var.Parametres.Add(exp); } formule.Parametres.Add(var); } CRepresentationExpressionGraphique graf = StartPoint; if (graf == null) { result.EmpileErreur(I.T("No start point|20103")); return(result); } while (graf != null) { result = graf.RefreshParametres(); if (!result) { return(result); } if (graf.Formule != null) { formule.Parametres.Add(graf.Formule); } graf = graf.Next; } m_formuleFinale = formule; return(CResultAErreur.True); }
//------------------------------------------------------- protected override CResultAErreur ProtectedEval(CContexteEvaluationExpression ctx) { CResultAErreur result = CResultAErreur.True; try { C2iExpressionChamp champ = Parametres2i[0] as C2iExpressionChamp; if (champ == null || champ.DefinitionPropriete as CDefinitionProprieteDynamiqueVariableFormule == null) { result.EmpileErreur(I.T("Bad parameter for VAR|20005")); return(result); } ctx.AddVariable(champ.DefinitionPropriete as CDefinitionProprieteDynamiqueVariableFormule); result.Data = null; } catch { result.EmpileErreur(I.T("Error during the variable cration|132")); } return(result); }
/// ////////////////////////////////////////// public override CResultAErreur MyEval(CContexteEvaluationExpression ctx, object[] valeursParametres) { CResultAErreur result = CResultAErreur.True; try { C2iExpressionChamp champ = (C2iExpressionChamp)Parametres[0]; if (champ.DefinitionPropriete == null || champ.DefinitionPropriete.IsReadOnly) { result.EmpileErreur(I.T("Impossible to affect a value to @1|133", champ.DefinitionPropriete == null?"null":champ.DefinitionPropriete.Nom)); return(result); } ctx.SetValeurVariable(champ.DefinitionPropriete, valeursParametres[1]); result.Data = valeursParametres[1]; } catch { result.EmpileErreur(I.T("Error during the variable creation|132")); } return(result); }
/// ////////////////////////////////////////// public override CResultAErreur AfterAnalyse(CAnalyseurSyntaxique analyseur) { CResultAErreur result = CResultAErreur.True; bool bIsTableau = false; Type tp = null; CAnalyseurSyntaxiqueExpression analyseurExpression = analyseur as CAnalyseurSyntaxiqueExpression; if (analyseurExpression != null) { C2iExpressionChamp champ = Parametres2i[0] as C2iExpressionChamp; //Vérifie que les paramètres sont bien des constantes string bool bParamOk = false; if (Parametres.Count >= 2) { if (Parametres[0] is C2iExpressionChamp && (Parametres[1] is C2iExpressionConstante || Parametres[1] is C2iExpressionTypesDynamics) && (Parametres.Count != 3 || Parametres[2] is C2iExpressionConstante || Parametres[2] is C2iExpressionVrai || Parametres[2] is C2iExpressionFaux)) { if (Parametres[1] is C2iExpressionTypesDynamics) { tp = ((C2iExpressionTypesDynamics)Parametres[1]).TypeReprésenté; } else if (Parametres[1] is Type) { tp = Parametres[1] as Type; } else { string strType = ((C2iExpressionConstante)Parametres2i[1]).Valeur.ToString(); tp = CActivatorSurChaine.GetType(strType, true); } if (tp == null) { result.EmpileErreur(I.T("The @1 type doesn't exist|136", Parametres[1].ToString())); return(result); } else { if (Parametres.Count == 3 && Parametres2i[2] is C2iExpressionConstante) { if (((C2iExpressionConstante)Parametres[2]).Valeur is int) { bIsTableau = (int)(((C2iExpressionConstante)Parametres[2]).Valeur) != 0; } if (((C2iExpressionConstante)Parametres[2]).Valeur is bool) { bIsTableau = (bool)((C2iExpressionConstante)Parametres[2]).Valeur; } } if (Parametres.Count == 3 && Parametres[2] is C2iExpressionVrai) { bIsTableau = true; } if (Parametres.Count == 3 && Parametres[2] is C2iExpressionFaux) { bIsTableau = false; } bParamOk = true; } } } if (!bParamOk) { result.EmpileErreur(I.T("The Var function paramters are invalid (two constant string are awaited and possibly one Boolean for the table)|138")); return(result); } CDefinitionProprieteDynamiqueVariableFormule def = new CDefinitionProprieteDynamiqueVariableFormule( champ.DefinitionPropriete.Nom, new CTypeResultatExpression(tp, bIsTableau), false); champ.DefinitionPropriete = def; analyseurExpression.AddVariable(def); } return(base.AfterAnalyse(analyseur)); }
/// ////////////////////////////////////////// protected override CResultAErreur ProtectedEval(CContexteEvaluationExpression ctx) { CResultAErreur result = CResultAErreur.True; try { C2iExpressionChamp champFinal = null; object objSource = ctx.ObjetSource; result = GetSourceEtChampFinal(Parametres2i[0], ctx, ref objSource, ref champFinal); if (!result) { return(result); } if (champFinal == null) { result.EmpileErreur(I.T("Impossible to affect a value to @1|133", Parametres2i[0].ToString())); return(result); } result = Parametres2i[1].Eval(ctx); if (!result) { return(result); } object valeur = result.Data; CDefinitionProprieteDynamiqueVariableFormule propFormule = champFinal.DefinitionPropriete as CDefinitionProprieteDynamiqueVariableFormule; if (propFormule != null) { ctx.SetValeurVariable(propFormule, valeur); } else { if (objSource == null) { return(result); } SynchronizationContext c = ctx.SynchronizationContext; if (c != null) { c.Post(x => CInterpreteurProprieteDynamique.SetValue(objSource, champFinal.DefinitionPropriete.NomPropriete, valeur), null); } else { result = CInterpreteurProprieteDynamique.SetValue(objSource, champFinal.DefinitionPropriete.NomPropriete, valeur); } } if (result) { result.Data = valeur; if (objSource != null) { ctx.Cache.ResetCache(objSource); } } } catch (Exception e) { result.EmpileErreur(new CErreurException(e)); } return(result); }
/// ////////////////////////////////////////// private CResultAErreur GetSourceEtChampFinal(C2iExpression expression, CContexteEvaluationExpression ctx, ref object source, ref C2iExpressionChamp expressionChamp) { CResultAErreur result = CResultAErreur.True; expressionChamp = expression as C2iExpressionChamp; if (expressionChamp != null) { return(result); } C2iExpressionObjet expObjet = expression as C2iExpressionObjet; if (expObjet == null) { result.EmpileErreur(I.T("Impossible to affect a value to @1|133", expression.GetString())); } result = expObjet.Parametres2i[0].Eval(ctx); if (!result || result == null) { return(result); } ctx.PushObjetSource(result.Data, false); source = result.Data; result = GetSourceEtChampFinal(expObjet.Parametres2i[1], ctx, ref source, ref expressionChamp); ctx.PopObjetSource(false); return(result); }
//-------------------------------------------------- /// <summary> /// crée les éléments graphiques d'une formule /// </summary> /// <param name="formule"></param> public void InitFromFormule(C2iExpression formule) { m_listeRepresentations.Clear(); m_listeVariables.Clear(); if (formule == null) { return; } ArrayList lst = formule.ExtractExpressionsType(typeof(C2iExpressionVariable)); foreach (C2iExpressionVariable variable in lst) { if (variable.Parametres.Count > 0) { C2iExpressionChamp champ = variable.Parametres[0] as C2iExpressionChamp; if (champ != null) { CDefinitionProprieteDynamiqueVariableFormule def = champ.DefinitionPropriete as CDefinitionProprieteDynamiqueVariableFormule; if (def != null) { m_listeVariables.Add(def); } } } } C2iExpressionBegin begin = formule as C2iExpressionBegin; m_strIdStartPoint = ""; int nX = 100; int nY = 20; if (begin != null) { CRepresentationExpressionGraphique previous = null; foreach (C2iExpression action in begin.Parametres) { if (!(action is C2iExpressionVariable)) { CRepresentationExpressionGraphique rep = new CRepresentationExpressionGraphique(); rep.Position = new Point(nX, nY); AddChild(rep); rep.Parent = this; rep.Formule = action; nY = rep.RectangleAbsolu.Bottom; foreach (CRepresentationExpressionGraphique repTmp in m_listeRepresentations) { if (repTmp.RectangleAbsolu.Bottom > nY) { nY = rep.RectangleAbsolu.Bottom; } } nY += 20; if (previous == null) { StartPoint = rep; } else { previous.Next = rep; } previous = rep; } } } else { CRepresentationExpressionGraphique rep = new CRepresentationExpressionGraphique(); rep.Position = new Point(nX, nY); AddChild(rep); rep.Parent = this; rep.Formule = formule; StartPoint = rep; } }