public HierachyNode(HierachyNode parent, string name) { if (string.IsNullOrEmpty(name) == true) { throw new ArgumentException("name값으로 null을 사용할 수 없습니다.", "name"); } _parent = parent; _name = name; _props = new ListDictionary(); _props[NODENAME] = _name; _props[DEPTH] = -1; }
private static void ApplyPropertiesToChild(HierachyNode parent, HierachyNode child) { foreach (DictionaryEntry entry in parent.Properties) { if (entry.Value is HierachyNodeProperty && (string)entry.Key != HierachyNode.DESCRIPTION && (string)entry.Key != HierachyNode.CATEGORIES && (string)entry.Key != HierachyNode.NODENAME) { HierachyNodeProperty prop = entry.Value as HierachyNodeProperty; if (prop.ApplyToDescendents == true) { child.Properties[entry.Key] = entry.Value; if (string.IsNullOrEmpty(prop.Description) == false) { string key = string.Format( "{0}_{1}", HierachyNode.DESCRIPTION, entry.Key); child.Properties[key] = prop.Description; } } } } }
public static HierachyNode LoadFromFile(string filePath) { string resourceName = "ebay.tests.NUnitExtension.HierachicalTestCase.HierachicalTestCaseSchema.xsd"; HierachyNode rootNode = null; Stream schemaStm = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName); XmlReader schemaReader = XmlReader.Create(schemaStm); XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Auto; settings.IgnoreWhitespace = true; settings.IgnoreComments = true; settings.ValidationType = ValidationType.Schema; settings.Schemas.Add(null, schemaReader); settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); using (XmlReader reader = XmlReader.Create(filePath, settings)) { reader.MoveToContent(); if (reader.ReadToDescendant("node") == true) { int prevDepth = reader.Depth; rootNode = new HierachyNode(null, "undefined"); rootNode.Depth = reader.Depth; ParseHierachyNodeXml(rootNode, reader); HierachyNode currentNode = rootNode; while (reader.Read()) { if (reader.LocalName != "node") { reader.ReadToFollowing("node"); } if (reader.LocalName == "node") { HierachyNode parentNode = null; int currentDepth = reader.Depth; if (currentDepth == prevDepth) { parentNode = currentNode.Parent; } else if (currentDepth > prevDepth) { parentNode = currentNode; } else if (currentDepth < prevDepth) { parentNode = currentNode.Parent; while (parentNode.Depth >= currentDepth) { parentNode = parentNode.Parent; } } currentNode = parentNode.CreateNewChildNode("undefined"); currentNode.Depth = currentDepth; HierachicalTestCaseService.ApplyPropertiesToChild(parentNode, currentNode); parentNode.Add(currentNode); ParseHierachyNodeXml(currentNode, reader); prevDepth = currentDepth; } } } } return rootNode; }
private static void ParseHierachyNodeXml(HierachyNode node, XmlReader reader) { string name = reader.GetAttribute("name"); string valueText = reader.GetAttribute("value"); string valueType = reader.GetAttribute("valueType"); string desc = reader.GetAttribute("description"); if (name != null) { node.Name = name; } if (string.IsNullOrEmpty(valueText) == false) { if (string.IsNullOrEmpty(valueType) == false && valueType != "string") { node.Value = HierachicalTestCaseService.ParseValue(valueText, valueType); } else { node.Value = valueText; } } if (string.IsNullOrEmpty(desc) == false) { node.Description = desc; } if (reader.IsEmptyElement == false) { reader.Read(); if (reader.IsStartElement("valueData") == true) { if (string.IsNullOrEmpty(valueText) == false) { reader.Skip(); } else { reader.ReadStartElement("valueData"); valueText = reader.ReadString(); if (string.IsNullOrEmpty(valueText) == false) { node.Value = HierachicalTestCaseService.ParseValue(valueText, valueType); } reader.ReadEndElement(); } } if (reader.IsStartElement("properties") == true) { reader.ReadStartElement("properties"); do { if(reader.LocalName != "property") { break; } HierachyNodeProperty prop = ParsePropertyNodeXml(reader); if (prop.Value != null) { node.Properties[prop.Name] = prop; } }while(true); reader.ReadEndElement(); //properties } } }
public HierachyNode CreateNewChildNode(string name, bool copyProperties) { HierachyNode childNode = new HierachyNode(this, name); if (copyProperties == true) { foreach (DictionaryEntry entry in this.Properties) { if ((string)entry.Key != DESCRIPTION && (string)entry.Key != CATEGORIES && (string)entry.Key != NODENAME) { childNode.Properties[entry.Key] = entry.Value; } } } return childNode; }
public int Add(HierachyNode childNode) { childNode._parent = this; return this.Nodes.Add(childNode); }