Ejemplo 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 Bot Framework Adapter with error handling enabled.
            services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

            //var storage = new MemoryStorage();



            /* COSMOSDB STORAGE - Uncomment the code in this section to use CosmosDB storage */

            var cosmosDbStorageOptions = new CosmosDbPartitionedStorageOptions()
            {
                CosmosDbEndpoint = "https://365db.documents.azure.com:443/",
                AuthKey          = "wprejZdl9ybqxTdb3SxESe1C6qTfNjPqsOiCFwU4E4YM5qf4GxDSCP2UJ6aFZGiwC3lY5RTDrZpVpqYY3THmQQ==",
                DatabaseId       = "365db",
                ContainerId      = "365container"
            };

            var storage = new CosmosDbPartitionedStorage(cosmosDbStorageOptions);

            var userState = new UserState(storage);

            services.AddSingleton(userState);

            var conversationState = new ConversationState(storage);

            services.AddSingleton(conversationState);


            // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.AddTransient <IBot, StateBot>();
        }
Ejemplo 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_2);

            // The following line enables Application Insights telemetry collection.
            services.AddApplicationInsightsTelemetry(_config);

            // 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.)
            IStorage storage;

            /* COSMOSDB STORAGE - Uncomment the code in this section to use CosmosDB storage */
            var cosmosDBIsConfigured = !string.IsNullOrEmpty(_config["CosmosDBStateStoreEndpoint"]) && !string.IsNullOrEmpty(_config["CosmosDBStateStoreKey"]) && !string.IsNullOrEmpty(_config["CosmosDBStateStoreDatabaseId"]) && !string.IsNullOrEmpty(_config["CosmosDBStateStoreCollectionId"]);

            if (cosmosDBIsConfigured)
            {
                var cosmosDbStorageOptions = new CosmosDbPartitionedStorageOptions()
                {
                    CosmosDbEndpoint = _config["CosmosDBStateStoreEndpoint"],
                    AuthKey          = _config["CosmosDBStateStoreKey"],
                    DatabaseId       = _config["CosmosDBStateStoreDatabaseId"],
                    ContainerId      = _config["CosmosDBStateStoreCollectionId"]
                };
                storage = new CosmosDbPartitionedStorage(cosmosDbStorageOptions);
            }
            else
            {
                storage = new MemoryStorage();
                Console.WriteLine("CosmosDB Storage not used!");
            }

            /* END COSMOSDB STORAGE */

            // Create the User state passing in the storage layer.
            var userState = new UserState(storage);

            services.AddSingleton(userState);

            // Create the Conversation state passing in the storage layer.
            var conversationState = new ConversationState(storage);

            services.AddSingleton(conversationState);

            // Register LUIS recognizer
            services.AddSingleton <AddressRecognizer>();

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

            // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.AddTransient <IBot, DialogAndWelcomeBot <MainDialog> >();

            // Add Healthcheck module
            services.AddSingleton <Healthcheck>();
        }
Ejemplo 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);

            // Register credential provider
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            // Register the skills configuration class
            services.AddSingleton <SkillsConfiguration>();

            // Register AuthConfiguration to enable custom claim validation.
            services.AddSingleton(sp => new AuthenticationConfiguration {
                ClaimsValidator = new AllowedCallersClaimsValidator(sp.GetService <SkillsConfiguration>())
            });

            // Register the Bot Framework Adapter with error handling enabled.
            // Note: some classes use the base BotAdapter so we add an extra registration that pulls the same instance.
            services.AddSingleton <BotFrameworkHttpAdapter, AdapterWithErrorHandler>();
            services.AddSingleton <BotAdapter>(sp => sp.GetService <BotFrameworkHttpAdapter>());

            // Register the skills conversation ID factory, the client and the request handler.
            services.AddSingleton <SkillConversationIdFactoryBase, SkillConversationIdFactory>();
            services.AddHttpClient <SkillHttpClient>();
            services.AddSingleton <ChannelServiceHandler, SkillHandler>();

            // Register the storage we'll be using for User and Conversation state. (Memory is great for testing purposes.)
            var storageOptions = new CosmosDbPartitionedStorageOptions
            {
                CosmosDbEndpoint = Configuration.GetValue <string>("CosmosDbEndpoint"),
                AuthKey          = Configuration.GetValue <string>("CosmosDbAuthKey"),
                DatabaseId       = Configuration.GetValue <string>("CosmosDbDatabaseId"),
                ContainerId      = Configuration.GetValue <string>("CosmosDbContainerId")
            };

            services.AddSingleton <IStorage>(new CosmosDbPartitionedStorage(storageOptions));

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

            // Register the SkillDialog (remote skill).
            services.AddSingleton <SkillDialog>();

            // Register the MainDialog that will be run by the bot.
            services.AddSingleton <MainDialog>();

            // Register the bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.AddTransient <IBot, RootBot <MainDialog> >();
        }
