Esempio n. 1
0
 /// <summary>
 /// Finds the topic by id.
 /// </summary>
 /// <param name="topicId">The topic id.</param>
 /// <returns></returns>
 public NTopic FindTopicById(string topicId)
 {
     if (RootTopic == null)
     {
         return(null);
     }
     return(RootTopic.FindTopicById(topicId));
 }
Esempio n. 2
0
        public Task OnReceiveActivity(IBotContext context)
        {
            var rootTopic = new RootTopic(context);

            rootTopic.OnReceiveActivity(context);

            return(Task.CompletedTask);
        }
Esempio n. 3
0
        public Task OnReceiveActivity(IBotContext context)
        {
            if (context.Request.Type == ActivityTypes.Message)
            {
                var rootTopic = new RootTopic(context);
                rootTopic.Accessor = httpContextAccessor;
                rootTopic.OnReceiveActivity(context);
            }

            return(Task.CompletedTask);
        }
        protected override Task OnReceiveActivity(IBotContext context)
        {
            if (context.Request.Type == ActivityTypes.Message)
            {
                var rootTopic = new RootTopic(context);

                rootTopic.OnReceiveActivity(context);
            }

            return(Task.CompletedTask);
        }
Esempio n. 5
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}]. PageId 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);
        }
Esempio n. 6
0
        public Task OnTurn(ITurnContext turnContext)
        {
            var rootTopic = new RootTopic(turnContext);

            return(rootTopic.OnTurn(turnContext));
        }