// 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 the Bot Framework Adapter with error handling enabled. services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); BlobsStorage storage = new BlobsStorage($"DefaultEndpointsProtocol=https;AccountName=ddkstorageaccount01;AccountKey={new getmysecret().KeyVaultsecretName("StorageBlobKey").ToString()};EndpointSuffix=core.windows.net", "ddkcontainer01"); // Create the bot services (LUIS, QnA) as a singleton. services.AddSingleton <IBotServices, BotServices>(); // 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); // The Dialog that will be run by the bot. services.AddSingleton <UserProfileDialog>(); // Create the bot as a transient. services.AddTransient <IBot, DispatchBot>(); }
/// <summary> /// Deletes a streams associated with an entity /// </summary> /// <param name="entity">Entity to delete streams from</param> /// <param name="operationContext">Gives the operation context</param> public virtual void DeleteStream(object entity, DataServiceOperationContext operationContext) { ExceptionUtilities.CheckArgumentNotNull(entity, "entity"); this.CheckOperationContext(operationContext); // this will remove named streams as well BlobsStorage.Remove(entity); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var storage = new BlobsStorage( Configuration.GetSection("StorageConnectionString").Value, Configuration.GetSection("StorageContainer").Value ); var userState = new UserState(storage); services.AddSingleton(userState); var conversationState = new ConversationState(storage); services.AddSingleton(conversationState); services.AddControllers().AddNewtonsoftJson(); string stringConnection = Configuration.GetConnectionString("Azure"); services.AddDbContext <BOTTGIngSoft2021Context>(options => options.UseSqlServer(stringConnection)); services.AddScoped(typeof(IRepository <>), typeof(Repository <>)); services.AddScoped(typeof(IRepositoryIntent), typeof(RepositoryIntent)); services.AddTransient <IIntentService, IntentService>(); services.AddTransient <IUsersBotService, UsersBotService>(); // Create the Bot Framework Adapter with error handling enabled. services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); services.AddSingleton <ILuisService, LuisService>(); services.AddTransient <RootDialog>(); services.AddTransient <IBot, BotTGIngSoft2021 <RootDialog> >(); }
// 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 the Bot Framework Adapter with error handling enabled. services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); var storageString = Configuration["StorageString"]; var storage = new BlobsStorage(storageString, "batonbotstorage"); var userState = new UserState(storage); services.AddSingleton(userState); // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. services.AddTransient <IBot, DevBot>(); services.AddSingleton <ICardCreator, CardCreator>(); services.AddSingleton <IFirebaseService, FirebaseService>(); services.AddSingleton <IBatonService, BatonService>(); services.AddSingleton <IGitHubService, GitHubService>(); services.AddSingleton <IFirebaseLogger, FirebaseLogger>(); services.AddSingleton <IRepositoryMapper, RepositoryMapper>(); services.AddSingleton <ICommandHandler, CommandHandler>(); services.AddSingleton <IShowCommandHandler, ShowCommandHandler>(); services.AddSingleton <ITakeCommandHandler, TakeCommandHandler>(); services.AddSingleton <IReleaseCommandHandler, ReleaseCommandHandler>(); services.AddSingleton <IGithubUpdateHandler, UpdateGithubHandler>(); services.AddSingleton <IGithubMergeHandler, MergeGithubHandler>(); services.AddSingleton <IWithinReleaseService, WithinReleaseService>(); services.AddSingleton <ICloseTicketCommandHandler, CloseTicketCommandHandler>(); services.AddSingleton <ITryAgainCommandHandler, TryAgainCommandHandler>(); services.AddSingleton <IToughDayCommandHandler, ToughDayCommandHandler>(); services.AddSingleton <ITokenCommandHandler, TokenCommandHandler>(); }
// 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 the Bot Framework Adapter with error handling enabled. services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); services.AddSingleton <IStorage, BlobsStorage>(sp => { // The Memory Storage used here is for local bot debugging only. When the bot // is restarted, everything stored in memory will be gone. //IStorage dataStore = new MemoryStorage(); //var blobConnectionString = Configuration.GetSection("BlobStorageConnectionString")?.Value; //var blobContainer = Configuration.GetSection("BlobStorageContainer")?.Value; //IStorage dataStore = new BlobsStorage(blobConnectionString, blobContainer); //services.AddSingleton<IStorage>(dataStore); // For production bots use the Azure Blob or // Azure CosmosDB storage providers. For the Azure // based storage providers, add the Microsoft.Bot.Builder.Azure // Nuget package to your solution. That package is found at: // https://www.nuget.org/packages/Microsoft.Bot.Builder.Azure/ // Uncomment the following lines to use Azure Blob Storage // //Storage configuration name or ID from the .bot file. // const string StorageConfigurationId = "<STORAGE-NAME-OR-ID-FROM-BOT-FILE>"; // var blobConfig = botConfig.FindServiceByNameOrId(StorageConfigurationId); // if (!(blobConfig is BlobStorageService blobStorageConfig)) // { // throw new InvalidOperationException($"The .bot file does not contain an blob storage with name '{StorageConfigurationId}'."); // } // // Default container name. // const string DefaultBotContainer = "botstate"; // var storageContainer = string.IsNullOrWhiteSpace(blobStorageConfig.Container) ? DefaultBotContainer : blobStorageConfig.Container; // IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureBlobStorage(blobStorageConfig.ConnectionString, storageContainer); var blobConnectionString = Configuration.GetSection("BlobStorageConnectionString")?.Value; var blobContainer = Configuration.GetSection("BlobStorageContainer")?.Value; BlobsStorage dataStore = new BlobsStorage(blobConnectionString, blobContainer); return(dataStore); }); // Create the User state. services.AddSingleton <UserState>(sp => { var dataStore = sp.GetRequiredService <IStorage>(); return(new UserState(dataStore)); }); // Create the Conversation state. services.AddSingleton <ConversationState>(sp => { var dataStore = sp.GetRequiredService <IStorage>(); return(new ConversationState(dataStore)); }); services.AddBot <PictureBot.Bots.PictureBot>(options => { var appId = Configuration.GetSection("MicrosoftAppId")?.Value; var appSecret = Configuration.GetSection("MicrosoftAppPassword")?.Value; options.CredentialProvider = new SimpleCredentialProvider(appId, appSecret); // Creates a logger for the application to use. ILogger logger = _loggerFactory.CreateLogger <PictureBot.Bots.PictureBot>(); // Catches any errors that occur during a conversation turn and logs them. options.OnTurnError = async(context, exception) => { logger.LogError($"Exception caught : {exception}"); await context.SendActivityAsync("Sorry, it looks like something went wrong."); }; options.Middleware.Add(new RegExpRecognizerMiddleware() .AddIntent("search", new Regex("search picture(?:s)*(.*)|search pic(?:s)*(.*)", RegexOptions.IgnoreCase)) .AddIntent("share", new Regex("share picture(?:s)*(.*)|share pic(?:s)*(.*)", RegexOptions.IgnoreCase)) .AddIntent("order", new Regex("order picture(?:s)*(.*)|order print(?:s)*(.*)|order pic(?:s)*(.*)", RegexOptions.IgnoreCase)) .AddIntent("help", new Regex("help(.*)", RegexOptions.IgnoreCase))); }); // Create and register state accesssors. // Acessors created here are passed into the IBot-derived class on every turn. services.AddSingleton <PictureBotAccessors>(sp => { var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value; if (options == null) { throw new InvalidOperationException("BotFrameworkOptions must be configured prior to setting up the state accessors"); } var conversationState = sp.GetRequiredService <ConversationState>(); //var conversationState = services.BuildServiceProvider().GetService<ConversationState>(); if (conversationState == null) { throw new InvalidOperationException("ConversationState must be defined and added before adding conversation-scoped state accessors."); } // Create the custom state accessor. // State accessors enable other components to read and write individual properties of state. return(new PictureBotAccessors(conversationState) { PictureState = conversationState.CreateProperty <PictureState>(PictureBotAccessors.PictureStateName), DialogStateAccessor = conversationState.CreateProperty <DialogState>("DialogState"), }); }); // Create and register a LUIS recognizer. services.AddSingleton(sp => { var luisApplication = new LuisApplication( Configuration.GetSection("luisAppId")?.Value, Configuration.GetSection("luisAppKey")?.Value, Configuration.GetSection("luisEndPoint")?.Value); // Set the recognizer options depending on which endpoint version you want to use. // More details can be found in https://docs.microsoft.com/en-gb/azure/cognitive-services/luis/luis-migration-api-v3 var recognizerOptions = new LuisRecognizerOptionsV3(luisApplication) { PredictionOptions = new Microsoft.Bot.Builder.AI.LuisV3.LuisPredictionOptions { IncludeAllIntents = true, } }; return(new LuisRecognizer(recognizerOptions)); }); services.AddSingleton <TextAnalyticsClient>(sp => { Uri cogsBaseUrl = new Uri(Configuration.GetSection("cogsBaseUrl")?.Value); string cogsKey = Configuration.GetSection("cogsKey")?.Value; var credentials = new AzureKeyCredential(cogsKey); return(new TextAnalyticsClient(cogsBaseUrl, credentials)); }); }
// 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 the Bot Framework Adapter with error handling enabled. services.AddSingleton <PictureBotAccessors>(sp => { var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value; if (options == null) { throw new InvalidOperationException("BotFrameworkOptions must be configured prior to setting up the state accessors"); } var conversationState = sp.GetRequiredService <ConversationState>(); //var conversationState = services.BuildServiceProvider().GetService<ConversationState>(); if (conversationState == null) { throw new InvalidOperationException("ConversationState must be defined and added before adding conversation-scoped state accessors."); } // Create the custom state accessor. // State accessors enable other components to read and write individual properties of state. return(new PictureBotAccessors(conversationState) { PictureState = conversationState.CreateProperty <PictureState>(PictureBotAccessors.PictureStateName), DialogStateAccessor = conversationState.CreateProperty <DialogState>("DialogState"), }); }); services.AddSingleton(sp => { var luisApplication = new LuisApplication( Configuration.GetSection("luisAppId")?.Value, Configuration.GetSection("luisAppKey")?.Value, Configuration.GetSection("luisEndPoint")?.Value); // Set the recognizer options depending on which endpoint version you want to use. // More details can be found in https://docs.microsoft.com/en-gb/azure/cognitive-services/luis/luis-migration-api-v3 var recognizerOptions = new LuisRecognizerOptionsV3(luisApplication) { PredictionOptions = new Microsoft.Bot.Builder.AI.LuisV3.LuisPredictionOptions { IncludeAllIntents = true, } }; return(new LuisRecognizer(recognizerOptions)); }); // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. services.AddBot <PictureBot.Bots.PictureBot>(options => { var appId = Configuration.GetSection("MicrosoftAppId")?.Value; var appSecret = Configuration.GetSection("MicrosoftAppPassword")?.Value; options.CredentialProvider = new SimpleCredentialProvider(appId, appSecret); // Creates a logger for the application to use. ILogger logger = _loggerFactory.CreateLogger <PictureBot.Bots.PictureBot>(); // Catches any errors that occur during a conversation turn and logs them. options.OnTurnError = async(context, exception) => { logger.LogError($"Exception caught : {exception}"); await context.SendActivityAsync("Sorry, it looks like something went wrong."); }; var middleware = options.Middleware; // Add middleware below with "middleware.Add(...." // Add Regex below // middleware.Add(new RegExpRecognizerMiddleware() // .AddIntent("search", new Regex("search picture(?:s)*(.*)|search pic(?:s)*(.*)", RegexOptions.IgnoreCase)) // .AddIntent("share", new Regex("share picture(?:s)*(.*)|share pic(?:s)*(.*)", RegexOptions.IgnoreCase)) // .AddIntent("order", new Regex("order picture(?:s)*(.*)|order print(?:s)*(.*)|order pic(?:s)*(.*)", RegexOptions.IgnoreCase)) // .AddIntent("help", new Regex("help(.*)", RegexOptions.IgnoreCase))); }); // Create the User state. services.AddSingleton <UserState>(sp => { var dataStore = sp.GetRequiredService <IStorage>(); return(new UserState(dataStore)); }); // Create the Conversation state. services.AddSingleton <ConversationState>(sp => { var dataStore = sp.GetRequiredService <IStorage>(); return(new ConversationState(dataStore)); }); // Create the IStorage. services.AddSingleton <IStorage, BlobsStorage>(sp => { var blobConnectionString = Configuration.GetSection("BlobStorageConnectionString")?.Value; var blobContainer = Configuration.GetSection("BlobStorageContainer")?.Value; BlobsStorage dataStore = new BlobsStorage(blobConnectionString, blobContainer); return(dataStore); }); services.AddSingleton(sp => { CosmosClientBuilder clientBuilder = new CosmosClientBuilder( Configuration.GetSection("cosmosEndpointURI")?.Value, Configuration.GetSection("cosmosKey")?.Value ); CosmosClient client = clientBuilder .WithConnectionModeDirect() .Build(); Container container = client.GetContainer( Configuration.GetSection("cosmosDatabaseName")?.Value, Configuration.GetSection("cosmosCollectionName")?.Value ); return(container); }); services.AddSingleton <TextAnalyticsClient>(sp => { Uri cogsBaseUrl = new Uri(Configuration.GetSection("cogsBaseUrl")?.Value); string cogsKey = Configuration.GetSection("cogsKey")?.Value; var credentials = new AzureKeyCredential(cogsKey); return(new TextAnalyticsClient(cogsBaseUrl, credentials)); }); }