コード例 #1
0
        protected override async Task TraceStateAsync(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var session = await FindSessionAsync(turnContext, cancellationToken).ConfigureAwait(false);

            if (session != null)
            {
                var task1 = _userState?.LoadAsync(turnContext, false, cancellationToken) ?? Task.CompletedTask;
                var task2 = _conversationState?.LoadAsync(turnContext, false, cancellationToken) ?? Task.CompletedTask;
                await Task.WhenAll(task1, task2).ConfigureAwait(false);

                var botState = new JObject();

                if (_userState != null)
                {
                    botState.Add("userState", _userState.Get(turnContext));
                }

                if (_conversationState != null)
                {
                    botState.Add("conversationState", _conversationState.Get(turnContext));
                }

                await InvokeSendAsync(turnContext, session, botState.TraceActivity(), cancellationToken).ConfigureAwait(false);
            }
        }
コード例 #2
0
 /// <summary>
 /// Gets a conversation state object from the turn context.
 /// </summary>
 /// <typeparam name="TState">The type of the state object to get.</typeparam>
 /// <param name="context">The context object for this turn.</param>
 /// <returns>The state object.</returns>
 public static TState GetConversationState <TState>(this ITurnContext context)
     where TState : class, new()
 {
     return(ConversationState <TState> .Get(context));
 }