public override void Initialize()
        {
            // Initialize mock service manager
            ServiceManager = new MockServiceManager();

            // Initialize service collection
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings()
            {
                OAuthConnections = new List <OAuthConnection>()
                {
                    new OAuthConnection()
                    {
                        Name = Provider, Provider = Provider
                    }
                }
            });

            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en-us", new CognitiveModelSet()
                        {
                            LuisServices = new Dictionary <string, LuisRecognizer>
                            {
                                { "General", new MockGeneralLuisRecognizer() },
                                {
                                    "Email", new MockEmailLuisRecognizer(
                                        new ForwardEmailUtterances(),
                                        new ReplyEmailUtterances(),
                                        new DeleteEmailUtterances(),
                                        new SendEmailUtterances(),
                                        new ShowEmailUtterances())
                                }
                            }
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(new ProactiveState(new MemoryStorage()));
            Services.AddSingleton(new MicrosoftAppCredentials(string.Empty, string.Empty));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                var proactiveState    = sp.GetService <ProactiveState>();
                return(new BotStateSet(userState, conversationState));
            });

            Services.AddSingleton <TestAdapter>(sp =>
            {
                var adapter = new DefaultTestAdapter();
                adapter.AddUserToken("Azure Active Directory v2", Channels.Test, "user1", "test");
                return(adapter);
            });

            // Configure localized responses
            var supportedLocales = new List <string>()
            {
                "en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn"
            };
            var templateFiles = new Dictionary <string, string>
            {
                { "Shared", "ResponsesAndTexts" },
            };

            var localizedTemplates = new Dictionary <string, List <string> >();

            foreach (var locale in supportedLocales)
            {
                var localeTemplateFiles = new List <string>();
                foreach (var(dialog, template) in templateFiles)
                {
                    // LG template for default locale should not include locale in file extension.
                    if (locale.Equals("en-us"))
                    {
                        localeTemplateFiles.Add(Path.Combine(".", "Responses", dialog, $"{template}.lg"));
                    }
                    else
                    {
                        localeTemplateFiles.Add(Path.Combine(".", "Responses", dialog, $"{template}.{locale}.lg"));
                    }
                }

                localizedTemplates.Add(locale, localeTemplateFiles);
            }

            Services.AddSingleton(new LocaleTemplateEngineManager(localizedTemplates, "en-us"));

            // Configure files for generating all responses. Response from bot should equal one of them.
            var engineAll = new TemplateEngine().AddFile(Path.Combine("Responses", "Shared", "ResponsesAndTexts.lg"));

            Services.AddSingleton(engineAll);

            Services.AddSingleton <IStorage>(new MemoryStorage());

            Services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            Services.AddSingleton <IServiceManager>(ServiceManager);

            Services.AddTransient <MainDialog>();
            Services.AddTransient <DeleteEmailDialog>();
            Services.AddTransient <FindContactDialog>();
            Services.AddTransient <ForwardEmailDialog>();
            Services.AddTransient <ReplyEmailDialog>();
            Services.AddTransient <SendEmailDialog>();
            Services.AddTransient <ShowEmailDialog>();
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();

            ConfigData.GetInstance().MaxDisplaySize = 3;
            ConfigData.GetInstance().MaxReadSize    = 3;
        }
