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); }
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; }
private async Task<Tuple<bool, string>> TryGetPageContents(string siteName, ImmutableWikiPage page) { IPageCache pageCache = null; string content = null; // TODO: Async-ify bool hasCache = config.TryGetPageCache(siteName, out pageCache); bool pageContentsCached = hasCache && pageCache.TryGetContents(page.WikiUrl, out content); Tuple<bool, string> results = new Tuple<bool, string>(false, string.Empty); if (!pageContentsCached) { results = await fileReader.TryReadFile(page.WikiPath); } // cache the contents if they weren't already if (hasCache && !pageContentsCached && results.Item1) { pageCache.CachePageContents(page.WikiUrl, results.Item2); } return results; }