private ParameterInfo GetParameterInfo(XmlNode parameter, String category, String name, String field, Type cSharpType, ParamConstraint paramConstraint, eParamParentType parent) { XmlAttribute valueAttr, descriptionAttr; String valueAttrValue, descriptionAttrValue = "", combined; String paramMin = null; String paramMax = null; descriptionAttr = parameter.Attributes[ConfigFileConstants.description]; if (descriptionAttr != null) // optional { descriptionAttrValue = descriptionAttr.Value; } combined = category + SchemaConstants.ParameterDelimiter + name; if (field.Length > 0) { combined = combined + SchemaConstants.FieldLeftDelimeter + field + SchemaConstants.FieldRightDelimeter; } paramMin = null; paramMax = null; if (paramConstraint != null) { paramMin = paramConstraint.Range.Min; paramMax = paramConstraint.Range.Max; } valueAttr = parameter.Attributes[ConfigFileConstants.Value]; if (valueAttr != null) { valueAttrValue = valueAttr.Value; object oValidatedValue = this._ValidateValue(cSharpType, valueAttrValue, paramMin, paramMax); if (oValidatedValue is Array) { // array - can't bulk insert, serialize BinaryFormatter formatter = new BinaryFormatter(); MemoryStream memoryStream = new MemoryStream(); formatter.Serialize(memoryStream, oValidatedValue); byte[] arrayData = memoryStream.ToArray(); return new ParameterInfo(category, name, field, combined, parent, "", descriptionAttrValue, paramMin, paramMax, arrayData); } else { string sParamValToStore = (oValidatedValue == null) ? valueAttrValue : oValidatedValue.ToString(); return new ParameterInfo(category, name, field, combined, parent, sParamValToStore, descriptionAttrValue, paramMin, paramMax); } } else { return new ParameterInfo(category, name, field, combined, parent, "", descriptionAttrValue, paramMin, paramMax); } }
// Get a constraint for a component or link public ParamConstraint GetConstraint(String category, String name, String childField, eParamParentType componentOrLink, String componentType, String linkType, String fromType, String toType) { XPathNavigator targetParameter = null; // get the parameter node if (componentOrLink == eParamParentType.Component) // (XML is in different places in config file) { targetParameter = this.m_model.GetParameter(componentType, category, name, childField); } else if (componentOrLink == eParamParentType.Link) { targetParameter = this.m_model.GetParameter(linkType, fromType, toType, category, name, childField); } if (targetParameter != null) // populate constraints object if any are provided for parameter { XPathNodeIterator constraints = targetParameter.Select("Constraints/Constraint"); if (constraints.Count > 0) { ParamConstraint paramConstraint = new ParamConstraint(); foreach (XPathNavigator constraint in constraints) { string sConstraintName = constraint.GetAttribute(ConfigFileConstants.constraintName, constraint.NamespaceURI); string sConstraintValue = constraint.GetAttribute(ConfigFileConstants.constraintValue, constraint.NamespaceURI); switch (sConstraintName.ToLower()) { case ConfigFileConstants.minConstraint: // "min" paramConstraint.Range.Min = sConstraintValue; break; case ConfigFileConstants.maxConstraint: // "max" paramConstraint.Range.Max = sConstraintValue; break; } } return paramConstraint; } } return null; }