Exemple #2
0
        public override void Initialize()
        {
            // Initialize mock service manager
            ServiceManager = new MockServiceManager();

            // Initialize service collection
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings()
            {
                OAuthConnections = new List <OAuthConnection>()
                {
                    new OAuthConnection()
                    {
                        Name = Provider, Provider = Provider
                    }
                }
            });

            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en-us", new CognitiveModelSet()
                        {
                            LuisServices = new Dictionary <string, LuisRecognizer>
                            {
                                { MockData.LuisGeneral, new MockLuisRecognizer(new GeneralTestUtterances()) },
                                {
                                    MockData.LuisToDo, new MockLuisRecognizer(
                                        new DeleteToDoFlowTestUtterances(),
                                        new AddToDoFlowTestUtterances(),
                                        new MarkToDoFlowTestUtterances(),
                                        new ShowToDoFlowTestUtterances())
                                }
                            }
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(new ProactiveState(new MemoryStorage()));
            Services.AddSingleton(new MicrosoftAppCredentials(string.Empty, string.Empty));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                var proactiveState    = sp.GetService <ProactiveState>();
                return(new BotStateSet(userState, conversationState));
            });

            Services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            Services.AddSingleton <IServiceManager>(ServiceManager);

            Services.AddSingleton <TestAdapter>(sp =>
            {
                var adapter = new DefaultTestAdapter();
                adapter.AddUserToken(Provider, Channels.Test, "user1", TestToken);
                return(adapter);
            });

            Services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            Services.AddTransient <MainDialog>();
            Services.AddTransient <AddToDoItemDialog>();
            Services.AddTransient <DeleteToDoItemDialog>();
            Services.AddTransient <MarkToDoItemDialog>();
            Services.AddTransient <ShowToDoItemDialog>();
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();

            // Configure localized responses
            var localizedTemplates = new Dictionary <string, string>();
            var templateFile       = "ResponsesAndTexts";
            var supportedLocales   = new List <string>()
            {
                "en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn"
            };

            foreach (var locale in supportedLocales)
            {
                // LG template for en-us does not include locale in file extension.
                var localeTemplateFile = locale.Equals("en-us")
                    ? Path.Combine(".", "Responses", "Shared", $"{templateFile}.lg")
                    : Path.Combine(".", "Responses", "Shared", $"{templateFile}.{locale}.lg");

                localizedTemplates.Add(locale, localeTemplateFile);
            }

            Services.AddSingleton(new LocaleTemplateManager(localizedTemplates, "en-us"));

            // Configure files for generating all responses. Response from bot should equal one of them.
            var allTemplates = Templates.ParseFile(Path.Combine("Responses", "Shared", "ResponsesAndTexts.lg"));

            Services.AddSingleton(allTemplates);

            Services.AddSingleton <IStorage>(new MemoryStorage());
        }
Exemple #3
0
        public override void Initialize()
        {
            this.ServiceManager = MockServiceManager.GetCalendarService();
            this.SearchService  = new MockSearchClient();

            // Initialize service collection
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings()
            {
                OAuthConnections = new List <OAuthConnection>()
                {
                    new OAuthConnection()
                    {
                        Name = Provider, Provider = Provider
                    }
                },

                AzureSearch = new BotSettings.AzureSearchConfiguration()
                {
                    SearchServiceName = "mockSearchService"
                }
            });

            Services.AddSingleton(new BotServices());
            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(new ProactiveState(new MemoryStorage()));
            Services.AddSingleton(new MicrosoftAppCredentials(string.Empty, string.Empty));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                var proactiveState    = sp.GetService <ProactiveState>();
                return(new BotStateSet(userState, conversationState));
            });

            Services.AddSingleton <TestAdapter>(sp =>
            {
                var adapter = new DefaultTestAdapter();
                adapter.AddUserToken("Azure Active Directory v2", Channels.Test, "user1", "test");
                return(adapter);
            });
            Services.AddSingleton(SearchService);

            // Configure localized responses
            var localizedTemplates = new Dictionary <string, string>();
            var templateFile       = "ResponsesAndTexts";
            var supportedLocales   = new List <string>()
            {
                "en-us", "de-de", "es-es", "fr-fr", "it-it", "zh-cn"
            };

            foreach (var locale in supportedLocales)
            {
                // LG template for en-us does not include locale in file extension.
                var localeTemplateFile = locale.Equals("en-us")
                    ? Path.Combine(".", "Responses", "Shared", $"{templateFile}.lg")
                    : Path.Combine(".", "Responses", "Shared", $"{templateFile}.{locale}.lg");

                localizedTemplates.Add(locale, localeTemplateFile);
            }

            Services.AddSingleton(new LocaleTemplateManager(localizedTemplates, "en-us"));

            // Configure files for generating all responses. Response from bot should equal one of them.
            var allTemplates = Templates.ParseFile(Path.Combine("Responses", "Shared", "ResponsesAndTexts.lg"));

            Services.AddSingleton(allTemplates);

            Services.AddSingleton <IStorage>(new MemoryStorage());
            Services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>();
            Services.AddSingleton(ServiceManager);
            Services.AddTransient <MainDialog>();
            Services.AddTransient <ChangeEventStatusDialog>();
            Services.AddTransient <JoinEventDialog>();
            Services.AddTransient <CreateEventDialog>();
            Services.AddTransient <FindContactDialog>();
            Services.AddTransient <ShowEventsDialog>();
            Services.AddTransient <TimeRemainingDialog>();
            Services.AddTransient <UpcomingEventDialog>();
            Services.AddTransient <UpdateEventDialog>();
            Services.AddTransient <CheckPersonAvailableDialog>();
            Services.AddTransient <FindMeetingRoomDialog>();
            Services.AddTransient <BookMeetingRoomDialog>();
            Services.AddTransient <UpdateMeetingRoomDialog>();
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();

            var state = Services.BuildServiceProvider().GetService <ConversationState>();

            CalendarStateAccessor = state.CreateProperty <CalendarSkillState>(nameof(CalendarSkillState));
        }