public void Walk(Folder folder, Anakia.Act act) { Queue queue = new Queue(); queue.Enqueue(folder); WalkQueue(queue, act); }
public void Walk(Folder folder, Act act) { foreach(Folder f in folder.Folders) { Walk(f, act); } foreach(DocumentNode node in folder.Documents) { act(node); } }
public DocumentNodeCollection(Folder owner) { this.owner = owner; }
public void Add(Folder folder) { BaseAdd(folder.Name, folder); folder.Parent = owner; }
public FolderCollection(Folder owner) : base(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default) { this.owner = owner; }
// private void PrintStructure(Folder folder, int ident) // { // for(int i = 0; i < ident; i++) // { // Console.Write(' '); // } // // Console.Write(folder.Name); // Console.WriteLine(); // // foreach(Folder f in folder.Folders) // { // PrintStructure(f, ident + 2); // } // } // // private void PrintStructure2(Folder folder, int ident) // { // for(int i = 0; i < ident; i++) // { // Console.Write(' '); // } // // Console.Write(folder.Name); // Console.WriteLine(); // // foreach(DocumentNode node in folder.Documents) // { // for(int i = 0; i < ident + 2; i++) // { // Console.Write(' '); // } // // Console.Write("- "); // Console.Write(node.Filename); // Console.WriteLine(); // } // // foreach(Folder f in folder.Folders) // { // PrintStructure2(f, ident + 2); // } // } private Folder GetFolderInstance(string[] folders) { Folder current = root; foreach(String folderName in folders) { Folder folder = current.Folders[folderName]; if (folder == null) { folder = new Folder(folderName); current.Folders[folderName] = folder; } current = folder; } return current; }
private void AppendFragments(Folder folder, XmlElement elem) { XmlElement el = elem.OwnerDocument.CreateElement(folder.Name); elem.AppendChild(el); el.SetAttribute("level", folder.Level.ToString()); if (folder.Documents.IndexNode != null) { el.SetAttribute("page", folder.Documents.IndexNode.TargetFilename); el.SetAttribute("title", folder.Documents.IndexNode.Meta.Title); } else { Console.WriteLine("No index.xml found for folder " + folder.Path); } el.SetAttribute("path", folder.Path); foreach(XmlDocumentFragment fragment in folder.SectionFragments) { foreach(XmlNode node in fragment.ChildNodes) { el.AppendChild(el.OwnerDocument.ImportNode(node, true)); } } foreach(Folder f in folder.Folders) { AppendFragments(f, el); } }
private void EnsureFolderHasBreadCrumb(Folder folder) { if (folder.BreadCrumbs.Count != 0) return; if (folder.Parent != null) { folder.BreadCrumbs.AddRange(folder.Parent.BreadCrumbs); } String title = folder.Name; if (folder.Documents.IndexNode != null) { title = folder.Documents.IndexNode.Meta.Title; } folder.BreadCrumbs.Add(new BreadCrumb(folder.Path + "/index.html", title)); }
protected override void ExecuteTask() { projectDom = new XmlDocument(); projectDom.Load(projectFile); DirectoryInfo basedir = sourceFileSet.BaseDirectory; root = new Folder("castle"); try { ArrayList staticFilesToCopy = new ArrayList(); foreach(String fullFileName in sourceFileSet.FileNames) { string lastProcessedFile = null; try { lastProcessedFile = fullFileName; String dir = Path.GetDirectoryName(fullFileName); String fileName = Path.GetFileName(fullFileName); String nodeName = String.Empty; Folder folder; String[] folders; if (basedir.FullName.ToLower() != dir.ToLower()) { nodeName = dir.Substring(basedir.FullName.Length + 1); } if (IsStaticFile(fullFileName)) { if (nodeName != String.Empty) { staticFilesToCopy.Add(new FileToCopy( fullFileName, root.Name + "/" + nodeName + "/" + fileName)); } else { staticFilesToCopy.Add(new FileToCopy( fullFileName, root.Name + "/" + fileName)); } continue; } if (nodeName != String.Empty) { folders = nodeName.Split('\\'); folder = GetFolderInstance(folders); } else { folder = root; } XmlDocument doc = new XmlDocument(); doc.Load(fullFileName); DocumentNode node = new DocumentNode(nodeName, fileName, doc, CreateMeta(doc)); folder.Documents.Add(node); } catch(Exception ex) { Console.WriteLine("File: {0} \r\n", lastProcessedFile); Console.WriteLine(ex); Console.WriteLine("\r\n --------------------------------------------------------"); } } siteMapDoc = CreateSiteMap(); siteMapDoc.Save(Path.Combine(TargetDir.FullName, "generatedsitemap.xml")); ITreeWalker walker = new BreadthFirstWalker(); walker.Walk(root, new Act(AssignNavigationDocToFolders)); walker.Walk(root, new Act(CreateBreadCrumb)); walker.Walk(root, new Act(FixRelativePaths)); walker.Walk(root, new Act(CreateHtml)); foreach(FileToCopy file2Copy in staticFilesToCopy) { String dir = Path.GetDirectoryName(file2Copy.TargetFile); EnsureDirExists(dir); String targetFile = targetDir.FullName + "/" + file2Copy.TargetFile; if (File.Exists(targetFile)) { if (File.GetLastWriteTime(targetFile) >= File.GetLastWriteTime(file2Copy.SourceFile)) { continue; } File.Delete(targetFile); } File.Copy(file2Copy.SourceFile, targetFile); } } catch(Exception ex) { Console.WriteLine(ex); Console.Read(); } }