Skip to content

Commit

Permalink
drop Accessors class
Browse files Browse the repository at this point in the history
  • Loading branch information
johnataylor committed Mar 12, 2019
1 parent 9d83955 commit 618f399
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 46 deletions.
19 changes: 6 additions & 13 deletions samples/csharp_dotnetcore/03.welcome-user/WelcomeUserBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
Expand Down Expand Up @@ -39,16 +38,12 @@ of the 'ConversationUpdate' event depends on the channel. You can
to user, explaining what your bot can do. In this example, the bot
handles 'hello', 'hi', 'help' and 'intro. Try it now, type 'hi'";

// The bot state accessor object. Use this to access specific state properties.
private WelcomeUserStateAccessors _welcomeUserStateAccessors;
private UserState _userState;
private BotState _userState;

// Initializes a new instance of the "WelcomeUserBot" class.
public WelcomeUserBot(UserState userState)
{
_userState = userState;
_welcomeUserStateAccessors = new WelcomeUserStateAccessors(userState);
_welcomeUserStateAccessors.WelcomeUserState = _userState.CreateProperty<WelcomeUserState>(WelcomeUserStateAccessors.WelcomeUserName);
}


Expand All @@ -72,16 +67,12 @@ protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersA

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
var didBotWelcomeUser = await _welcomeUserStateAccessors.WelcomeUserState.GetAsync(turnContext, () => new WelcomeUserState());

WelcomeUserState welcomeUserState = await _welcomeUserStateAccessors.WelcomeUserState.GetAsync(turnContext, () => new WelcomeUserState());
var welcomeUserStateAccessor = _userState.CreateProperty<WelcomeUserState>(nameof(WelcomeUserState));
var didBotWelcomeUser = await welcomeUserStateAccessor.GetAsync(turnContext, () => new WelcomeUserState());

if (didBotWelcomeUser.DidBotWelcomeUser == false)
{
didBotWelcomeUser.DidBotWelcomeUser = true;
// Update user state flag to reflect bot handled first user interaction.
await _welcomeUserStateAccessors.WelcomeUserState.SetAsync(turnContext, didBotWelcomeUser);
await _welcomeUserStateAccessors.UserState.SaveChangesAsync(turnContext);

// the channel should sends the user name in the 'From' object
var userName = turnContext.Activity.From.Name;
Expand All @@ -108,7 +99,9 @@ protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivi
break;
}
}
await _welcomeUserStateAccessors.UserState.SaveChangesAsync(turnContext);

// Save any state changes.
await _userState.SaveChangesAsync(turnContext);
}

private static async Task SendIntroCardAsync(ITurnContext turnContext, CancellationToken cancellationToken)
Expand Down

This file was deleted.

0 comments on commit 618f399

Please sign in to comment.