Exemplo n.º 1
0
        // 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);

            // Create the credential provider to be used with the Bot Framework Adapter.
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            // Create the Bot Framework Adapter with error handling enabled.
            services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

            // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
            services.AddSingleton <IStorage, MemoryStorage>();

            // Create the User state. (Used in this bot's Dialog implementation.)
            services.AddSingleton <UserState>();

            // Create the Conversation state. (Used by the Dialog system itself.)
            services.AddSingleton <ConversationState>();

            // The Dialog that will be run by the bot.
            services.AddSingleton <RootDialog>();

            // Resource explorer helps load all .lg files for this project.
            var resourceExplorer = ResourceExplorer.LoadProject(Directory.GetCurrentDirectory(), ignoreFolders: new string[] { "models" });

            services.AddSingleton(resourceExplorer);

            // Create the bot. the ASP Controller is expecting an IBot.
            services.AddSingleton <IBot, DialogAndWelcomeBot <RootDialog> >();
        }
Exemplo n.º 2
0
        // 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);

            // Create the credential provider to be used with the Bot Framework Adapter.
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            // Create the Bot Framework Adapter with error handling enabled.
            services.AddSingleton <IBotFrameworkHttpAdapter, AdaptiveBotHttpAdapter>();

            // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
            services.AddSingleton <IStorage, MemoryStorage>();

            // Create the User state. (Used in this bot's Dialog implementation.)
            services.AddSingleton <UserState>();

            // Create the Conversation state. (Used by the Dialog system itself.)
            services.AddSingleton <ConversationState>();

            var resourceExplorer = ResourceExplorer.LoadProject(this.HostingEnvironment.ContentRootPath);

            services.AddSingleton(resourceExplorer);

            // Create the bot  In this case the ASP Controller is expecting an IBot.
            services.AddSingleton <IBot, AdaptiveBot>();
        }
Exemplo n.º 3
0
    // 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);

        // Create the Bot Framework Adapter with error handling enabled.
        services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

        // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
        services.AddSingleton <IStorage, MemoryStorage>();

        // Create the User state. (Used in this bot's Dialog implementation.)
        services.AddSingleton <UserState>();

        // Create the Conversation state. (Used by the Dialog system itself.)
        services.AddSingleton <ConversationState>();

        var resourceExplorer = ResourceExplorer.LoadProject(this.HostingEnvironment.ContentRootPath);

        services.AddSingleton(resourceExplorer);

        // The Dialog that will be run by the bot.
        services.AddSingleton <RootDialog>();

        // Add this so settings memory scope is populated correctly.
        services.AddSingleton <IConfiguration>(this.Configuration);

        // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
        services.AddTransient <IBot, DialogBot <RootDialog> >();
    }
 public static void ClassInitialize(TestContext context)
 {
     TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
     DeclarativeTypeLoader.AddComponent(new AdaptiveComponentRegistration());
     DeclarativeTypeLoader.AddComponent(new LanguageGenerationComponentRegistration());
     resourceExplorer = ResourceExplorer.LoadProject(GetProjectFolder());
 }
