/// <summary> /// Return a serialized string of values for the pre value editor model /// </summary> /// <returns></returns> public override string GetSerializedValue() { var xml = new XElement("preValues", new XElement("preValue", new XAttribute("name", "ShowLabel"), new XCData(ShowLabel.ToString())), new XElement("preValue", new XAttribute("name", "ShowContextMenu"), new XCData(ShowContextMenu.ToString())), new XElement("preValue", new XAttribute("name", "Size"), new XCData(Size.Width + "x" + Size.Height)), new XElement("preValue", new XAttribute("name", "Features"), new XCData( string.Join(",", Features .Where(x => x.Selected) .Select(x => x.Value).ToArray()))), new XElement("preValue", new XAttribute("name", "Stylesheets"), new XCData( string.Join(",", Stylesheets .Where(x => x.Selected) .Select(x => x.Value).ToArray()))), new XElement("preValue", new XAttribute("name", "IsRequired"), new XCData(IsRequired.ToString()))); if (!ValidElements.IsNullOrWhiteSpace()) { xml.Add(new XElement("preValue", new XAttribute("name", "validElements"), new XCData(ValidElements.Trim()))); } return(xml.ToString()); }
/// <summary> /// set the pre values from the serialized values in the repository /// </summary> /// <param name="serializedVal"></param> public override void SetModelValues(string serializedVal) { if (_appContext == null) { return; // Need an app context to set model values } Stylesheets = GetStylesheets(); Features = GetFeatures(); Size = new Size(650, 400); if (!string.IsNullOrEmpty(serializedVal)) { var xml = XElement.Parse(serializedVal); ShowLabel = xml.Elements("preValue").Any(x => (string)x.Attribute("name") == "ShowLabel" && x.Value == bool.TrueString); ShowContextMenu = xml.Elements("preValue").Any(x => (string)x.Attribute("name") == "ShowContextMenu" && x.Value == bool.TrueString); ValidElements = (string)xml.Elements("preValue").Where(x => (string)x.Attribute("name") == "validElements").SingleOrDefault(); CustomPlugins = (string)xml.Elements("preValue").Where(x => (string)x.Attribute("name") == "customPlugins").SingleOrDefault(); var featuresEl = xml.Elements("preValue").Where(x => (string)x.Attribute("name") == "Features").SingleOrDefault(); if (featuresEl != null) { var features = featuresEl.Value.ToUpper().Split(','); foreach (var e in Features.Where(x => features.Contains(x.Value.ToUpper()))) { e.Selected = true; } } var stylesheetsEl = xml.Elements("preValue").Where(x => (string)x.Attribute("name") == "Stylesheets").SingleOrDefault(); if (stylesheetsEl != null) { var stylesheets = stylesheetsEl.Value.ToUpper().Split(','); foreach (var e in Stylesheets.Where(x => stylesheets.Contains(x.Value.ToUpper()))) { e.Selected = true; } } var sizeEl = xml.Elements("preValue").Where(x => (string)x.Attribute("name") == "Size").SingleOrDefault(); if (sizeEl != null) { var size = sizeEl.Value.Split('x'); var width = Size.Width; var height = Size.Height; if (int.TryParse(size[0], out width) && int.TryParse(size[1], out height)) { Size = new Size(width, height); } } IsRequired = xml.Elements("preValue").Any(x => (string)x.Attribute("name") == "IsRequired" && x.Value == bool.TrueString); } }