}//_ValidateAdd protected void _ValidateAdd( XmlDocument doc, string sParentXPath, string componentType, Component.eComponentType eComponentType, string name) { try { lastValidateAddComponentType = componentType; //creating child xml element String baseType = this._GetBaseComponentType(componentType); lastValidateAddBaseType = baseType; if (baseType != null) // replace with base for validation { componentType = baseType; } XmlElement childXml = doc.CreateElement(componentType); //creating attributes XmlAttribute attributeType = doc.CreateAttribute(XmlSchemaConstants.Config.eType); attributeType.Value = eComponentType.ToString(); XmlAttribute attributeName = doc.CreateAttribute(XmlSchemaConstants.Config.Name); attributeName.Value = name; //adding attributes childXml.SetAttributeNode(attributeType); childXml.SetAttributeNode(attributeName); // use 'base' of component type to find in validated document lastValidateAddComponentXPath = lastValidateAddComponentXPath + "/" + componentType; // cache will use this doc = AddChildAtXPath(doc, sParentXPath, childXml, true); this._Validate(doc, componentType); //Validating the XmlDocument } catch (Exception) { throw; } }//_ValidateAdd
}//_VerifyBeforeValidateAdd_GetParentXPath private void _ValidateAdd( int topID, int parentID, string componentType, Component.eComponentType eComponentType, string name, string linkType) { string sParentXPath = this._VerifyBeforeValidateAdd_GetParentXPath(topID, parentID); XmlDocument doc = this._GetXmlDoc_Validation(topID, linkType); this._ValidateAdd(doc, sParentXPath, componentType, eComponentType, name); }//_ValidateAdd
// Process parameters the same way for link and component // Node looks like '/Parameters' private XmlDocument ProcessParameters(XmlNode parameters, int componentOrLinkID, Component.eComponentType eType, eParamParentType paramParType, Dictionary<String, List<DataRow>> parameterTableCache) { bool IDisClass = eType == Component.eComponentType.Class; bool IDisSubclass = eType == Component.eComponentType.Subclass; // prepare values from DB Dictionary<String, String> parameterNameValues = new Dictionary<String, String>(); Dictionary<String, List<NameValuePair>> parameterArrayNameValues = new Dictionary<String, List<NameValuePair>>(); if (parameterTableCache != null) { String key = componentOrLinkID+paramParType.ToString(); if (parameterTableCache.ContainsKey(key)) { List<DataRow> parameterRows = parameterTableCache[key]; parameterNameValues = new Dictionary<String, String>(); foreach (DataRow parameterRow in parameterRows) { ProcessParameterDataRow(parameterRow, ref parameterNameValues, ref parameterArrayNameValues); } } else { parameterNameValues = new Dictionary<String, String>(); } } else { DataTable parameterTable = this.m_model.GetParameterTable(componentOrLinkID, paramParType.ToString()); foreach (DataRow parameterRow in parameterTable.Rows) { ProcessParameterDataRow(parameterRow, ref parameterNameValues, ref parameterArrayNameValues); } } // prepare XML document for view XmlDocument toView = new XmlDocument(); XmlElement parametersNodeForView = null; if (paramParType == eParamParentType.Component) { parametersNodeForView = toView.CreateElement(XmlSchemaConstants.Display.sComponentParameters); // ComponentParameters } else if (paramParType == eParamParentType.Link) { parametersNodeForView = toView.CreateElement(XmlSchemaConstants.Display.sLinkParameters); // LinkParameters } XmlNode parametersRoot = toView.AppendChild(parametersNodeForView); if (parameters != null) { // create Parameters with type 'Complex', these will hold all the parameters for a category. List<String> categories = new List<String>(); XmlNodeList allCategories = parameters.SelectNodes(XmlSchemaConstants.Display.sParameter); foreach (XmlNode categoryNode in allCategories) // collect all categories { String category = categoryNode.Attributes[ConfigFileConstants.category].Value; if (!categories.Contains(category)) { categories.Add(category); } } foreach (String category in categories) // go through categories, build parent node, collect children { XmlElement newComplex = toView.CreateElement("Parameter"); XmlAttribute categoryAttributeForNewComplex = toView.CreateAttribute(ConfigFileConstants.category); categoryAttributeForNewComplex.Value = category; XmlAttribute typeAttributeForNewComplex = toView.CreateAttribute(ConfigFileConstants.Type); typeAttributeForNewComplex.Value = ConfigFileConstants.complexType; // type="Complex" newComplex.SetAttributeNode(categoryAttributeForNewComplex); newComplex.SetAttributeNode(typeAttributeForNewComplex); XmlNodeList complexChildren = parameters.SelectNodes("Parameter[@category='" + category + "']"); // go through children... foreach (XmlNode complexChild in complexChildren) { String name = complexChild.Attributes[ConfigFileConstants.displayedName].Value; String combined = category + SchemaConstants.ParameterDelimiter + name; // category.name XmlNode copy = complexChild.CloneNode(true); // check browsable attribute XmlAttribute browseAttr = copy.Attributes[ConfigFileConstants.browsable]; if (browseAttr == null) { browseAttr = copy.OwnerDocument.CreateAttribute(ConfigFileConstants.browsable); browseAttr.Value = "true"; copy.Attributes.Append(browseAttr); } // check classOnly - // if parameter is specified as class only: // For a class, set browsable to true, otherwise false. // otherwise, use browse attribute value XmlAttribute classAttr = copy.Attributes[ConfigFileConstants.classOnly]; if (classAttr != null) { String classAttrValue = classAttr.Value; if (classAttrValue.Equals("true")) { if (IDisClass) { browseAttr.Value = "true"; } else if (IDisSubclass && combined != Component.Class.InstancesUseClassName.Name) // don't show InstancesUseClassName name for subclasses { browseAttr.Value = "true"; } else { browseAttr.Value = "false"; } } } copy = ProcessChildParameterValue(copy, combined, parameterNameValues, parameterArrayNameValues); // check for struct children XmlNodeList structChildren = copy.SelectNodes("Parameters/Parameter"); for (int i = 0; i < structChildren.Count; i++) { XmlNode structChild = structChildren[i]; String fieldName = structChild.Attributes[ConfigFileConstants.Name].Value; String structName = combined + SchemaConstants.FieldLeftDelimeter + fieldName + SchemaConstants.FieldRightDelimeter; structChild = ProcessChildParameterValue(structChild, structName, parameterNameValues, parameterArrayNameValues); } newComplex.AppendChild(toView.ImportNode(copy, true)); } // parameter loop // sanity check: if complex has no children, don't add it (they might have all been empty IgnoreEmptyString is true) if (newComplex.HasChildNodes) { parametersRoot.AppendChild(newComplex); // append complex node to root } } // complex loop } return toView; }
}//_GetXmlTree public XmlElement CommonElementCreate(XmlDocument doc, int id, int? linkID, String baseType, String type, String name, String desc, Component.eComponentType eType) { int? iClassID = null; int? iSubClassID = null; DataRow drClass = null; DataRow drSubClass = null; //creating element XmlElement xmlElement = doc.CreateElement(XmlSchemaConstants.Display.sComponent); //creating attributes XmlAttribute attrCompType = doc.CreateAttribute(XmlSchemaConstants.Display.Component.Type); attrCompType.Value = type; XmlAttribute attrCompID = doc.CreateAttribute(XmlSchemaConstants.Display.Component.Id); attrCompID.Value = id.ToString(); XmlAttribute attrCompName = doc.CreateAttribute(XmlSchemaConstants.Display.Component.Name); attrCompName.Value = name; XmlAttribute attrCompDesc = doc.CreateAttribute(XmlSchemaConstants.Display.Component.Description); attrCompDesc.Value = desc; XmlAttribute attCompEtype = doc.CreateAttribute(XmlSchemaConstants.Display.Component.eType); attCompEtype.Value = eType.ToString(); //adding attributes xmlElement.SetAttributeNode(attrCompType); xmlElement.SetAttributeNode(attrCompID); xmlElement.SetAttributeNode(attrCompName); xmlElement.SetAttributeNode(attrCompDesc); xmlElement.SetAttributeNode(attCompEtype); //Base Component Type attribute if (baseType != null) { XmlAttribute attrBaseCompType = doc.CreateAttribute(XmlSchemaConstants.Display.Component.BaseType); attrBaseCompType.Value = baseType; xmlElement.SetAttributeNode(attrBaseCompType); }//Base Component Type attribute //LinkID attribute if (linkID.HasValue) { XmlAttribute attrLinkID = doc.CreateAttribute(XmlSchemaConstants.Display.Component.LinkID); attrLinkID.Value = linkID.Value.ToString(); xmlElement.SetAttributeNode(attrLinkID); } //class & subclass components and their ids this._GetClassSubclass(id, eType, out drClass, out drSubClass); if (drClass != null) { iClassID = (int)drClass[SchemaConstants.Id]; } if (drSubClass != null) { iSubClassID = (int)drSubClass[SchemaConstants.Id]; } //if (compOptions.InstanceUseClassName) //{ // // check use class name controller variable // //ComponentIDName classIDName = this.CheckUseClassName(iCompID, eCompEtype); // if (drClass != null) // { // string key = drClass[SchemaConstants.Id].ToString(); // string valueCheck = GetCacheValue(key, Component.Class.InstancesUseClassName.Name, eParamParentType.Component); // if (valueCheck != null) // { // if (valueCheck.Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase)) // { // xmlElement.Attributes[XmlSchemaConstants.Display.Component.Name].Value = drClass[SchemaConstants.Name].ToString(); // } // } // else // { // ComponentIDName classIDName = this.CheckUseClassName(drClass); // if (classIDName != null) // { // xmlElement.Attributes[XmlSchemaConstants.Display.Component.Name].Value = classIDName.Name; // } // } // } //}//if user is asking to use class name for instances if (iClassID.HasValue) { XmlAttribute attrClassID = doc.CreateAttribute(XmlSchemaConstants.Display.Component.ClassID); attrClassID.Value = iClassID.Value.ToString(); xmlElement.SetAttributeNode(attrClassID); }//if classInstanceInfo if (iSubClassID.HasValue) { XmlAttribute attrSubclassID = doc.CreateAttribute(XmlSchemaConstants.Display.Component.SubclassID); attrSubclassID.Value = iSubClassID.Value.ToString(); xmlElement.SetAttributeNode(attrSubclassID); }//SubclassInstanceInfo return xmlElement; }
private IXPathNavigable _GetParametersForComponent(int componentID, String componentType, Component.eComponentType eType, Dictionary<String, XmlNode> typeToParameterXMLCache, Dictionary<String, List<DataRow>> parameterTableCache) { String key = "" + componentID; if (componentParametersXMLCache[m_model].ContainsKey(key)) { return componentParametersXMLCache[m_model][key]; } XmlNode complex = null; if (typeToParameterXMLCache != null && typeToParameterXMLCache.ContainsKey(componentType)) { complex = typeToParameterXMLCache[componentType]; } else { complex = this.m_model.GetParametersXML(componentType); if (typeToParameterXMLCache != null) { typeToParameterXMLCache.Add(componentType, complex); } } XmlDocument returnDocument = ProcessParameters(complex, componentID, eType, eParamParentType.Component, parameterTableCache); XmlDocumentFragment fragment = returnDocument.CreateDocumentFragment(); fragment.InnerXml = returnDocument.InnerXml; componentParametersXMLCache[m_model].Add(key, fragment); return returnDocument; }