/// <summary> /// Gets all the attributes assigned in the xml file for this parameter or all of the nested switches for /// this parameter group /// </summary> private static SwitchRelations ObtainAttributes(XmlNode node, SwitchRelations switchGroup) { SwitchRelations switchRelations; if (switchGroup != null) { switchRelations = switchGroup.Clone(); } else { switchRelations = new SwitchRelations(); } foreach (XmlAttribute attribute in node.Attributes) { // do case-insensitive comparison switch (attribute.Name.ToUpperInvariant()) { case nameProperty: switchRelations.SwitchValue = attribute.InnerText; break; case status: switchRelations.Status = attribute.InnerText; break; default: //LogError("InvalidAttribute", attribute.Name); break; } } return(switchRelations); }
private bool ParseSwitchGroupOrSwitch(XmlNode node, Dictionary <string, SwitchRelations> switchRelationsList, SwitchRelations switchRelations) { while (node != null) { if (node.NodeType == XmlNodeType.Element) { // if the node's name is <ParameterGroup> get all the attributes if (String.Equals(node.Name, switchGroupType, StringComparison.OrdinalIgnoreCase)) { SwitchRelations newSwitchRelations = ObtainAttributes(node, switchRelations); if (!ParseSwitchGroupOrSwitch(node.FirstChild, switchRelationsList, newSwitchRelations)) { return(false); } } else if (String.Equals(node.Name, switchType, StringComparison.OrdinalIgnoreCase)) { // node is a switchRelations if (!ParseSwitch(node, switchRelationsList, switchRelations)) { return(false); } } else if (String.Equals(node.Name, importType, StringComparison.OrdinalIgnoreCase)) { // node is an import option if (!ParseImportOption(node)) { return(false); } } } node = node.NextSibling; } return(true); }
public SwitchRelations Clone() { var cloned = new SwitchRelations { SwitchValue = SwitchValue, Status = Status, Conflicts = new List <string>(Conflicts), Overrides = new List <string>(Overrides), Requires = new List <string>(Requires), ExcludedPlatforms = new List <string>(ExcludedPlatforms), IncludedPlatforms = new List <string>(IncludedPlatforms), ExternalConflicts = new Dictionary <string, List <string> >( ExternalConflicts, StringComparer.OrdinalIgnoreCase), ExternalOverrides = new Dictionary <string, List <string> >( ExternalOverrides, StringComparer.OrdinalIgnoreCase), ExternalRequires = new Dictionary <string, List <string> >( ExternalRequires, StringComparer.OrdinalIgnoreCase) }; return(cloned); }
private static bool ParseSwitch(XmlNode node, Dictionary <string, SwitchRelations> switchRelationsList, SwitchRelations switchRelations) { SwitchRelations switchRelationsToAdd = ObtainAttributes(node, switchRelations); // make sure that the switchRelationsList has a name, unless it is type always if (string.IsNullOrEmpty(switchRelationsToAdd.SwitchValue)) { return(false); } // generate the list of parameters in order if (!switchRelationsList.ContainsKey(switchRelationsToAdd.SwitchValue)) { switchRelationsList.Remove(switchRelationsToAdd.SwitchValue); } // build the dependencies and the values for a parameter XmlNode child = node.FirstChild; while (child != null) { if (child.NodeType == XmlNodeType.Element) { if (String.Equals(child.Name, requiresType, StringComparison.OrdinalIgnoreCase)) { string tool = String.Empty; string Switch = String.Empty; bool isExternal = false; foreach (XmlAttribute attrib in child.Attributes) { switch (attrib.Name.ToUpperInvariant()) { case nameProperty: break; case toolAttribute: isExternal = true; tool = attrib.InnerText; break; case switchAttribute: Switch = attrib.InnerText; break; default: return(false); } } if (!isExternal) { if (Switch != String.Empty) { switchRelationsToAdd.Requires.Add(Switch); } else { return(false); } } else { if (!switchRelationsToAdd.ExternalRequires.ContainsKey(tool)) { var switches = new List <string> { Switch }; switchRelationsToAdd.ExternalRequires.Add(tool, switches); } else { switchRelationsToAdd.ExternalRequires[tool].Add(Switch); } } } else if (String.Equals(child.Name, includedPlatformType, StringComparison.OrdinalIgnoreCase)) { foreach (XmlAttribute attrib in child.Attributes) { switch (attrib.Name.ToUpperInvariant()) { case nameProperty: switchRelationsToAdd.IncludedPlatforms.Add(attrib.InnerText); break; default: return(false); } } } else if (String.Equals(child.Name, excludedPlatformType, StringComparison.OrdinalIgnoreCase)) { foreach (XmlAttribute attrib in child.Attributes) { switch (attrib.Name.ToUpperInvariant()) { case nameProperty: switchRelationsToAdd.ExcludedPlatforms.Add(attrib.InnerText); break; default: return(false); } } } else if (String.Equals(child.Name, overridesType, StringComparison.OrdinalIgnoreCase)) { foreach (XmlAttribute attrib in child.Attributes) { switch (attrib.Name.ToUpperInvariant()) { case switchName: switchRelationsToAdd.Overrides.Add(attrib.InnerText); break; case argumentValueName: break; default: return(false); } } } } child = child.NextSibling; } // We've read any enumerated values and any dependencies, so we just // have to add the switchRelations switchRelationsList.Add(switchRelationsToAdd.SwitchValue, switchRelationsToAdd); return(true); }