private void DeleteParentIfEmpty(WikiDirectory parent) { // there's no point keeping empty directories around so delete if empty if (!parent.Children.Any()) { DeleteEntryCommon(parent); } }
private void DeleteDirectoryDetails(WikiDirectory directory) { // remove ourselves from the map UnderlyingModel.RemoveAsset(directory.SourcePath); // fire event HandleDirectoryDeleted(directory); }
public void Visit(WikiDirectory directory) { // add to the stack directoryStack.Push(directory); foreach (var child in directory.Children) { child.Accept(this); } }
public void Visit(WikiDirectory directory) { foreach (var child in directory.Children) { child.Accept(this); } if (directoryDeleteAction != null) { directoryDeleteAction(directory); } }
private IDictionary <string, ImmutableWikiEntry> CreateFinalMapBy(Func <IWikiEntry, string> keySelector) { IDictionary <string, ImmutableWikiEntry> map = new Dictionary <string, ImmutableWikiEntry>(); while (directoryStack.Any()) { WikiDirectory directory = directoryStack.Pop(); IList <ImmutableWikiEntry> children = new List <ImmutableWikiEntry>(); foreach (WikiEntry mutableChild in directory.Children) { if (mutableChild is WikiPage) { // create the child and add to the directory and to the map ImmutableWikiPage immutablePage = new ImmutableWikiPage( mutableChild.SourcePath, mutableChild.WikiPath, mutableChild.WikiUrl, mutableChild.LastUpdated, mutableChild.Depth); map[keySelector(mutableChild)] = immutablePage; children.Add(immutablePage); } else if (mutableChild is WikiDirectory) { // because we are traversing the branches of the tree from leaf to root // we can assume that any directory children have already been added to the // map children.Add(map[keySelector(mutableChild)]); } } // now add the directory itself ImmutableWikiDirectory immutableDirectory = new ImmutableWikiDirectory( directory.SourcePath, directory.WikiPath, directory.WikiUrl, directory.LastUpdated, directory.Depth, children); map[keySelector(immutableDirectory)] = immutableDirectory; } return(map); }
/// <summary> /// Adds a directory to the model. /// </summary> /// <param name="sourcePath">Source path of the directory</param> /// <param name="rootInfo">Contains information about directory, *only* if the directory being added is the root</param> protected void AddDirectory(string sourcePath, RootInfo rootInfo) { WikiDirectory parent = null; if (rootInfo == null) { string parentPath = Path.GetDirectoryName(sourcePath); // recursively add any directories between us and the closest ancestor // in the map if (!UnderlyingModel.ContainsAssetBySourcePath(parentPath)) { AddDirectory(parentPath, null); } parent = UnderlyingModel.UnsafeGetAsset(parentPath) as WikiDirectory; } WikiDirectory newDirectory = new WikiDirectory { SourcePath = sourcePath, LastUpdated = DateTime.UtcNow, Depth = sourcePath.Count(c => c.Equals(Path.DirectorySeparatorChar)), Parent = parent, Children = new List <WikiEntry>() }; if (rootInfo == null) { newDirectory.WikiUrl = PathHelper.GetWikiUrl(UnderlyingModel.RootSourcePath, newDirectory.SourcePath); newDirectory.WikiPath = Path.Combine(UnderlyingModel.RootWikiPath, newDirectory.WikiUrl); // add child to the parent parent.Children.Add(newDirectory); } else { newDirectory.WikiUrl = ""; newDirectory.WikiPath = rootInfo.RootWikiPath; UnderlyingModel.SetRootDirectory(newDirectory); } UnderlyingModel.AddAsset(newDirectory.SourcePath, newDirectory); // fire event HandleDirectoryAdded(newDirectory); }
// // Protected methods, for use by derived classes // protected void AddPage(string fullPath) { // make sure we've got the full path fullPath = PathHelper.GetFullPath(fullPath); if (UnderlyingModel.ContainsAssetBySourcePath(fullPath)) { // page already exists return; } string parentPath = Path.GetDirectoryName(fullPath); // recursively add any directories between us and the closest ancestor // in the map if (!UnderlyingModel.ContainsAssetBySourcePath(parentPath)) { AddDirectory(parentPath, null); } WikiDirectory parent = UnderlyingModel.UnsafeGetAsset(parentPath) as WikiDirectory; WikiPage newPage = new WikiPage { SourcePath = fullPath, LastUpdated = DateTime.UtcNow, Depth = fullPath.Count(c => c.Equals(Path.DirectorySeparatorChar)), Parent = parent }; string relativePath = PathHelper.GetWikiUrl(UnderlyingModel.RootSourcePath, newPage.SourcePath); // change file extension newPage.WikiUrl = Path.Combine(Path.GetDirectoryName(relativePath), Path.GetFileNameWithoutExtension(relativePath) + ".html"); newPage.WikiPath = Path.Combine(UnderlyingModel.RootWikiPath, newPage.WikiUrl); // add child to the parent parent.Children.Add(newPage); // add to the map UnderlyingModel.AddAsset(fullPath, newPage); // fire event HandlePageAdded(newPage); }
public void Visit(WikiDirectory directory) { string oldSourcePath = directory.SourcePath; string oldWikiPath = directory.WikiPath; string oldWikiUrl = directory.WikiUrl; CommonVisit(directory); foreach (var child in directory.Children) { child.Accept(this); } if (directoryRenameAction != null) { directoryRenameAction(oldSourcePath, oldWikiPath, oldWikiUrl, directory); } }
protected abstract void HandleDirectoryUpdated(WikiDirectory page);
public void SetRootDirectory(WikiDirectory root) { rootDirectory = root; }
protected abstract void HandleDirectoryDeleted(WikiDirectory page);
protected override void HandleDirectoryMoved(WikiDirectory page, string oldSourcePath, string oldWikiPath, string oldWikiUrl) { System.Console.WriteLine("{0} Firing event (DirectoryMoved: {1}) on thread: {2}", DateTime.Now.Ticks, page.SourcePath, Thread.CurrentThread.Name); FireEvent(DirectoryMoved, page, oldSourcePath, oldWikiPath, oldWikiUrl); }
protected abstract void HandleDirectoryMoved(WikiDirectory page, string oldSourcePath, string oldWikiPath, string oldWikiUrl);