/* * コンストラクタ * 引数として指定したMyStateAccessorsはDIとして自動解決される(意味不 * DIとは * IoCコンテナという場所に登録した情報を元に、必要なオブジェクトを動的に取り出す仕組みのこと * ASP.NET Coreでは標準でこの機能が提供されている * //*/ public MyBot(MyStateAccessors accessors) { this.accessors = accessors; this.dialogs = new DialogSet(accessors.ConversationDialogState); /* * /* * ウォーターフォールのステップを定義 * 処理準にメソッドを追加 * (メソッドは下のほうに定義している) * /// * var waterfallSteps = new WaterfallStep[] * { * NameStepAsync, * NameConfirmStepAsync, * AgeStepAsync, * ConfirmStepAsync, * SummaryStepAsync * }; * * //ウォーターフォールダイアログを追加 * dialogs.Add(new WaterfallDialog("profile", waterfallSteps)); * //テキスト型のプロンプトとしてid=nameで作成(意味不 * dialogs.Add(new TextPrompt("name")); * //数値型のプロンプトとしてid=ageで作成 * dialogs.Add(new NumberPrompt<int>("age")); * // * dialogs.Add(new ConfirmPrompt("confirm")); * * //*/ //コンポーネントダイアログを追加 dialogs.Add(new ProfileDialog(accessors)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { /* * services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); * //*/ services.AddBot <MyBot>(options => { //ログ出力ミドルウェア options.Middleware.Add(new MyLoggingMiddleware()); //添付ファイル拒否ミドルウェア options.Middleware.Add(new MyMiddleware()); ///* //ストレージとしてインメモリを利用 IStorage dataStore = new MemoryStorage(); //それぞれのステートを作成 var userState = new UserState(dataStore); var conversationState = new ConversationState(dataStore); options.State.Add(userState); options.State.Add(conversationState); //*/ }); //MyStateAccessorをIoC(Inversion of Control)に登録 // IoCというコンテナがあるらしい(謎 services.AddSingleton(sp => { // AddBotで登録したoptionsを取得 var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value; if (options == null) { throw new InvalidOperationException("BotFrameworkOptionsを事前に構成してください。"); } var userState = options.State.OfType <UserState>().FirstOrDefault(); if (userState == null) { throw new InvalidOperationException("UserStateを事前に定義してください。"); } var conversationState = options.State.OfType <ConversationState>().FirstOrDefault(); if (conversationState == null) { throw new InvalidOperationException("ConversationStateを事前に定義してください。"); } var accessors = new MyStateAccessors(userState, conversationState) { //DialogStateをConversationStateのプロパティとして設定(意味不 ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"), UserProfile = userState.CreateProperty <UserProfile>("UserProfile") }; return(accessors); }); //services.AddBot<MyBot>(); }
public ProfileDialog(MyStateAccessors accessors) : base(nameof(ProfileDialog)) { this.accessors = accessors ?? throw new System.ArgumentNullException(nameof(accessors)); var waterfallSteps = new WaterfallStep[] { NameStepAsync, NameConfirmStepAsync, AgeStepAsync, ConfirmStepAsync, SummaryStepAsync, }; AddDialog(new WaterfallDialog("profile", waterfallSteps)); AddDialog(new TextPrompt("name")); AddDialog(new NumberPrompt <int>("age")); AddDialog(new ConfirmPrompt("confirm")); }
public ProfileDialog(MyStateAccessors accessors) : base(nameof(ProfileDialog)) { this.accessors = accessors; // ウォーターフォールのステップを定義。処理順にメソッドを追加。 var waterfallSteps = new WaterfallStep[] { NameStepAsync, NameConfirmStepAsync, AgeStepAsync, ConfirmStepAsync, SummaryStepAsync, }; // ウォーターフォールダイアログと各種プロンプトを追加 AddDialog(new WaterfallDialog("profile", waterfallSteps)); AddDialog(new TextPrompt("name")); AddDialog(new NumberPrompt <int>("age")); AddDialog(new ConfirmPrompt("confirm")); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddBot <MyBot>(options => { options.Middleware.Add(new MyLoggingMiddleware()); options.Middleware.Add(new MyMiddleware()); IStorage dataStore = new MemoryStorage(); var userState = new UserState(dataStore); var conversationState = new ConversationState(dataStore); options.State.Add(userState); options.State.Add(conversationState); }); services.AddSingleton(sp => { var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value; if (options == null) { throw new InvalidOperationException("BotFrameworkOptions を事前に構成してください。"); } var userState = options.State.OfType <UserState>().FirstOrDefault(); if (userState == null) { throw new InvalidOperationException("UserState を事前に定義してください。"); } var conversationState = options.State.OfType <ConversationState>().FirstOrDefault(); if (conversationState == null) { throw new InvalidOperationException("ConversationState を事前に定義してください。"); } var accessors = new MyStateAccessors(userState, conversationState) { ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"), UserProfile = userState.CreateProperty <UserProfile>("UserProfile"), }; return(accessors); }); }
public MyBot(MyStateAccessors accessors) { this.accessors = accessors; this.dialogs = new DialogSet(accessors.ConversationDialogState); dialogs.Add(new ProfileDialog(accessors)); }