/// <summary> /// Initializes a new instance of the <see cref="TemplateContainer"/> class. /// </summary> /// <param name="parent">The parent.</param> public TemplateContainer(TemplateContainer parent) { this.Parent = parent; this.Attributes = new Dictionary<string, object>(); this.ArrayValues = new List<TemplateContainer>(); this.ArrayValuesMap = new Dictionary<string, TemplateContainer>(); }
/// <summary> /// Initializes a new instance of the <see cref="TemplateContainer"/> class. /// </summary> /// <param name="parent">The parent.</param> public TemplateContainer(TemplateContainer parent) { this.Parent = parent; this.Attributes = new Dictionary <string, object>(); this.ArrayValues = new List <TemplateContainer>(); this.ArrayValuesMap = new Dictionary <string, TemplateContainer>(); }
private void BuildDomains(TemplateContainer node) { foreach (MetaDomain domain in model.Domains) { TemplateContainer arrnode = node.AddArrayValue(domain.Id.ToString()); arrnode.AddFromObject(domain); } }
public TemplateContainer Convert(MetaModel metamodel) { this.model = metamodel; TemplateContainer root = new TemplateContainer(); root.AddAttribute("Test", "OK"); this.BuildDomains(root.AddChild("Domains")); this.BuildColumns(root.AddChild("Columns")); this.BuildTables(root.AddChild("Tables")); return root; }
/// <summary> /// Gets the key from array value. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private string GetKeyFromArrayValue(TemplateContainer item) { foreach (KeyValuePair <string, TemplateContainer> kvp in this.ArrayValuesMap) { if (kvp.Value == item) { return(kvp.Key); } } return(null); }
private void button2_Click(object sender, EventArgs e) { TemplateContainer container = new TemplateContainer(); container.AddAttribute("varprueba", "prueba"); container.AddAttribute("vartrans", "transformación"); container.AddAttribute("i", 7); string s = "El resultado es [%if(i > 7)%]cierto[%else%]falso"; s = TemplateTransformer.Transform(s); s = JavascriptEvaluator.ReplaceString(s, container); this.richTextBox2.Text = s; }
/// <summary> /// Removes the array value. /// </summary> /// <param name="index">The index.</param> public void RemoveArrayValue(int index) { TemplateContainer item = this.ArrayValues[index]; this.ArrayValues.RemoveAt(index); string key = this.GetKeyFromArrayValue(item); if (!string.IsNullOrEmpty(key)) { this.ArrayValuesMap.Remove(key); } }
public static string Test(string s, string expected, TemplateContainer container) { string result = JavascriptEvaluator.RunScript(s, container).ToString(); if (result.Equals(expected)) { return string.Format("OK '{0}' = {1}\n", s, result); } else { return string.Format("Error executing '{0}'. Expected {1} but obtained {2}\n", s, expected, result); } }
private void BuildTables(TemplateContainer node) { foreach (MetaTable table in model.Tables) { TemplateContainer arrnode = node.AddArrayValue(table.Id.ToString()); arrnode.AddFromObject(table); TemplateLink listLink = arrnode.AddListLink("Columns", "/Columns"); foreach (MetaColumn column in table.Columns) { listLink.AddListValue(table.Id.ToString() + "!" + column.Ix.ToString()); } } }
public void BuildColumns(TemplateContainer node) { foreach (MetaTable table in model.Tables) { foreach (MetaColumn column in table.Columns) { TemplateContainer arrnode = node.AddArrayValue(table.Id.ToString() + "!" + column.Ix.ToString()); arrnode.AddFromObject(column); arrnode.AddLink("Table", "Tables[" + column.TableId.ToString() + "]"); MetaColumn currentcolumn = column; while (currentcolumn.TargetColumn != null) { currentcolumn = currentcolumn.TargetColumn; } node.AddLink("Domain", "/Domains[" + currentcolumn.Domain.Id.ToString() + "]"); } } }
/// <summary> /// Adds the array value. /// </summary> /// <param name="key">The key.</param> /// <param name="item">The item.</param> /// <returns></returns> public TemplateContainer AddArrayValue(string key, TemplateContainer item) { this.ArrayValuesMap.Add(key, item); this.ArrayValues.Add(item); return item; }
/// <summary> /// Adds the array value. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public TemplateContainer AddArrayValue(TemplateContainer item) { return this.AddArrayValue(this.ArrayValues.Count.ToString(), item); }
/// <summary> /// Initializes a new instance of the <see cref="TemplateLink"/> class. /// </summary> /// <param name="parent">The parent.</param> /// <param name="link">The link.</param> public TemplateLink(TemplateContainer parent, string link) { this.Parent = parent; this.Link = link; this.ListValues = null; }
public TemplateContainer AddChild(string name, TemplateContainer container) { this.AddAttribute(name, container); return container; }
/// <summary> /// Adds the array value. /// </summary> /// <param name="key">The key.</param> /// <param name="item">The item.</param> /// <returns></returns> public TemplateContainer AddArrayValue(string key, TemplateContainer item) { this.ArrayValuesMap.Add(key, item); this.ArrayValues.Add(item); return(item); }
/// <summary> /// Adds the array value. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public TemplateContainer AddArrayValue(TemplateContainer item) { return(this.AddArrayValue(this.ArrayValues.Count.ToString(), item)); }
public TemplateContainer AddChild(string name, TemplateContainer container) { this.AddAttribute(name, container); return(container); }
/// <summary> /// Gets the key from array value. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private string GetKeyFromArrayValue(TemplateContainer item) { foreach (KeyValuePair<string, TemplateContainer> kvp in this.ArrayValuesMap) { if (kvp.Value == item) { return kvp.Key; } } return null; }