Example #1
0
        /// <summary>
        /// Registers the specified topic and all subtopics.
        /// </summary>
        public void Register(NTopic topic)
        {
            if (topic == null)
            {
                return;
            }

            var previousTopic = FindById(topic.Id);

            if (previousTopic is NTopic)
            {
                Logger.Error("The topic [{0}] is already declared", previousTopic.Id);
                return;
            }

            // Otherwise, the previous topic is probably a class/member definition, so we
            // don't need to register it
            if (previousTopic != null)
            {
                return;
            }

            // If this is a real topic, we can register it and all its children
            Register((IModelReference)topic);
            foreach (var subTopic in topic.SubTopics)
            {
                Register(subTopic);
            }
        }
Example #2
0
 /// <summary>
 /// Associate topics with their parent
 /// </summary>
 public void BuildParents(NTopic parentTopic = null)
 {
     Parent = parentTopic;
     foreach (var subTopic in SubTopics)
     {
         subTopic.BuildParents(this);
     }
 }
Example #3
0
        /// <summary>
        /// Finds the topic by id.
        /// </summary>
        /// <param name="topics">The topics.</param>
        /// <param name="topicId">The topic id.</param>
        /// <returns></returns>
        public static NTopic FindTopicById(IEnumerable <NTopic> topics, string topicId)
        {
            NTopic topicFound = null;

            foreach (var topic in topics)
            {
                topicFound = topic.FindTopicById(topicId);
                if (topicFound != null)
                {
                    break;
                }
            }
            return(topicFound);
        }
Example #4
0
        /// <summary>
        /// Registers the specified topic and all subtopics.
        /// </summary>
        public void Register(NTopic topic)
        {
            if (topic == null)
                return;

            var previousTopic = FindById(topic.Id);
            if (previousTopic is NTopic)
            {
                Logger.Error("The topic [{0}] is already declared", previousTopic.Id);
                return;
            }

            // Otherwise, the previous topic is probably a class/member definition, so we
            // don't need to register it
            if (previousTopic != null)
                return;

            // If this is a real topic, we can register it and all its children
            Register((IModelReference)topic);
            foreach (var subTopic in topic.SubTopics)
                Register(subTopic);
        }
Example #5
0
 /// <summary>
 /// Associate topics with their parent
 /// </summary>
 public void BuildParents(NTopic parentTopic = null)
 {
     Parent = parentTopic;
     foreach (var subTopic in SubTopics)
         subTopic.BuildParents(this);
 }
Example #6
0
        /// <summary>
        /// Build topics for Assemblies, Namespaces and Types in order to use them in the TOC
        /// </summary>
        public void Run(Config config, Func<IModelReference, string> pageIdFunction)
        {
            RootTopic = config.RootTopic;

            // Load an existing root topic
            if (RootTopic != null)
            {
                RootTopic.ForEachTopic(
                    topic =>
                        {
                            topic.PageId = pageIdFunction(topic);

                            // Check that PageId is a valid filename
                            if (!Utility.IsValidFilename(topic.PageId))
                                Logger.Error("Invalid PageId [{0}] for topic [{1}]. Fileid must contain valid filename chars", topic.PageId, this);
                        });
            }

            NTopic topicLibrary = null;

            // If there are any assemblies, we have to generate class library topics
            if (Namespaces.Count >= 0)
            {
                // Find if a ClassLibrary topic is referenced in the config topic
                topicLibrary = (RootTopic != null) ? RootTopic.FindTopicById(NTopic.ClassLibraryTopicId) : null;
                if (topicLibrary == null)
                {
                    // If no class library topic found, create a new one
                    topicLibrary = NTopic.DefaultClassLibraryTopic;
                    if (RootTopic == null)
                        RootTopic = topicLibrary;
                    else
                        RootTopic.SubTopics.Add(topicLibrary);
                }
                ClassLibraryTopic = topicLibrary;
            }

            if (RootTopic == null)
            {
                Logger.Fatal("No root topic assigned/ no topic for class library ");
                return;
            }

            // Calculate starting index for class library based on index from topics
            int index = 0;
            var indices = new HashSet<int>();
            var topicToReindex = new List<NTopic>();
            RootTopic.ForEachTopic(
                topic =>
                    {
                        if (indices.Contains(topic.Index))
                        {
                            // Silently reassign an index, as index is no longer important
                            //Logger.Warning("Index [{0}] for Topic [{1}] is already used. Need to reassign a new index.", topic.Index, topic.Name);
                            topicToReindex.Add(topic);
                        }
                        else
                        {
                            indices.Add(topic.Index);
                            index = Math.Max(index, topic.Index);
                        }
                    });
            index++;
            foreach (var topicToIndex in topicToReindex)
            {
                topicToIndex.Index = index++;
            }

            foreach (var @namespace in Namespaces)
            {
                // Affect new Index based on previous topics
                @namespace.Index = index++;
                var namespaceTopic = new NTopic(@namespace) { Name = @namespace.Name + " Namespace", AttachedClassNode = @namespace };
                @namespace.TopicLink = namespaceTopic;
                topicLibrary.SubTopics.Add(namespaceTopic);
                @namespace.SeeAlsos.Add(new NSeeAlso(topicLibrary));

                foreach (var type in @namespace.Types)
                {
                    // Affect new Index based on previous topics
                    type.Index = index++;
                    var typeTopic = new NTopic(type) { Name = type.Name + " " + type.Category, AttachedClassNode = type};
                    type.TopicLink = typeTopic;
                    namespaceTopic.SubTopics.Add(typeTopic);
                    type.SeeAlsos.Add(new NSeeAlso(topicLibrary));

                    // We don't process fields for enums
                    if (!(type is NEnum))
                    {
                        foreach (var member in type.Members)
                        {
                            var memberTopic = new NTopic(member) { Name = member.Name, AttachedClassNode = type };
                            member.TopicLink = memberTopic;
                            typeTopic.SubTopics.Add(memberTopic);

                            // Affect new Index based on previous topics
                            member.Index = index++;
                            member.SeeAlsos.Add(new NSeeAlso(topicLibrary));
                        }
                    }
                }
            }

            SearchTopic = NTopic.DefaultSearchResultsTopic;
            SearchTopic.Index = index++;

            // Add SearchTopic to the root topic
            RootTopic.SubTopics.Add(SearchTopic);

            // Associate each topic with its parent
            RootTopic.BuildParents();

            // Register root topics and all sub topics (excluding class library topics)
            Registry.Register(RootTopic);
        }