}//_GetSchemaPath #region Read Values From Schema protected SchemaDefaults _GetDefaultValuesFromSchema(XmlDocument validationDoc) { SchemaDefaults schemaValues = new SchemaDefaults(); try { if (validationDoc != null) { string sSchemaPath = this._GetSchemaPath(validationDoc); if (sSchemaPath != null) { //Create settings XmlReaderSettings settings = new XmlReaderSettings(); XmlReader xsdReader = this.GetXSD(sSchemaPath); settings.Schemas.Add(null, xsdReader); settings.ValidationType = ValidationType.Schema; //Create reader with settings StringReader strReader = new StringReader(validationDoc.OuterXml); XmlReader xmlReader = XmlReader.Create(strReader, settings); XmlDocument doc = new XmlDocument(); doc.Load(xmlReader); string sXpathVisibleFuncs = string.Format("//*[@{0}][@{1}]", XmlSchemaConstants.Config.Id, XmlSchemaConstants.Config.VisibleFunctions); string sXpathInvisibleFuncs = string.Format("//*[@{0}][@{1}]", XmlSchemaConstants.Config.Id, XmlSchemaConstants.Config.InvisibleFunctions); XmlNodeList nodeListVisibleFuncs = doc.SelectNodes(sXpathVisibleFuncs); XmlNodeList nodeListInvisibleFuncs = doc.SelectNodes(sXpathInvisibleFuncs); foreach (XmlNode visibleFuncNode in nodeListVisibleFuncs) { XmlAttribute xmlAttrCompID = visibleFuncNode.Attributes[XmlSchemaConstants.Config.Id]; XmlAttribute xmlAttrVisibleFuncs = visibleFuncNode.Attributes[XmlSchemaConstants.Config.VisibleFunctions]; int iCompID = int.Parse(xmlAttrCompID.Value); string sVisibleFuncName = xmlAttrVisibleFuncs.Name; string sVisibleFuncValue = xmlAttrVisibleFuncs.Value; schemaValues.AddComponentFunctions(iCompID, sVisibleFuncName, sVisibleFuncValue); }//foreach visible function node foreach (XmlNode invisibleFuncNode in nodeListInvisibleFuncs) { XmlAttribute xmlAttrCompID = invisibleFuncNode.Attributes[XmlSchemaConstants.Config.Id]; XmlAttribute xmlAttrInvisibleFuncs = invisibleFuncNode.Attributes[XmlSchemaConstants.Config.InvisibleFunctions]; int iCompID = int.Parse(xmlAttrCompID.Value); string sInvisibleFuncName = xmlAttrInvisibleFuncs.Name; string sInvisibleFuncValue = xmlAttrInvisibleFuncs.Value; schemaValues.AddComponentFunctions(iCompID, sInvisibleFuncName, sInvisibleFuncValue); }//foreach invisible function node xsdReader.Close(); }//if schemaPath != null }//if validationDoc != null }//try catch(Exception e) { throw e; } return schemaValues; }//_GetDefaultValuesFromSchema
}//_DisplayLinkSchemaPath private XmlElement _GetXmlTree( XmlDocument doc, int compID, string linkType, ComponentOptions compOptions, SchemaDefaults schemaDefs, DataTable componentTable) { Dictionary<String, List<DataRow>> parameterTableCache = null; if (useLoadingCaches) { parameterTableCache = loadingParameterCache[m_model]; } else { if (compOptions.CompParams) { if (!Controller.componentParametersXMLCache[m_model].ContainsKey("" + compID) && compID >= 0) { parameterTableCache = GetParameterTableCache(); } } } // building the caches can be expensive, only do so if we have a link type and multi-level // otherwise we're fetching for a single component if (linkType != null && !linkType.Equals("") && ( (compOptions.LevelDown.HasValue && compOptions.LevelDown.Value >= 2) || !compOptions.LevelDown.HasValue)) { Dictionary<String, DataRow> componentTableCache; Dictionary<String, List<DataRow>> linkTableCache; GetComponentAndLinkTableCache(out componentTableCache, out linkTableCache, componentTable, linkType); DataRow component = null; String key = "" + compID; if (componentTableCache != null) { if (componentTableCache.ContainsKey(key)) { component = componentTableCache[key]; } } else { component = this._GetComponent(compID); } return this._GetXmlTree( doc, component, linkType, compOptions, schemaDefs, new Dictionary<String, String>(), new Dictionary<String, XmlNode>(), componentTable, componentTableCache, linkTableCache, parameterTableCache, new List<Int32>()); } else { return this._GetXmlTree( doc, this._GetComponent(compID), linkType, compOptions, schemaDefs, new Dictionary<String, String>(), new Dictionary<String, XmlNode>(), componentTable, null, null, null, new List<Int32>()); } }//_GetXmlTree
}//_GetXmlTree private XmlElement _GetFunctionsForComponent(XmlDocument doc, int compID, SchemaDefaults schemaDefs) { //creating "Functions" element XmlElement xmlElementFuncs = doc.CreateElement(XmlSchemaConstants.Display.sFunction + "s"); //Functions if (schemaDefs.ComponentFunctions.ContainsKey(compID)) { Dictionary<string, ComponentFunction> compFuncs = schemaDefs.ComponentFunctions[compID]; foreach (ComponentFunction compFunc in compFuncs.Values) { //adding "Function" element to "Functions" element XmlElement xmlElementFunc = CreateXmlFunction(doc, compFunc.Name, compFunc.Action, ""+compFunc.Visible); xmlElementFuncs.AppendChild(xmlElementFunc); }//foreach component function }//if any functions for compID return xmlElementFuncs; }//_GetFunctionsForComponent
protected XmlElement _GetXmlTree(XmlDocument doc, DataRow component, IComponentOnlyOptions compOptions, SchemaDefaults schemaDefs, Dictionary<String, String> typeToBaseCache, Dictionary<String, XmlNode> typeToParametersXMLCache, Dictionary<String, List<DataRow>> parameterTableCache) { if (component == null) { return null; } string sCompType; string sBaseCompType; int iCompID; string sCompName; string sCompDesc; int? iLinkID = null; Component.eComponentType eCompEtype = Component.eComponentType.None; sCompType = (string)component[SchemaConstants.Type]; if (typeToBaseCache != null && typeToBaseCache.ContainsKey(sCompType)) { sBaseCompType = typeToBaseCache[sCompType]; } else { sBaseCompType = this._GetBaseComponentType(sCompType); if (typeToBaseCache != null) { typeToBaseCache.Add(sCompType, sBaseCompType); } } iCompID = (int)component[SchemaConstants.Id]; sCompName = (string)component[SchemaConstants.Name]; sCompDesc = (string)component[SchemaConstants.Description]; eCompEtype = this._GetComponentType(component); //LinkID if (component.Table.Columns.Contains(SchemaConstants.LinkID)) { iLinkID = (int)component[SchemaConstants.LinkID]; } XmlElement xmlElement = this.CommonElementCreate(doc, iCompID, iLinkID, sBaseCompType, sCompType, sCompName, sCompDesc, eCompEtype); // Component Parameters if (compOptions.CompParams) { IXPathNavigable clone = _GetParametersForComponent(component, typeToParametersXMLCache, parameterTableCache); if (clone != null) { XmlNode insert = ((XmlNode)clone).SelectSingleNode(XmlSchemaConstants.Display.sComponentParameters); insert = doc.ImportNode(insert, true); xmlElement.AppendChild(insert); } }//if Parameters //Link Parameters if (compOptions.LinkParams && iLinkID.HasValue) { IXPathNavigable clone = _GetParametersForLink(iLinkID.Value, typeToParametersXMLCache, parameterTableCache); if (clone != null) { XmlNode insert = ((XmlNode)clone).SelectSingleNode(XmlSchemaConstants.Display.sLinkParameters); insert = doc.ImportNode(insert, true); xmlElement.AppendChild(insert); } }//if Link Parameters //Functions if (schemaDefs != null) { XmlElement funcsElement = this._GetFunctionsForComponent(doc, iCompID, schemaDefs); if (funcsElement != null) { xmlElement.AppendChild(funcsElement); } }//if functions return xmlElement; }//_GetXmlTree
}//_GetXmlTree //bypass cache, e.g. single component lookup protected XmlElement _GetXmlTree(XmlDocument doc, DataRow component, IComponentOnlyOptions compOptions, SchemaDefaults schemaDefs) { return this._GetXmlTree(doc, component, compOptions, schemaDefs, null, null, null); }//_GetXmlTree
//bypass cache, e.g. single component lookup protected XmlElement _GetXmlTree(XmlDocument doc, int compID, IComponentOnlyOptions compOptions, SchemaDefaults schemaDefs) { return this._GetXmlTree(doc, this._GetComponent(compID), compOptions, schemaDefs, null, null, null); }//_GetXmlTree
private XmlElement _GetXmlTree(XmlDocument doc, DataRow component, string linkType, ComponentOptions compOptions, SchemaDefaults schemaDefs, Dictionary<String, String> typeToBaseCache, Dictionary<String, XmlNode> typeToParametersXMLCache, DataTable componentTable, Dictionary<String, DataRow> componentTableCache, Dictionary<String, List<DataRow>> linkTableCache, Dictionary<String, List<DataRow>> parameterTableCache, List<Int32> callerIDs) { if (componentTableCache != null && instanceToClassCache == null) { PopulateChildToClassCache(componentTableCache); } if (useLoadingCaches) { instanceToClassCache = loadingInstanceToClassCache; subclassToClassCache = loadingSubClassToClassCache; } if (component == null) { return null; } XmlElement xmlElement = this._GetXmlTree(doc, component, compOptions, schemaDefs, typeToBaseCache, typeToParametersXMLCache, parameterTableCache); //getting children int iCompID = (int)component[SchemaConstants.Id]; if ( !compOptions.LevelDown.HasValue || (compOptions.LevelDown.HasValue && (compOptions.LevelDown.Value > 0)) ) { ComponentOptions newCompOptions = compOptions.Clone(); if (compOptions.LevelDown.HasValue) { newCompOptions.LevelDown = compOptions.LevelDown - 1; } if (linkType != null && !linkType.Equals(String.Empty)) { DataTable childComponents = null; // new fetch - build from component and link table in memory if (componentTable != null && componentTableCache != null && linkTableCache != null) { childComponents = GetChildComponentsByCache(iCompID, linkType, componentTable, componentTableCache, linkTableCache); } else { childComponents = this.m_model.GetChildComponents(iCompID, linkType); } // add self to caller ID list before recursing into children callerIDs.Add(iCompID); foreach (DataRow childComponent in childComponents.Rows) { XmlElement childElement = null; // if child is parent, set level to 0 terminate infinite recursion // or if the child has already made this call, ie he's in the caller ID list int childID = (int)childComponent[SchemaConstants.Id]; if (iCompID == childID || callerIDs.Contains(childID)) { ComponentOptions cloneForSelfLink = newCompOptions.Clone(); cloneForSelfLink.LevelDown = 0; //getting xml element for the child component childElement = this._GetXmlTree(doc, childComponent, linkType, cloneForSelfLink, schemaDefs, typeToBaseCache, typeToParametersXMLCache, componentTable, componentTableCache, linkTableCache, parameterTableCache, callerIDs); } else { childElement = this._GetXmlTree(doc, childComponent, linkType, newCompOptions, schemaDefs, typeToBaseCache, typeToParametersXMLCache, componentTable, componentTableCache, linkTableCache, parameterTableCache, callerIDs); } //adding child element to parent xmlElement.AppendChild(childElement); }//foreach child component // we're returning, remove ourself from the caller list callerIDs.Remove(iCompID); // before we return, check includes for other linktypes to include if (includesMap.Count > 0 && !processingIncludes) { String compType = (String)component[SchemaConstants.Type]; if (includesMap.ContainsKey(compType)) { List<Include> referencedIncludes = includesMap[compType]; foreach (Include referencedInclude in referencedIncludes) { String referenceIncludeLT = referencedInclude.LinkType; if (referencedInclude.IsDynamic) { referenceIncludeLT = this.GetDynamicLinkType(referenceIncludeLT, "" + iCompID); } ComponentOptions full = new ComponentOptions(); full.CompParams = referencedInclude.IncludeParameters; full.ClassInstanceInfo = false; full.SubclassInstanceInfo = false; full.LinkParams = referencedInclude.IncludeParameters; full.LevelDown = referencedInclude.LevelDown; processingIncludes = true; // a guard so that this call doesn't invoke includes! IXPathNavigable inav = this.GetComponentAndChildren(iCompID, referenceIncludeLT, full); processingIncludes = false; XmlElement includes = xmlElement.OwnerDocument.CreateElement("Include"); XmlAttribute isDynamicAttr = xmlElement.OwnerDocument.CreateAttribute("isDynamic"); XmlAttribute linkTypeAttr = xmlElement.OwnerDocument.CreateAttribute("linkType"); XmlAttribute componentTypeAttr = xmlElement.OwnerDocument.CreateAttribute("componentType"); isDynamicAttr.Value = referencedInclude.IsDynamic.ToString(); linkTypeAttr.Value = referencedInclude.LinkType; componentTypeAttr.Value = referencedInclude.ComponentType; includes.Attributes.Append(isDynamicAttr); includes.Attributes.Append(linkTypeAttr); includes.Attributes.Append(componentTypeAttr); XmlNodeList includeAppends = ((XmlDocument)inav).SelectNodes("/Components/Component/Component"); foreach (XmlNode includeAppend in includeAppends) { XmlNode imported = xmlElement.OwnerDocument.ImportNode(includeAppend, true); includes.AppendChild(imported); } xmlElement.AppendChild(includes); } } } } // linkType check }//if depth is > 0 return xmlElement; }//_GetXmlTree