private static bool ProcessItemGroupNode(XPathNavigator nav) { try { if (nav.MoveToChild("StyleCopTreatErrorsAsWarnings", "http://schemas.microsoft.com/developer/msbuild/2003")) { if (nav.Value == "false") { nav.ReplaceSelf("<StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>"); } else { nav.ReplaceSelf("<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>"); } } else { nav.AppendChild("<StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>"); } return true; } catch { return false; } }
public virtual XmlWriter InsertAfter() { switch (NodeType) { case XPathNodeType.Root: case XPathNodeType.Attribute: case XPathNodeType.Namespace: throw new InvalidOperationException(String.Format("Insertion after {0} is not allowed.", NodeType)); } XPathNavigator nav = Clone(); if (nav.MoveToNext()) { return(nav.InsertBefore()); } else if (nav.MoveToParent()) { return(nav.AppendChild()); } else { throw new InvalidOperationException("Could not move to parent to insert sibling node"); } }
/// <summary> /// Updates the node replacing inheritdoc node with comments found. /// </summary> /// <param name="inheritDocNodeNavigator">Navigator for inheritdoc node</param> /// <param name="contentNodeNavigator">Navigator for content</param> private void UpdateNode(XPathNavigator inheritDocNodeNavigator, XPathNavigator contentNodeNavigator) { // retrieve the selection filter if specified. string selectValue = inheritDocNodeNavigator.GetAttribute("select", string.Empty); if(!string.IsNullOrEmpty(selectValue)) sourceExpression = XPathExpression.Compile(selectValue); inheritDocNodeNavigator.MoveToParent(); if(inheritDocNodeNavigator.LocalName != "comments" && inheritDocNodeNavigator.LocalName != "element") sourceExpression = XPathExpression.Compile(inheritDocNodeNavigator.LocalName); else inheritDocNodeNavigator.MoveTo(this.sourceDocument.CreateNavigator().SelectSingleNode(inheritDocExpression)); XPathNodeIterator sources = (XPathNodeIterator)contentNodeNavigator.CreateNavigator().Evaluate(sourceExpression); inheritDocNodeNavigator.DeleteSelf(); // append the source nodes to the target node foreach(XPathNavigator source in sources) inheritDocNodeNavigator.AppendChild(source); }
private void WriteApiPlatforms(XPathNavigator referenceNode, string apiGroup, string topicTypeName, string topicNamespaceName) { XPathNodeIterator versionNodes = referenceNode.Select(versionNodesExpression); List<string> supportedPlatforms = new List<string>(); XmlWriter platformsWriter = referenceNode.AppendChild(); foreach (string platformId in versionFilters.Keys) { Dictionary<string, VersionFilter> filters = versionFilters[platformId]; bool included = false; foreach (XPathNavigator versionNode in versionNodes) { string versionId = versionNode.GetAttribute("name", string.Empty); VersionFilter filter; if (filters.TryGetValue(versionId, out filter)) { switch (apiGroup) { case "type": included = filter.IsIncludedType(referenceNode, topicNamespaceName); break; case "member": included = filter.IsIncludedMember(referenceNode, topicTypeName, topicNamespaceName); break; } } if (included) break; } if (included) supportedPlatforms.Add(platformId); } platformsWriter.WriteStartElement("platforms"); foreach (string platformId in supportedPlatforms) { platformsWriter.WriteElementString("platform", platformId); } platformsWriter.WriteEndElement(); platformsWriter.Close(); }
/// <summary> /// Merge the XML comments from one member into another /// </summary> /// <param name="fromMember">The member from which to merge comments</param> /// <param name="toMember">The member into which the comments merged</param> /// <param name="filter">The selection filter</param> private static void MergeComments(XPathNavigator fromMember, XPathNavigator toMember, string filter) { XPathNavigator duplicate; string[] dupAttrs = new string[] { "cref", "href", "name", "vref", "xref" }; string attrValue; if(String.IsNullOrEmpty(filter)) filter = "*"; // Merge based on the element name foreach(XPathNavigator element in fromMember.Select(filter)) switch(element.Name) { case "example": // Ignore if already present case "exclude": case "filterpriority": case "preliminary": case "summary": case "remarks": case "returns": case "threadsafety": case "value": if(toMember.SelectSingleNode(element.Name) == null) toMember.AppendChild(element); break; case "overloads": // Ignore completely. We only need one. break; default: if(!element.HasAttributes) toMember.AppendChild(element); else { // Ignore if there is a duplicate by attribute // name and value. duplicate = null; foreach(string attrName in dupAttrs) { attrValue = element.GetAttribute(attrName, String.Empty); if(!String.IsNullOrEmpty(attrValue)) { duplicate = toMember.SelectSingleNode(String.Format(CultureInfo.InvariantCulture, "{0}[@{1}='{2}']", element.Name, attrName, attrValue)); if(duplicate != null) break; } } if(duplicate == null) toMember.AppendChild(element); } break; } }
private void EnsureChildNode(XPathNavigator parent, string nodeName) { XPathNavigator child = parent.SelectSingleNode(String.Format("c:{0}", nodeName), _resolver); if (child == null) parent.AppendChild(String.Format("<{0}/>", nodeName)); }
private void createSpecies(XPathNavigator navLocal, XmlDocument document, XPathNavigator navGlobal) { // Set up component values String cType = "Species"; String cName = navLocal.SelectSingleNode("Name").Value; String cDescription = String.Empty; // Create component createComponent(VSGConfiguration, document, cType, cName, cDescription); // Create links #region links // Scenario createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), cName, "Scenario", String.Empty); // SpeciesType createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), cName, "SpeciesType", String.Empty); String speciesBase = (navLocal.SelectSingleNode("Base") == null) ? String.Empty : navLocal.SelectSingleNode("Base").Value; if (navGlobal.SelectSingleNode(String.Format("/Scenario/Species[Name='{0}']", speciesBase)) != null) { createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), cName, speciesBase, "SpeciesType", String.Empty); speciesBase = "ExistingSpecies"; } #endregion // Create parameters #region parameters createParameter(VSGConfiguration, document, cName, "Component", "Species.IsWeapon", (navLocal.SelectSingleNode("IsWeapon") == null) ? String.Empty : navLocal.SelectSingleNode("IsWeapon").Value, String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.RemoveOnDestruction", (navLocal.SelectSingleNode("RemoveOnDestruction") == null) ? String.Empty : navLocal.SelectSingleNode("RemoveOnDestruction").Value, String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.CollisionRadius", (navLocal.SelectSingleNode("Size") == null) ? String.Empty : navLocal.SelectSingleNode("Size").Value, String.Empty); switch (speciesBase) { case "LandObject": createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "true", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); break; case "AirObject": createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "true", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); break; case "SeaObject": createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "true", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); break; case "ExistingSpecies": createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "true", String.Empty); break; default: createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); break; } // Name States // Because of the State to State links we need to create the names first. Then create them. XPathNodeIterator itStates = navLocal.Select("FullyFunctional | DefineState"); while (itStates.MoveNext()) { if (itStates.Current.SelectSingleNode("State") != null) { String stateName = itStates.Current.SelectSingleNode("State").Value; //itStates.Current.SelectSingleNode("State").SetValue(cName + AME.Tools.ImportTool.Delimitter + stateName); itStates.Current.CreateAttribute(String.Empty, "name", itStates.Current.NamespaceURI, cName + AME.Tools.ImportTool.Delimitter + stateName); } else //itStates.Current.AppendChildElement(String.Empty, "State", String.Empty, cName + AME.Tools.ImportTool.Delimitter + "FullyFunctional"); itStates.Current.CreateAttribute(String.Empty, "name", String.Empty, cName + AME.Tools.ImportTool.Delimitter + "FullyFunctional"); } // Create States itStates = navLocal.Select("FullyFunctional | DefineState"); Boolean isDeadState = false; while (itStates.MoveNext()) { String stateName = itStates.Current.GetAttribute("name", itStates.Current.NamespaceURI); if (stateName.ToLower().Equals(cName.ToLower() + AME.Tools.ImportTool.Delimitter + "Dead".ToLower())) isDeadState = true; } if (!isDeadState) { String name = cName + AME.Tools.ImportTool.Delimitter + "Dead"; XmlElement deadState = document.CreateElement("DefineState"); XmlAttribute deadStateName = document.CreateAttribute("name"); deadStateName.InnerXml = name; deadState.Attributes.Append(deadStateName); XmlElement state = document.CreateElement("State"); state.InnerXml = name; deadState.AppendChild(state); navLocal.AppendChild(deadState.CreateNavigator()); } itStates = navLocal.Select("FullyFunctional | DefineState"); while (itStates.MoveNext()) { createState(itStates.Current, document, navGlobal); } #endregion }
private void createSpecies(XPathNavigator navLocal, XmlDocument document, XPathNavigator navGlobal) { // Set up component values String cType = "Species"; String cName = navLocal.SelectSingleNode("Name").Value; String cDescription = String.Empty; // Create component createComponent(VSGConfiguration, document, cType, cName, cDescription); // Create links #region links // Scenario createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), cName, "Scenario", String.Empty); // SpeciesType createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), cName, "SpeciesType", String.Empty); String speciesBase = (navLocal.SelectSingleNode("Base") == null) ? String.Empty : navLocal.SelectSingleNode("Base").Value; if (navGlobal.SelectSingleNode(String.Format("/Scenario/Species[Name='{0}']", speciesBase)) != null) { createLink(VSGConfiguration, document, navGlobal.SelectSingleNode("/Scenario").GetAttribute("name", navGlobal.NamespaceURI), cName, speciesBase, "SpeciesType", String.Empty); speciesBase = "ExistingSpecies"; } // SpeciesDMCanOwn String canDMOwn = (navLocal.SelectSingleNode("CanOwn") == null) ? String.Empty : navLocal.SelectSingleNode("CanOwn").Value; if (canDMOwn != String.Empty) { String[] dms = canDMOwn.Split(','); foreach (String dm in dms) { String dmName = dm.Trim(); if (navGlobal.SelectSingleNode(String.Format("/Scenario/DecisionMaker[Identifier='{0}']", dmName)) != null) { createLink(VSGConfiguration, document, cName, cName, dmName, "SpeciesDMCanOwn", String.Empty); } } } XPathNodeIterator itCapacities = navLocal.Select("SubplatformCapacity"); while (itCapacities.MoveNext()) { String subplatformSpeciesName = itCapacities.Current.SelectSingleNode("SpeciesName").Value; int subplatformSpeciesCount = Int32.Parse(itCapacities.Current.SelectSingleNode("Count").Value); String dynamicLinkName = GetDynamicLinkType("SpeciesSubplatformCapacity", cName); createLink(VSGConfiguration, document, cName, cName, subplatformSpeciesName, dynamicLinkName, String.Empty); String linkID = GetLinkID(cName, subplatformSpeciesName, dynamicLinkName); createParameter(VSGConfiguration, document, linkID, eParamParentType.Link.ToString(), "Capacity.Count", subplatformSpeciesCount.ToString(), ""); } #endregion // Create parameters #region parameters createParameter(VSGConfiguration, document, cName, "Component", "Species.IsWeapon", (navLocal.SelectSingleNode("IsWeapon") == null) ? String.Empty : navLocal.SelectSingleNode("IsWeapon").Value, String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.RemoveOnDestruction", (navLocal.SelectSingleNode("RemoveOnDestruction") == null) ? String.Empty : navLocal.SelectSingleNode("RemoveOnDestruction").Value, String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.DefaultClassification", (navLocal.SelectSingleNode("DefaultClassification") == null) ? String.Empty : navLocal.SelectSingleNode("DefaultClassification").Value, String.Empty); if (navLocal.SelectSingleNode("ClassificationDisplayRules") != null) { String rules = navLocal.SelectSingleNode("ClassificationDisplayRules").OuterXml; ClassificationDisplayRules CDRs = new ClassificationDisplayRules(); int i = rules.IndexOf("\r\n"); int start = rules.IndexOf(">",i-1); int end = rules.IndexOf("<", i); while (i >= 0) { start = rules.IndexOf(">", i-1); end = rules.IndexOf("<", start); if (end - start > 1) { rules = rules.Remove(start + 1, end - start-1); } i = rules.IndexOf("\r\n"); } CDRs.Rules = ClassificationDisplayRules.FromXML(rules); createParameter(VSGConfiguration, document, cName, "Component", "Species.ClassificationDisplayRules", CDRs.ToXML(), String.Empty); } createParameter(VSGConfiguration, document, cName, "Component", "Species.CollisionRadius", (navLocal.SelectSingleNode("Size") == null) ? String.Empty : navLocal.SelectSingleNode("Size").Value, String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.LaunchedByOwner", (navLocal.SelectSingleNode("LaunchedByOwner") == null) ? String.Empty : navLocal.SelectSingleNode("LaunchedByOwner").Value, String.Empty); switch (speciesBase) { case "LandObject": createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "true", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); break; case "AirObject": createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "true", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); break; case "SeaObject": createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "true", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); break; case "ExistingSpecies": createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "true", String.Empty); break; default: createParameter(VSGConfiguration, document, cName, "Component", "Species.LandObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.AirObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.SeaObject", "false", String.Empty); createParameter(VSGConfiguration, document, cName, "Component", "Species.ExistingSpecies", "false", String.Empty); break; } // Name States // Because of the State to State links we need to create the names first. Then create them. XPathNodeIterator itStates = navLocal.Select("FullyFunctional | DefineState"); while (itStates.MoveNext()) { if (itStates.Current.SelectSingleNode("State") != null) { String stateName = itStates.Current.SelectSingleNode("State").Value; //itStates.Current.SelectSingleNode("State").SetValue(cName + AME.Tools.ImportTool.Delimitter + stateName); itStates.Current.CreateAttribute(String.Empty, "name", itStates.Current.NamespaceURI, cName + AME.Tools.ImportTool.Delimitter + stateName); } else //itStates.Current.AppendChildElement(String.Empty, "State", String.Empty, cName + AME.Tools.ImportTool.Delimitter + "FullyFunctional"); itStates.Current.CreateAttribute(String.Empty, "name", String.Empty, cName + AME.Tools.ImportTool.Delimitter + "FullyFunctional"); } // Create States itStates = navLocal.Select("FullyFunctional | DefineState"); Boolean isDeadState = false; while (itStates.MoveNext()) { String stateName = itStates.Current.GetAttribute("name", itStates.Current.NamespaceURI); if (stateName.ToLower().Equals(cName.ToLower() + AME.Tools.ImportTool.Delimitter + "Dead".ToLower())) isDeadState = true; } if (!isDeadState) { String name = cName + AME.Tools.ImportTool.Delimitter + "Dead"; XmlElement deadState = document.CreateElement("DefineState"); XmlAttribute deadStateName = document.CreateAttribute("name"); deadStateName.InnerXml = name; deadState.Attributes.Append(deadStateName); XmlElement state = document.CreateElement("State"); state.InnerXml = name; deadState.AppendChild(state); navLocal.AppendChild(deadState.CreateNavigator()); } itStates = navLocal.Select("FullyFunctional | DefineState"); while (itStates.MoveNext()) { createState(itStates.Current, document, navGlobal); } #endregion }
private static void Merge(XPathNavigator DstNavi, XmlDocument SrcDoc, string Parent) { var Current = NodePath(Parent, NodeView(DstNavi)); if (!string.IsNullOrWhiteSpace(Current)) { if (DstNavi.NodeType == XPathNodeType.Element) { var SrcElem = SrcDoc.SelectSingleNode(Current); if (SrcElem != null) { var Frozen = GetFrozenAttributes(Current, FrozenAttributes); if (DstNavi.MoveToFirstAttribute()) { do { var SrcElemAttr = SrcElem.Attributes[DstNavi.LocalName]; if (SrcElemAttr != null && CanProcess(DstNavi.LocalName, Frozen)) DstNavi.SetValue(SrcElemAttr.Value); } while (DstNavi.MoveToNextAttribute()); DstNavi.MoveToParent(); } } } else if (DstNavi.NodeType == XPathNodeType.Text) { var SrcElem = SrcDoc.SelectSingleNode(Current); if (SrcElem != null) DstNavi.SetValue(SrcElem.InnerText); } if (DstNavi.MoveToFirstChild()) { do { Merge(DstNavi, SrcDoc, Current); } while (DstNavi.MoveToNext()); DstNavi.MoveToParent(); } else if (DstNavi.NodeType == XPathNodeType.Element) { var SrcElem = SrcDoc.SelectSingleNode(Current); if (SrcElem != null && !string.IsNullOrWhiteSpace(SrcElem.InnerXml)) foreach (XmlNode Child in SrcElem.ChildNodes) DstNavi.AppendChild(Child.CloneNode(true).CreateNavigator()); } } }