Ejemplo n.º 4
0
        public static IStorage GetStorage(CosmosDbPartitionedStorageOptions options, int timeToLiveInSeconds = -1)
        {
            using (var client = new CosmosClient(
                       options.CosmosDbEndpoint,
                       options.AuthKey,
                       options.CosmosClientOptions ?? new CosmosClientOptions()))
            {
                var containerResponse = (client
                                         .CreateDatabaseIfNotExistsAsync(options.DatabaseId).GetAwaiter().GetResult())
                                        .Database
                                        .DefineContainer(options.ContainerId, "/id")
                                        .WithDefaultTimeToLive(timeToLiveInSeconds)
                                        .WithIndexingPolicy().WithAutomaticIndexing(false).Attach()
                                        .CreateIfNotExistsAsync(options.ContainerThroughput)
                                        .ConfigureAwait(false).GetAwaiter().GetResult();
            }

            return(new CosmosDbPartitionedStorage(options));
        }
Ejemplo n.º 5
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>();

            var cosmosDbStorageOptions = new CosmosDbPartitionedStorageOptions()
            {
                CosmosDbEndpoint = "https://electioncosmos.documents.azure.com:443/",
                AuthKey          = "0zqSGejOcM7dqU603OFedsrfXf3HG6DBrwO0YZm85h2IlZrdyDY7la7tgfX0axd9ccNN4myrphorQMlxOuuBSw==",
                DatabaseId       = "BotStoage",
                ContainerId      = "Group4"
            };
            var storage = new CosmosDbPartitionedStorage(cosmosDbStorageOptions);

            services.AddSingleton <IStorage>(new CosmosDbPartitionedStorage(cosmosDbStorageOptions));

            // 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>();

            // Register LUIS recognizer
            services.AddSingleton <ConversationRecognizer>();

            // The MainDialog that will be run by the bot.
            services.AddSingleton <MainDialog>();
            services.AddSingleton <ElectionDialog>();
            services.AddSingleton <IssuesDialog>();
            services.AddSingleton <ConstituencyDialog>();
            services.AddSingleton <EndConversationDialog>();
            services.AddSingleton <PartyDialog>();
            services.AddSingleton <UserProfileDialog>();

            // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.AddTransient <IBot, DialogAndWelcomeBot <MainDialog> >();
        }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddNewtonsoftJson();

            // Create a global service for our ConversationReferences
            services.AddSingleton <TimeoutConversationService>();

            // 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.
            var options = new CosmosDbPartitionedStorageOptions()
            {
                AuthKey           = Configuration["CosmosKey"],
                ContainerId       = Configuration["ComosDbStateContainer"],
                CosmosDbEndpoint  = Configuration["CosmosUri"],
                DatabaseId        = Configuration["CosmosDb"],
                CompatibilityMode = false,
            };

            // NOTE: set timeToLiveInSeconds parameter to enable dynamically creating
            // the container with default TTL
            services.AddSingleton <IStorage>(CosmosDbStorageInitializer.GetStorage(options));

            // 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 <UserProfileDialog>();

            // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.AddTransient <IBot, DialogBot <UserProfileDialog> >();
        }