Ejemplo n.º 1
0
        /// <summary>
        /// Handles the bot conversation based on the users previously loaded dialogStrcuture, in JSON format
        /// </summary>
        public async Task HandleBotConversationsAsync(ITurnContext turnContext, CancellationToken cancellationToken, DialogLibAccessors accessors = null)
        {
            if (accessors != null)
            {
                // Get the topic state from the turn context.
                _topicState = await accessors?.TopicState?.GetAsync(turnContext, () => new TopicState());

                // Get the user profile (with feedback variables) from the turn context.
                _userProfile = await accessors?.UserProfile?.GetAsync(turnContext, () => new UserProfile());
            }

            if (turnContext.Activity.Type is ActivityTypes.Message)
            {
                await HandleTriggersAsync(turnContext, cancellationToken);
            }
            else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate &&
                     turnContext.Activity.MembersAdded.First().Name == "User")
            {
                await dialogMessageHandler.SendWelcomeMessageAsync(turnContext, cancellationToken);
            }

            if (accessors != null)
            {
                await accessors.TopicState.SetAsync(turnContext, _topicState);

                await accessors.ConversationState.SaveChangesAsync(turnContext);

                await accessors.UserProfile.SetAsync(turnContext, _userProfile);

                await accessors.UserState.SaveChangesAsync(turnContext);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 调整级别
        /// </summary>
        /// <param name="graphic">图对象</param>
        /// <param name="level">目标级别</param>
        public void SetLevel(GraphicViewModel graphic, TopicState level)
        {
            switch (level)
            {
            case TopicState.None:
                if (_observers.Remove(graphic))
                {
                    _subscribers.Remove(graphic);
                }
                break;

            case TopicState.Subscribed:
                if (!_subscribers.Remove(graphic))
                {
                    _observers.Add(graphic);
                }
                break;

            case TopicState.Active:
                if (_subscribers.Add(graphic))
                {
                    _observers.Add(graphic);
                }
                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method for updating state on a topic.
        /// </summary>
        /// <param name="topic">The topic to update.</param>
        /// <param name="newState">The new state of the topic.</param>
        /// <returns></returns>
        public Topic Update(Topic topic, TopicState newState)
        {
            if (topic == null)
            {
                throw new ArgumentNullException("topic");
            }
            this.logger.WriteFormat("Update called on TopicService, Id: {0}", topic.Id);
            // Let's get the topic from the data-storage!
            Topic oldTopic = this.Read(topic.Id);

            if (oldTopic == null)
            {
                this.logger.WriteFormat("Update topic failed, no topic with the given id was found, Id: {0}", topic.Id);
                throw new ArgumentException("topic does not exist");
            }

            Topic originalTopic = oldTopic.Clone() as Topic;

            // Has state changed?
            if (oldTopic.State != newState)
            {
                oldTopic.State = newState;

                oldTopic.Editor   = this.userProvider.CurrentUser;
                oldTopic.EditorId = this.userProvider.CurrentUser.Id;
                oldTopic.Changed  = DateTime.UtcNow;
                oldTopic          = this.topicRepo.Update(oldTopic);
                this.logger.WriteFormat("Topic updated in TopicService, Id: {0}", oldTopic.Id);
                this.eventPublisher.Publish <TopicStateUpdated>(new TopicStateUpdated(originalTopic)
                {
                    UpdatedTopic = oldTopic
                });
                this.logger.WriteFormat("Update events in TopicService fired, Id: {0}", oldTopic.Id);
            }
            return(oldTopic);
        }
Ejemplo n.º 4
0
 public virtual void ChangeState(TopicState newState)
 {
     this.ValidateEditorOrFail();
     this.State = newState;
 }
Ejemplo n.º 5
0
 public Topic(Forum forum, String subject, String content, TopicType type, TopicState state) : base(subject, content, null)
 {
     this.ForumId = forum.Id;
     this.Type    = type;
     this.State   = state;
 }
Ejemplo n.º 6
0
 private Topic Update(String authorId, String topicId, String subject, String text, TopicType type, TopicState state)
 {
     return(this.dataStore.UpdateTopic(authorId, topicId, subject, text, type, state));
 }
Ejemplo n.º 7
0
 public static SolidColorBrush Brushify(this TopicState state) =>
 state switch
 {
Ejemplo n.º 8
0
 public override void SetTopicsState(TopicState topicState)
 {
     _topicManager.SetTopicsState(topicState);
 }
Ejemplo n.º 9
0
        public Topic UpdateTopic(String userId, String topicId, String subject, String text, TopicType type, TopicState state)
        {
            Guid id;

            if (!Guid.TryParse(topicId, out id))
            {
                throw new ArgumentException(nameof(topicId));
            }
            Guid uId;

            if (!Guid.TryParse(userId, out uId))
            {
                throw new ArgumentException(nameof(userId));
            }
            if (String.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentNullException(nameof(subject));
            }
            Dbos.Topic topic = this.topicRepository.FindById(id);

            topic.Message.Subject  = subject;
            topic.Message.Text     = text;
            topic.Type             = type;
            topic.Message.Updated  = DateTime.UtcNow;
            topic.Message.EditorId = uId;
            topic.State            = state;

            topic = this.topicRepository.Update(topic);
            return(topic.ToModel());
        }
Ejemplo n.º 10
0
		/// <summary>
		/// Method for updating state on a topic.
		/// </summary>
		/// <param name="topic">The topic to update.</param>
		/// <param name="newState">The new state of the topic.</param>
		/// <returns></returns>
		public Topic Update(Topic topic, TopicState newState) {
			if (topic == null) {
				throw new ArgumentNullException("topic");
			}
			this.logger.WriteFormat("Update called on TopicService, Id: {0}", topic.Id);
			// Let's get the topic from the data-storage!
			Topic oldTopic = this.Read(topic.Id);
			if (oldTopic == null) {
				this.logger.WriteFormat("Update topic failed, no topic with the given id was found, Id: {0}", topic.Id);
				throw new ArgumentException("topic does not exist");
			}

			Topic originalTopic = oldTopic.Clone() as Topic;
			// Has state changed?
			if (oldTopic.State != newState) {
				oldTopic.State = newState;

				oldTopic.Editor = this.userProvider.CurrentUser;
				oldTopic.EditorId = this.userProvider.CurrentUser.Id;
				oldTopic.Changed = DateTime.UtcNow;
				oldTopic = this.topicRepo.Update(oldTopic);
				this.logger.WriteFormat("Topic updated in TopicService, Id: {0}", oldTopic.Id);
				this.eventPublisher.Publish<TopicStateUpdated>(new TopicStateUpdated(originalTopic) {
					UpdatedTopic = oldTopic
				});
				this.logger.WriteFormat("Update events in TopicService fired, Id: {0}", oldTopic.Id);
			}
			return oldTopic;
		}