Exemplo n.º 5
0
        public MainDialog(ILogger <MainDialog> logger)
            : base(nameof(MainDialog))
        {
            _logger = logger;

            // combine path for cross platform support
            string[] paths            = { ".", "Resources", "MainDialog.LG" };
            string   mainDialogLGFile = Path.Combine(paths);

            paths = new string[] { ".", "Resources", "Cards.LG" };
            string cardsLGFile = Path.Combine(paths);

            string[] lgFiles = { mainDialogLGFile, cardsLGFile };

            // For simple LG resolution, we will call the TemplateEngine directly.
            _lgEngine = TemplateEngine.FromFiles(lgFiles);

            // Resource explorer helps load all .lg files for this project.
            // TextMessageActivityGenerator is used to transform chatdown style cards into full blown activity.
            var resourceExplorer = ResourceExplorer.LoadProject(Directory.GetCurrentDirectory(), ignoreFolders: new string[] { "models" });

            _activityGenerator = new TextMessageActivityGenerator(new LGLanguageGenerator(resourceExplorer));

            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
            AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
            {
                ChoiceCardStepAsync,
                ShowCardStepAsync,
            }));

            // The initial child Dialog to run.
            InitialDialogId = nameof(WaterfallDialog);
        }
        public static void ClassInitialize(TestContext context)
        {
            TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
            DeclarativeTypeLoader.AddComponent(new AdaptiveComponentRegistration());
            DeclarativeTypeLoader.AddComponent(new LanguageGenerationComponentRegistration());
            DeclarativeTypeLoader.AddComponent(new QnAMakerComponentRegistration());
            TypeFactory.Register("Microsoft.RuleRecognizer", typeof(RuleRecognizer));
            string projPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, PathUtils.NormalizePath($@"..\..\..\..\..\tests\Microsoft.Bot.Builder.TestBot.Json\Microsoft.Bot.Builder.TestBot.Json.csproj")));

            resourceExplorer = ResourceExplorer.LoadProject(projPath);
        }
        public AdapterWithErrorHandler(ICredentialProvider credentialProvider, ILogger <BotFrameworkHttpAdapter> logger, ConversationState conversationState = null)
            : base(credentialProvider)
        {
            // combine path for cross platform support
            string[] paths    = { ".", "Resources", "AdapterWithErrorHandler.LG" };
            string   fullPath = Path.Combine(paths);

            _lgEngine = TemplateEngine.FromFiles(fullPath);

            // manage all bot resources
            var resourceExplorer = ResourceExplorer
                                   .LoadProject(Directory.GetCurrentDirectory(), ignoreFolders: new string[] { "models" });

            //resourceExplorer.AddFolder(luisModelsFolder);

            var lg = new LGLanguageGenerator(resourceExplorer);

            Use(new RegisterClassMiddleware <ILanguageGenerator>(lg));
            Use(new RegisterClassMiddleware <IMessageActivityGenerator>(new TextMessageActivityGenerator(lg)));


            OnTurnError = async(turnContext, exception) =>
            {
                // Log any leaked exception from the application.
                logger.LogError($"Exception caught : {exception.Message}");

                // Send a catch-all apology to the user.
                await turnContext.SendActivityAsync(_lgEngine.EvaluateTemplate("SomethingWentWrong", null));

                if (conversationState != null)
                {
                    try
                    {
                        // Delete the conversationState for the current conversation to prevent the
                        // bot from getting stuck in a error-loop caused by being in a bad state.
                        // ConversationState should be thought of as similar to "cookie-state" in a Web pages.
                        await conversationState.DeleteAsync(turnContext);
                    }
                    catch (Exception e)
                    {
                        logger.LogError($"Exception caught on attempting to Delete ConversationState : {e.Message}");
                    }
                }
            };
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            // Create the credential provider to be used with the Bot Framework Adapter.
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            // Create the Bot Framework Adapter with error handling enabled.
            services.AddSingleton <IBotFrameworkHttpAdapter, AdaptiveBotAdapter>();

            // Create the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
            services.AddSingleton <IStorage, MemoryStorage>();

            // Create the User state. (Used in this bot's Dialog implementation.)
            services.AddSingleton <UserState>();

            // Create the Conversation state. (Used by the Dialog system itself.)
            services.AddSingleton <ConversationState>();

            var resourceExplorer = ResourceExplorer.LoadProject(this.HostingEnvironment.ContentRootPath);

            services.AddSingleton(resourceExplorer);

            // Create the bot  In this case the ASP Controller is expecting an IBot.
            services.AddSingleton <IBot, AdaptiveBot>();

            // Add this so settings memory scope is populated correctly.
            services.AddSingleton <IConfiguration>(this.Configuration);

            //services.AddSingleton<IAlexaHttpAdapter>(new AlexaHttpAdapter(false));
            services.Configure <KestrelServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });
        }
Exemplo n.º 9
0
 public static void ClassInitialize(TestContext context)
 {
     ResourceExplorer = new ResourceExplorer();
     ResourceExplorer.LoadProject(Path.Combine(GetProjectPath(), "Iciclecreek.AdaptiveExpressions.Tests.csproj"));
     PythonFunctions.AddPythonFunctions(ResourceExplorer);
 }