/// <summary> /// Parses OrderCustomPropertiesInfo. /// </summary> public static OrderCustomPropertiesInfo ParseOrderCustomPropertiesInfo(string xml) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); OrderCustomPropertiesInfo info = null; XmlNode root = xmlDoc.SelectSingleNode(NODE_ORDERCUSTOMPROP); if (root != null) { info = new OrderCustomPropertiesInfo(); foreach (XmlNode node in root.ChildNodes) { if (node.NodeType != XmlNodeType.Element) { continue; // skip comments and other non element nodes } if (node.Name.Equals(NODE_PROPERTY, StringComparison.OrdinalIgnoreCase)) { XmlAttributeCollection attributes = node.Attributes; string name = attributes[ATTR_NAME].Value; string description = null; if (null != attributes[ATTR_DESCRIPTION]) { description = attributes[ATTR_DESCRIPTION].Value; } int length = int.Parse(attributes[ATTR_MAXLENGTH].Value); OrderCustomPropertyType type = OrderCustomPropertyType.Text; // NOTE: for default used text XmlAttribute typeAttribute = attributes[ATTR_TYPE]; if (null != typeAttribute) { type = (OrderCustomPropertyType)Enum.Parse(typeof(OrderCustomPropertyType), typeAttribute.Value); } bool orderPairKey = false; // default XmlAttribute orderPairKeyAttribute = attributes[ATTR_ORDERPAIRKEY]; if (null != orderPairKeyAttribute) { orderPairKey = bool.Parse(orderPairKeyAttribute.Value); } info.Add(new OrderCustomProperty(name, type, length, description, orderPairKey)); } else { throw new FormatException(); } } } else { throw new FormatException(); } return(info); }
/// <summary> /// Converts collection of CustomOrderProperty objects to OrderCustomPropertiesInfo. /// </summary> /// <returns>OrderCustomPropertiesInfo object.</returns> public OrderCustomPropertiesInfo GetOrderCustomPropertiesInfo() { OrderCustomPropertiesInfo orderCustomPropertiesInfo = new OrderCustomPropertiesInfo(); foreach (CustomOrderProperty customOrderProperty in _customOrderProperties) { // Create custom order property info using data of item in collection. OrderCustomProperty newOrderCustomProperty = new OrderCustomProperty(customOrderProperty.Name, OrderCustomPropertyType.Text, customOrderProperty.MaximumLength, customOrderProperty.Description, customOrderProperty.OrderPairKey); // Add new custom order property to collection. orderCustomPropertiesInfo.Add(newOrderCustomProperty); } return(orderCustomPropertiesInfo); }
/// <summary> /// Parses OrderCustomPropertiesInfo. /// </summary> public static OrderCustomPropertiesInfo ParseOrderCustomPropertiesInfo(string xml) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); OrderCustomPropertiesInfo info = null; XmlNode root = xmlDoc.SelectSingleNode(NODE_ORDERCUSTOMPROP); if (root != null) { info = new OrderCustomPropertiesInfo(); foreach (XmlNode node in root.ChildNodes) { if (node.NodeType != XmlNodeType.Element) continue; // skip comments and other non element nodes if (node.Name.Equals(NODE_PROPERTY, StringComparison.OrdinalIgnoreCase)) { XmlAttributeCollection attributes = node.Attributes; string name = attributes[ATTR_NAME].Value; string description = null; if (null != attributes[ATTR_DESCRIPTION]) description = attributes[ATTR_DESCRIPTION].Value; int length = int.Parse(attributes[ATTR_MAXLENGTH].Value); OrderCustomPropertyType type = OrderCustomPropertyType.Text; // NOTE: for default used text XmlAttribute typeAttribute = attributes[ATTR_TYPE]; if (null != typeAttribute) type = (OrderCustomPropertyType)Enum.Parse(typeof(OrderCustomPropertyType), typeAttribute.Value); bool orderPairKey = false; // default XmlAttribute orderPairKeyAttribute = attributes[ATTR_ORDERPAIRKEY]; if (null != orderPairKeyAttribute) orderPairKey = bool.Parse(orderPairKeyAttribute.Value); info.Add(new OrderCustomProperty(name, type, length, description, orderPairKey)); } else throw new FormatException(); } } else throw new FormatException(); return info; }
/// <summary> /// Converts collection of CustomOrderProperty objects to OrderCustomPropertiesInfo. /// </summary> /// <returns>OrderCustomPropertiesInfo object.</returns> public OrderCustomPropertiesInfo GetOrderCustomPropertiesInfo() { OrderCustomPropertiesInfo orderCustomPropertiesInfo = new OrderCustomPropertiesInfo(); foreach (CustomOrderProperty customOrderProperty in _customOrderProperties) { // Create custom order property info using data of item in collection. OrderCustomProperty newOrderCustomProperty = new OrderCustomProperty(customOrderProperty.Name, OrderCustomPropertyType.Text, customOrderProperty.MaximumLength, customOrderProperty.Description, customOrderProperty.OrderPairKey); // Add new custom order property to collection. orderCustomPropertiesInfo.Add(newOrderCustomProperty); } return orderCustomPropertiesInfo; }