/// <summary> /// Remove an existing node. /// </summary> /// <param name="XmlFs"></param> /// <param name="Rootnode"></param> /// <param name="ParentNode"></param> /// <param name="AttributeKeyVal"></param> /// <returns> /// A <see cref="System.Boolean"/>A list of all getted value. /// </returns> public static bool RemoveNode(string XmlFs, string Rootnode, string ParentNode, Dictionary <string, string> AttributeKeyVal) { bool Result = false; XmlDocument doc = new XmlDocument(); try { doc.Load(XmlFs); } catch (Exception) { return(false); } try { XmlNode RootNde = doc.SelectNodes(Rootnode).Item(0); //Create a new node. XmlElement NodeToAdd = doc.CreateElement("CheckedNode"); int AttrCount = 0; foreach (KeyValuePair <string, string> item in AttributeKeyVal) { NodeToAdd.SetAttribute(item.Key, item.Value); AttrCount += 1; } foreach (XmlNode CurNode in RootNde.ChildNodes) { if (string.IsNullOrEmpty(CurNode.Name) == false) { if (CurNode.Name == ParentNode) { foreach (XmlNode ChildNode in CurNode.ChildNodes) { if (ChildNode.Attributes.Count == 2 & NodeToAdd.Attributes.Count == 2) { if (ChildNode.Attributes[0].Value == NodeToAdd.Attributes[0].Value & ChildNode.Attributes[1].Value == NodeToAdd.Attributes[1].Value) { CurNode.RemoveChild(ChildNode); doc.Save(XmlFs); Result = true; break; } } } } } } return(Result); } catch (Exception) { return(false); } }
internal void Dump() { List <int> Stack = new List <int>(); RegexNode CurNode; int CurChild; CurNode = this; CurChild = 0; Debug.WriteLine(CurNode.Description()); for (; ;) { if (CurNode._children != null && CurChild < CurNode._children.Count) { Stack.Add(CurChild + 1); CurNode = CurNode._children[CurChild]; CurChild = 0; int Depth = Stack.Count; if (Depth > 32) { Depth = 32; } Debug.WriteLine(Space.Substring(0, Depth) + CurNode.Description()); } else { if (Stack.Count == 0) { break; } CurChild = Stack[Stack.Count - 1]; Stack.RemoveAt(Stack.Count - 1); CurNode = CurNode._next; } } }
//当前Unit的node是否可以连接到目标Unit的Blocker范围内,一般可以用来做攻击检测 public bool IsInBlockerRange(BaseUnit unit) { HashList <GraphNode> connection = new HashList <GraphNode>(); CurNode.GetConnections(connection.Add); HashList <GraphNode> targetUnitBlocker = AStarMgr.GetBlocker(unit); if (targetUnitBlocker != null) { foreach (var item in targetUnitBlocker) { if (connection.Contains(item)) { return(true); } } } else { CLog.Error("{0}:目标单位没有Blocker", unit.BaseConfig.GetName()); } return(false); }
public static void Parse() { XmlDocument MainXMLSource = _Prev; if (MainXMLSource == null || InputPath != _PrevPath) { MainXMLSource = new XmlDocument(); MainXMLSource.Load(InputPath); _PrevPath = InputPath; _Prev = MainXMLSource; } Encoding enc = GetEncoding(); Dictionary <string, string> PartName = null; using (_Writer = new StreamWriter(OutputPath, false, enc)) { if (ShowComposer || ShowTitle) { FindBeginData(MainXMLSource.DocumentElement); } if (ShowPartName) { PartName = GetParts(MainXMLSource.DocumentElement); } Note.Division = -1; int RepeatId = -1; foreach (XmlNode v in MainXMLSource.SelectNodes("/score-partwise/part")) { if (ShowPartName) { var Part = PartName[v.Attributes["id"].Value]; if (Part.IsNotNullAndNotEmpty()) { WriteString("Part {0}", Part); } } if (ShowPartInstrument) { var Part = v.SelectSingleNode("part-name"); if (Part != null) { var res = Part.InnerText; if (res.IsNotNullAndNotEmpty()) { WriteString("Instrument {0}", res); } } } Tie LastTie = null; _Cache.Clear(); foreach (XmlNode MeasureNode in v.SelectNodes("measure")) { MeasureID = MeasureNode.Attributes["number"].Value.ToInt(); // Measure number if (ShowMeasure) { _Cache.Add(Line.Create("Measure {0}", MeasureID)); } // Div dont print var DivBuf = MeasureNode.SelectSingleNode("attributes/divisions")?.InnerText.ToInt(-1) ?? -1; if (DivBuf > 0) { Note.Division = DivBuf; } if (Note.Division < 1) { throw new Exception("Division was not found."); } bool Chord = false; foreach (XmlNode CurNode in MeasureNode.ChildNodes) { switch (CurNode.Name) { case "attributes": if (ShowClef || ShowTimeSignature || ShowKeys) { ParseAttribute(CurNode); } break; case "note": if (ShowNotes) { var CurNote = new Note(CurNode); var n = CurNode.SelectSingleNode("chord"); if (n != null) { if (!Chord) { Chord = true; (_Cache[_Cache.Count - 1] as Note)?.SetChord(RangeType.Start); } } else if (Chord) { Chord = false; (_Cache[_Cache.Count - 1] as Note)?.SetChord(RangeType.Stop); } if (CurNote.Tie == RangeType.Start) { if (LastTie == null) { LastTie = new Tie(); _Cache.Add(LastTie); } } LastTie?.Add(CurNote.Duration, Note.Division); if (CurNote.Tie == RangeType.Stop) { LastTie = null; } if (LastTie != null && CurNote.Tie != RangeType.Start) { CurNote.Tie = RangeType.Between; } _Cache.Add(CurNote); } break; case "direction": if (ShowWords) { var Word = ParseWord(CurNode); if (Word == ")" && ShowNotes) { //_Cache.Add(new InvisibleLine(InvisibleLine.IDSpicatto)); var buf = _Cache.GetLast() as Note; if (buf != null) { buf.Addition = "spicatto"; } } else if (Word != null) { _Cache.Add(Line.Create("Word {0}", Word)); } } break; case "barline": if (ShowBarLine || ShowRepeats) { ParseBarline(CurNode, MeasureID, ref RepeatId); } break; } } } foreach (var il in _Cache) { il.Print(); } } // //END // WriteString("END"); if (ShowCopyrigths) { ParseCopyrigths(MainXMLSource.DocumentElement, _Writer); } //WriteString("Piranha Touch Aural Visual\r\nCopyright {0} by Stave Breakthrough", DateTime.Now.Year.ToString()); //WriteString("www.stavebreakthrough.com"); } }