示例#1
0
        /// <summary>
        /// 通过订阅者位置移除订阅者
        /// </summary>
        /// <param name="position">订阅者位置</param>
        /// <returns>结果</returns>
        public async Task<bool> RemoveSubsriberAt(int position)
        {
            if (position < 0 || position > instance.SubscriberList.Count)
            {
                return false;
            }

            Subscriber subscriber = instance.SubscriberList[position];
            Topic removedTopic = GetTopicByName(subscriber.TopicName);

            //订阅者列表更新
            instance.SubscriberList.Remove(subscriber);

            //数据库更新
            SubscriberController subscriberController = new SubscriberController(db.Subscribers);
            subscriberController.SetSubscriber(subscriber);
            subscriberController.DeleteSubscriber();

            //话题列表更新
            instance.TopicList.Remove(removedTopic);

            //数据库更新
            TopicController topicController = await GetTopicController(removedTopic);
            topicController.DeleteTopic();

            //向服务器请求删除订阅者
            client.RemoveSubscriber(subscriber);

            //移除成功返回真
            return true;
        }
示例#2
0
        /// <summary>
        /// 移除订阅者
        /// </summary>
        /// <param name="subscriber">订阅者对象</param>
        /// <returns>结果</returns>
        public async Task<bool> RemoveSubscriber(Subscriber subscriber)
        {
            //判断订阅者是否位于订阅者列表中
            if (!instance.SubscriberList.Contains(subscriber))
            {
                return false;
            }

            Topic removedTopic = GetTopicByName(subscriber.TopicName);

            //订阅者列表更新
            instance.SubscriberList.Remove(subscriber);

            //数据库更新
            SubscriberController subscriberController = new SubscriberController(db.Subscribers);
            subscriberController.SetSubscriber(subscriber);
            subscriberController.DeleteSubscriber();

            //话题列表更新
            instance.TopicList.Remove(removedTopic);

            //数据库更新
            TopicController topicController = await GetTopicController(removedTopic);
            topicController.DeleteTopic();

            //向服务器请求删除订阅者
            client.RemoveSubscriber(subscriber);

            return true;
        }
示例#3
0
        /// <summary>
        /// 增加订阅者(群组话题使用)
        /// </summary>
        /// <param name="subsricber">订阅者对象</param>
        /// <returns>结果</returns>
        public async Task <bool> AddSubscriber(Subscriber subscriber)
        {
            //判断订阅者是否位于订阅者列表中
            if (instance.SubsriberList.Contains(subscriber))
            {
                //重复添加返回假
                return(false);
            }
            subscriber.TopicName = instance.Name;
            instance.SubsriberList.Add(subscriber);

            //调用订阅者控制器更新订阅者
            SubscriberController subscriberController = new SubscriberController(db.Subscribers);

            subscriberController.SetSubscriber(subscriber);
            subscriberController.UpsertSubscriber();

            //更新话题时间戳
            instance.LastUsed = ChatMessageBuilder.GetTimeStamp();
            var dbContext = db.Topics.GetRepository();
            await dbContext.UpsertTopic(instance);

            //添加成功返回真
            return(true);
        }
示例#4
0
        /// <summary>
        /// 通过订阅者获取订阅者控制器
        /// </summary>
        /// <param name="subscriber">订阅者</param>
        /// <returns>订阅者控制器</returns>
        public SubscriberController GetSubscriberController(Subscriber subscriber)
        {
            if (subscriber == null)
            {
                return null;
            }

            SubscriberController subscriberController = new SubscriberController(db.Subscribers);
            subscriberController.SetSubscriber(subscriber);
            return subscriberController;
        }
示例#5
0
        /// <summary>
        /// 新增订阅者
        /// </summary>
        /// <param name="subscriber">订阅者对象</param>
        /// <param name="isTemporary">是否临时保存</param>
        /// <returns>结果</returns>
        public async Task<bool> AddSubscriber(Subscriber subscriber, bool isTemporary = false)
        {
            //判断是否为有效订阅者
            if (instance.SubscriberList.Contains(subscriber) || subscriber.TopicName == "fnd" || subscriber.TopicName == "me")
            {
                //无效订阅者返回假
                return false;
            }

            //判断是否为临时查询
            if (isTemporary == true)
            {
                if (searchSubscriberResult.Contains(subscriber))
                {
                    return false;
                }
                searchSubscriberResult.Add(subscriber);
                return true;
            }

            //获取已存在话题或创建话题
            Topic newTopic = GetTopicByName(subscriber.TopicName);
            if (newTopic == null)
            {
                newTopic = new Topic(subscriber.TopicName);
            }

            if (newTopic == null)
            {
                newTopic = new Topic(subscriber.TopicName);
            }

            //话题列表更新
            await AddTopic(newTopic);

            //数据库更新
            TopicController topicController = await GetTopicController(newTopic);
            topicController.UpsertTopic();

            //订阅者列表更新
            instance.SubscriberList.Add(subscriber);

            //数据库更新
            SubscriberController subscriberController = new SubscriberController(db.Subscribers);
            subscriberController.SetSubscriber(subscriber);
            subscriberController.UpsertSubscriber();

            //服务器更新
            client.SubscribeTopic(newTopic);
            return true;
        }
示例#6
0
        /// <summary>
        /// 移除订阅者(群组话题使用)
        /// </summary>
        /// <param name="subscriber">订阅者对象</param>
        /// <returns>结果</returns>
        public async Task <bool> RemoveSubscriber(Subscriber subscriber)
        {
            //判断订阅者是否位于订阅者列表中
            if (!instance.SubsriberList.Contains(subscriber))
            {
                //订阅者不存在返回假
                return(false);
            }
            instance.SubsriberList.Remove(subscriber);

            //调用订阅者控制器删除订阅者
            SubscriberController subscriberController = new SubscriberController(db.Subscribers);

            subscriberController.SetSubscriber(subscriber);
            subscriberController.DeleteSubscriber();

            //更新话题时间戳
            instance.LastUsed = ChatMessageBuilder.GetTimeStamp();
            var dbContext = db.Topics.GetRepository();
            await dbContext.UpsertTopic(instance);

            //删除成功返回真
            return(true);
        }