/// <summary> /// Attempts to convert the value specified into a useable value on the front-end /// </summary> /// <param name="value"></param> /// <returns></returns> public Attempt<object> ConvertPropertyValue(object value) { if (value != null && value.ToString().Length > 0) { var data = value.ToString(); // check if the data is XML if (XmlHelper.CouldItBeXml(data)) { // TODO [LK->HR] Discuss with Hendy whether to return a collection of AutoCompleteItem(s)? // ... or a collection of Content-specific objects; e.g. List<Media>, List<Member>, List<INodeFactory>? // parse the XML var xdoc = XDocument.Parse(data); if (xdoc != null) { // select the Item nodes var nodes = xdoc.XPathSelectElements("//Item"); if (nodes != null && nodes.Count() > 0) { // iterate over the nodes; building collection of AutoCompleteItem(s) var items = new List<AutoCompleteItem>(); foreach (var node in nodes) { // check if the node has any attributes if (!node.HasAttributes) continue; var item = new AutoCompleteItem(); // loop through the attributes, setting the properties accordingly foreach (var attribute in node.Attributes()) { switch (attribute.Name.LocalName) { case "Text": item.Text = attribute.Value; break; case "Value": item.Value = attribute.Value; break; default: break; } } items.Add(item); } return new Attempt<object>(true, items); } } } } return Attempt<object>.False; }
/// <summary> /// Inits the specified current node id. /// </summary> /// <param name="CurrentNodeId">The current node id.</param> /// <param name="PropertyData">The property data.</param> /// <param name="instance">The instance.</param> /// <returns></returns> public bool Init(int CurrentNodeId, string PropertyData, out object instance) { // check if the data is XML if (Helper.Xml.CouldItBeXml(PropertyData)) { // if model binding is disbaled, return a DynamicXml object if (!Settings.RazorModelBindingEnabled) { #pragma warning disable 0618 instance = new DynamicXml(PropertyData); #pragma warning restore 0618 return true; } // TODO [LK->HR] Discuss with Hendy whether to return a collection of AutoCompleteItem(s)? // ... or a collection of Content-specific objects; e.g. List<Media>, List<Member>, List<INodeFactory>? // parse the XML var xdoc = XDocument.Parse(PropertyData); if (xdoc != null) { // select the Item nodes var nodes = xdoc.XPathSelectElements("//Item"); if (nodes != null && nodes.Count() > 0) { // iterate over the nodes; building collection of AutoCompleteItem(s) var items = new List<AutoCompleteItem>(); foreach (var node in nodes) { // check if the node has any attributes if (!node.HasAttributes) continue; var item = new AutoCompleteItem(); // loop through the attributes, setting the properties accordingly foreach (var attribute in node.Attributes()) { switch (attribute.Name.LocalName) { case "Text": item.Text = attribute.Value; break; case "Value": item.Value = attribute.Value; break; default: break; } } items.Add(item); } instance = items; return true; } } } // all else fails, return default value instance = PropertyData; return true; }