Esempio n. 1
0
        /// <summary>
        /// 通过话题获取话题控制器
        /// </summary>
        /// <param name="topic">话题</param>
        /// <returns>话题控制器</returns>
        public async Task<TopicController> GetTopicController(Topic topic)
        {
            if (topic == null)
            {
                return null;
            }

            //获取或创建控制器
            TopicController topicController;
            if (topicControllerDictionary.TryGetValue(topic.Name, out topicController) == false)
            {
                client.SubscribeTopic(topic);
                topicController = new TopicController(db);
                await topicController.SetTopic(topic);
                topicControllerDictionary.TryAdd(topic.Name, topicController);
            }

            return topicController;
        }
Esempio n. 2
0
        /// <summary>
        /// 通过话题名获取话题控制器
        /// </summary>
        /// <param name="name">话题名</param>
        /// <returns>话题控制器</returns>
        public async Task<TopicController> GetTopicControllerByName(string name)
        {
            int index = instance.TopicList.IndexOf(new Topic(name));
            if (index == -1)
            {
                return null;
            }
            
            //获取或创建控制器
            TopicController topicController;
            if (topicControllerDictionary.TryGetValue(name, out topicController) == false)
            {
                client.SubscribeTopic(instance.TopicList[index]);
                topicController = new TopicController(db);
                await topicController.SetTopic(instance.TopicList[index]);
                topicControllerDictionary.TryAdd(name, topicController);
            }

            return topicController;
        }