Example #1
0
        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);
        }
Example #2
0
        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;
        }