Exemple #1
0
 /// <summary>
 /// Recursive find by name starting by a reference
 /// </summary>
 /// <param name="vars">all variables</param>
 /// <param name="types">all types</param>
 /// <param name="name">name to find</param>
 /// <returns>an accu child</returns>
 public static Accumulate.AccuChild RecursiveFindByName(Dictionary <string, LuigiVariable> vars, Dictionary <string, Accumulate.Accu> types, string name)
 {
     string[] seq = name.Split('.');
     if (seq.Length > 1)
     {
         if (vars.ContainsKey(seq[0].Substring(1)))
         {
             LuigiVariable v = vars[seq[0].Substring(1)];
             if (v.LeftValueType == LuigiVariableType.VAR && v.RightValueType == LuigiVariableType.NEW)
             {
                 // value est une reference sur un accu
                 Accumulate.Accu      a = Accumulate.Accu.FindByName(types, v.Value);
                 Accumulate.AccuChild c = Accumulate.AccuChild.RecursiveFindByName(a, 1, seq);
             }
             else
             {
                 throw new FormatException(String.Format("{0} is not a reference accu", seq[0]));
             }
         }
         else
         {
             throw new KeyNotFoundException(String.Format("Variable name {0} not found", seq[0]));
         }
     }
     else
     {
         throw new ArgumentException("bad name", "name");
     }
 }
Exemple #2
0
 /// <summary>
 /// Execute the variable
 /// </summary>
 /// <param name="w">writer</param>
 /// <param name="indentValue">space size</param>
 /// <param name="currentLine">in-progress line add</param>
 /// <param name="config">configuration</param>
 /// <param name="dir">directory</param>
 public void Execute(TextWriter w, ref int indentValue, ref string currentLine, Dictionary <string, LuigiVariable> vars, Dictionary <string, Accumulate.Accu> types, string dir)
 {
     if (LeftValueType == LuigiVariableType.VAR)
     {
     }
     else if (LeftValueType == LuigiVariableType.REF)
     {
         Accumulate.AccuChild a = Accumulate.Accu.RecursiveFindByName(types, this.name);
         if (RightValueType == LuigiVariableType.VAR)
         {
             if (vars.ContainsKey(this.value))
             {
                 a.Value = vars[this.value].Value;
             }
         }
         else if (RightValueType == LuigiVariableType.CONST)
         {
             a.Value = this.Value;
         }
         else if (RightValueType == LuigiVariableType.NEW)
         {
             Accumulate.Accu n = Accumulate.Accu.FindByName(types, this.Value);
             a.SetReference(n.TypeName);
         }
         else
         {
             // gets the variable element
             // set the accuchild with an another accuchild
             Accumulate.AccuChild b = Accumulate.Accu.RecursiveFindByName(types, this.name);
         }
     }
 }
Exemple #3
0
 /// <summary>
 /// Add a variable
 /// </summary>
 /// <param name="key">key name</param>
 /// <param name="obj">object value</param>
 public void AddVariable(string key, Accumulate.Accu obj)
 {
     if (this.variables.ContainsKey(key))
     {
         this.variables[key] = obj;
     }
     else
     {
         this.variables.Add(key, obj);
     }
 }
Exemple #4
0
 /// <summary>
 /// Add a type
 /// </summary>
 /// <param name="key">key name</param>
 /// <param name="obj">object value</param>
 public void AddType(string key, Accumulate.Accu obj)
 {
     if (this.types.ContainsKey(key))
     {
         this.types[key] = obj.Clone() as Accumulate.Accu;
     }
     else
     {
         this.types.Add(key, obj.Clone() as Accumulate.Accu);
     }
 }
Exemple #5
0
 /// <summary>
 /// Edit a variable
 /// </summary>
 /// <param name="key">key name</param>
 /// <param name="obj">object value</param>
 public void EditVariable(string key, Accumulate.Accu obj)
 {
     if (this.variables.ContainsKey(key))
     {
         this.variables[key] = obj.Clone() as Accumulate.Accu;
     }
     else
     {
         this.variables.Add(key, obj.Clone() as Accumulate.Accu);
     }
 }
Exemple #6
0
 /// <summary>
 /// Create an instance from an accu type name
 /// </summary>
 /// <param name="varName">name of variable</param>
 /// <param name="typeName">type of accu</param>
 /// <returns>accu</returns>
 public Accumulate.Accu CreateInstanceFromType(string varName, string typeName)
 {
     if (this.types.ContainsKey(typeName))
     {
         Accumulate.Accu a = this.types[typeName].Clone() as Accumulate.Accu;
         a.TypeName        = varName;
         a.ValueOrFileName = typeName;
         return(a);
     }
     else
     {
         throw new KeyNotFoundException(String.Format("{0} is not a type", typeName));
     }
 }
Exemple #7
0
 /// <summary>
 /// Add a variable
 /// </summary>
 /// <param name="key">key name</param>
 /// <param name="val">string value</param>
 public void AddVariable(string key, string val)
 {
     if (this.variables.ContainsKey(key))
     {
         Accumulate.Accu      a     = this.variables[key];
         Accumulate.AccuChild child = a.Values.Last(x => x.Name == "value") as Accumulate.AccuChild;
         child.Value = val;
     }
     else
     {
         Accumulate.Accu a = new Accumulate.Accu(key, Path.Combine("Luigi", "value.prt"));
         a.TypeName = key;
         Accumulate.AccuChild child = a.Values.Last(x => x.Name == "value") as Accumulate.AccuChild;
         child.Value = val;
         this.variables.Add(key, a);
     }
 }