public virtual void Write(ICodeFragment fragment, IOutputCache output) { AttributeTemplate template = (AttributeTemplate)fragment; output.Add("[") .Add(template.Name); if (template.HasValue || template.Properties.Count > 0) { output.Add("("); if (template.HasValue) { output.Add(template.Code); } if (template.Properties.Count > 0) { foreach (KeyValuePair <string, object> pair in template.Properties) { output.Add($"{pair.Key} = {this.Language.ConvertValue(pair.Value)}"); } } output.Add(")"); } output.Add("]"); if (template.IsInline) { output.Add(" "); } else { output.BreakLine(); } }
void LoadAttributeTemplates() { ddlAttTemplates.DataSource = AttributeTemplate.FetchAll(); ddlAttTemplates.DataTextField = "attributeName"; ddlAttTemplates.DataValueField = "templateID"; ddlAttTemplates.DataBind(); }
protected void btnSaveAttTemplate_Click(object sender, EventArgs e) { Commerce.Common.Attribute att = new Commerce.Common.Attribute(); Attributes atts = new Attributes(); AttributeTemplate attributeTemplate = new AttributeTemplate(); attributeTemplate.AttributeName = txtAttributeNew.Text.Trim(); attributeTemplate.AttributeTypeID = int.Parse(ddlAttNewSelectionType.SelectedValue); ArrayList aList = GetSelections(); if (aList != null) { if (aList.Count > 0) { att.Selections = new System.Collections.Generic.List <AttributeSelection>(); for (int i = 0; i < aList.Count; i++) { att.Selections.Add((AttributeSelection)aList[i]); } } } atts.Add(att); attributeTemplate.SelectionList = Utility.ObjectToXML(typeof(Attributes), atts); attributeTemplate.Description = txtAttNewDesc.Text.Trim(); attributeTemplate.Save(Page.User.Identity.Name); lblTemplateSaved.Text = " Template Saved"; LoadAttributeTemplates(); }
public static T WithAttribute <T>(this T attributeableTempalte, string name) where T : AttributeableTempalte { AttributeTemplate attribute = new AttributeTemplate(name); attributeableTempalte.Attributes.Add(attribute); return(attributeableTempalte); }
public override void Write(ICodeFragment fragment, IOutputCache output) { AssemblyName assemblyName = (Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly()).GetName(); ClassTemplate template = (ClassTemplate)fragment; AttributeTemplate attributeTemplate = template.AddAttribute("GeneratedCode", Code.Instance.String(assemblyName.Name), Code.Instance.String(assemblyName.Version.ToString())); base.Write(fragment, output); template.Attributes.Remove(attributeTemplate); }
public void AttributeWithProperty() { AttributeTemplate template = new AttributeTemplate("test"); template.Properties.Add("key", Code.String("value")); AttributeWriter writer = new AttributeWriter(); writer.Write(template, this.output); Assert.AreEqual("[test(key = \"value\")]", this.output.ToString()); }
private int SelectOptionFromOptionSet(AttributeTemplate attributeTemplate) { var optionSetMetadata = ( EnumAttributeMetadata )attributeTemplate.AttMetadata; var optionList = (from o in optionSetMetadata.OptionSet.Options select new { o.Value, Text = o.Label.UserLocalizedLabel.Label }).ToList( ); var randomNumber = new Random( ); return(Convert.ToInt32(optionList[randomNumber.Next(0, optionList.Count - 1)].Value)); }
public static T GetValue <T>(this AttributeTemplate attributeTemplate, string fieldName) { if (attributeTemplate == null) { return(default(T)); } var field = attributeTemplate.Fields.SingleOrDefault(e => e.Name.Equals(fieldName, StringComparison.OrdinalIgnoreCase)); if (field == null) { return(default(T)); } return((T)Convert.ChangeType(field.Value, typeof(T))); }
private object CastStringToObject(AttributeTemplate attributeTemplate, string value) { switch (attributeTemplate.AttMetadata.AttributeType.ToString( )) { // TODO add decimal case "BigInt": return(Convert.ToInt64(value)); case "Boolean": return(Convert.ToBoolean(value)); case "DateTime": return(Convert.ToDateTime(value)); case "Integer": return(Convert.ToInt32(value)); case "Memo": return(value); case "Picklist": return(new OptionSetValue(SelectOptionFromOptionSet(attributeTemplate))); case "String": return(value); case "Money": return(new Money(Convert.ToDecimal(value))); case "Decimal": return(Convert.ToDecimal(value)); case "Double": return(Convert.ToDouble(value)); case "Customer": case "Lookup": case "State": case "Status": break; } throw new Exception("Object type unusable " + attributeTemplate.Name + " " + attributeTemplate.AttMetadata.AttributeType); }
protected void btnSetTemplate_Click(object sender, EventArgs e) { string sTemplate = ddlAttTemplates.SelectedValue; AttributeTemplate template = new AttributeTemplate(int.Parse(sTemplate)); txtAttributeNew.Text = template.AttributeName; txtAttNewDesc.Text = template.Description; ddlAttNewSelectionType.SelectedValue = template.AttributeTypeID.ToString(); Commerce.Common.Attributes attributes = (Attributes)Utility.XmlToObject(typeof(Attributes), template.SelectionList); ArrayList aList = new ArrayList(); foreach (AttributeSelection selection in attributes[0].Selections) { aList.Add(selection); } BindSells(aList); ViewState["aList"] = aList; }
public virtual void Write(ICodeFragment fragment, IOutputCache output) { AttributeTemplate template = (AttributeTemplate)fragment; output.Add("@") .Add(template.Name); //if (template.HasValue || template.Properties.Count > 0) { output.Add("("); if (template.HasValue) { output.Add(template.Code, ", "); } if (template.Properties.Count > 0) { foreach (KeyValuePair <string, ICodeFragment> pair in template.Properties) { output.Add($"{pair.Key} = ").Add(pair.Value); } } output.Add(")") .BreakLine(); } }
public static Dictionary <string, string> ToDictionary(this AttributeTemplate template) { return(template.Fields.ToDictionary(e => e.Name, e => e.Value)); }