protected void Application_Start()
        {
            new Task(async() =>
            {
                await DocumentDBRepository.Initialize();
                await AnnouncementScheduler.InitializeSchedulesFromDB();
            }).Start();


            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            Conversation.UpdateContainer(
                builder =>
            {
                builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));

                // Using Azure Table Storage
                var store = new TableBotDataStore(ConfigurationManager.AppSettings["AzureWebJobsStorage"]); // requires Microsoft.BotBuilder.Azure Nuget package

                // To use CosmosDb or InMemory storage instead of the default table storage, uncomment the corresponding line below
                // var store = new DocumentDbBotDataStore("cosmos db uri", "cosmos db key"); // requires Microsoft.BotBuilder.Azure Nuget package
                // var store = new InMemoryDataStore(); // volatile in-memory store

                builder.Register(c => store)
                .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore)
                .AsSelf()
                .SingleInstance();
            });
        }
コード例 #2
0
        public async Task <ActionResult> CleanDatabase()
        {
            var authRequestHeader = Request.Headers["AuthKey"];

            if (!string.IsNullOrEmpty(authRequestHeader) && ConfigurationManager.AppSettings["AuthKey"] == authRequestHeader)
            {
                // Clean up Schedules
                await AnnouncementScheduler.CleanUpOldSchedules();

                // Cleanup up database
                await DocumentDBRepository.CleanUpAsync();

                // Cleanup cached.
                Cache.Clear();
                // Delete profile photos
                var baseDirectory = System.Web.Hosting.HostingEnvironment.MapPath($"~/ProfilePhotos/");
                if (System.IO.Directory.Exists(baseDirectory))
                {
                    // Delete directory and then create it.
                    System.IO.Directory.Delete(baseDirectory, true);
                    System.IO.Directory.CreateDirectory(baseDirectory);
                }

                // Cleanup TableStorage
                var storageAccountConnectionString = ConfigurationManager.AppSettings["AzureWebJobsStorage"];
                var storageAccount = CloudStorageAccount.Parse(storageAccountConnectionString);
                var tableClient    = storageAccount.CreateCloudTableClient();
                var table          = tableClient.GetTableReference("botdata");
                await table.DeleteIfExistsAsync();

                // Recreate DB Collection
                await DocumentDBRepository.Initialize();
                await SafeCreateIfNotExists(table);

                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.OK));
            }
            else
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Forbidden, "Auth key does not match."));
            }
        }