public void XMLFormat_Equals_Test2() { XMLFormat xml = new XMLFormat(new XMLFormatInitializerTest2()); XMLFormat xml2 = new XMLFormat(); xml2.SetRoot("deo"); xml2.Append(0, new XMLFormat.DirNode { id = 36, name = "sek" }); xml2.Append(0, new XMLFormat.FileNode { id = 121, name = "try" }); xml2.Append(36, new XMLFormat.DirNode { id = 99, name = "uig" }); xml2.Append(36, new XMLFormat.FileNode { id = 2092, name = "qvg" }); xml2.Append(99, new XMLFormat.FileNode { id = 370, name = "xoj" }); Boolean isEqual = xml.Equals(xml2); Assert.True(isEqual); }
private void FindSubNodesAndAppend(DirNode dnode, Int32 pos, String currPath) { Int32 lvl = currPath.Count(ch => ch == '/'); // Уровень вложенности текущей папки for (Int32 i = pos; i < find.n; i++) { var path = find.GetPath(i); Int32 theLvl = path.Count(ch => ch == '/'); if (theLvl == lvl + 1 && path.StartsWith(currPath)) { String name = path.Substring(currPath.Length + 1); if (IsFile(path, i)) { FileNode fnode = new FileNode { id = find.GetId(i), name = name }; xml.Append(dnode.id, fnode); } else { DirNode node = new DirNode { id = find.GetId(i), name = name }; xml.Append(dnode.id, node); FindSubNodesAndAppend(node, i + 1, currPath + "/" + name); } } } }
public void Init(AFormat format) { XMLFormat xml = (XMLFormat)format; xml.SetRoot("site"); xml.Append(0, new XMLFormat.FileNode { id = 12, name = "news" }); }
public void Init(AFormat format) { XMLFormat xml = (XMLFormat)format; xml.SetRoot("deo"); xml.Append(0, new XMLFormat.DirNode { id = 36, name = "sek" }); xml.Append(0, new XMLFormat.FileNode { id = 121, name = "try" }); xml.Append(36, new XMLFormat.DirNode { id = 99, name = "uig" }); xml.Append(36, new XMLFormat.FileNode { id = 2092, name = "qvg" }); xml.Append(99, new XMLFormat.FileNode { id = 370, name = "xoj" }); }
private void ProcessDirectory(XMLFormat xml, Int32 currDirId) { String line, type, name; Int32 id; do { line = Console.ReadLine(); if (line == null || line.EndsWith("</dir>")) { return; } var tuple = GetTypeNameIdTupleFromLine(line); type = tuple.Item1; name = tuple.Item2; id = tuple.Item3; if (id == 0) { xml.SetRoot(name); ProcessDirectory(xml, 0); } else { if (type == "dir") { xml.Append(currDirId, new DirNode { id = id, name = name }); ProcessDirectory(xml, id); } else if (type == "file") { xml.Append(currDirId, new FileNode { id = id, name = name }); } } } while(line != null); }
public void XMLFormatInitializerTest1() { XMLFormat xml = new XMLFormat(new XMLFormatInitializerTest1()); XMLFormat xml2 = new XMLFormat(); xml2.SetRoot("site"); xml2.Append(0, new XMLFormat.FileNode { id = 12, name = "news" }); Boolean isEqual = xml.Equals(xml2); Assert.True(isEqual); }
public void XMLFormat_Append_Test1() { XMLFormat xml = new XMLFormat(); xml.SetRoot("a"); xml.Append(0, new XMLFormat.FileNode() { name = "b", id = 1 }); var node = xml.GetNode(1); Assert.True(node.name == "b"); }