public virtual void InitializeSkill()
        {
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings());
            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en-us", new CognitiveModelSet
                        {
                            LuisServices = new Dictionary <string, LuisRecognizer>
                            {
                                { "General", GeneralTestUtil.CreateRecognizer() },
                                { "SkillSample", SkillTestUtil.CreateRecognizer() }
                            }
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new MicrosoftAppCredentials("appId", "password"));
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            var localizedTemplates = new Dictionary <string, string>();
            var templateFile       = "AllResponses";
            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", $"{templateFile}.lg")
                    : Path.Combine(".", "Responses", $"{templateFile}.{locale}.lg");

                localizedTemplates.Add(locale, localeTemplateFile);
            }

            TemplateEngine = new LocaleTemplateManager(localizedTemplates, "en-us");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-us");
            Services.AddSingleton(TemplateEngine);
            Services.AddTransient <MainDialog>();
            Services.AddTransient <SampleDialog>();
            Services.AddTransient <SampleAction>();
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();
            Services.AddTransient <IBot, DefaultActivityHandler <MainDialog> >();
        }
Ejemplo n.º 2
0
        public virtual void InitializeSkill()
        {
            Services = new ServiceCollection();
            Services.AddSingleton(new BotSettings());
            Services.AddSingleton(new BotServices()
            {
                CognitiveModelSets = new Dictionary <string, CognitiveModelSet>
                {
                    {
                        "en", new CognitiveModelSet
                        {
                            LuisServices = new Dictionary <string, ITelemetryRecognizer>
                            {
                                { "General", GeneralTestUtil.CreateRecognizer() },
                                { "skill", SkillTestUtil.CreateRecognizer() }
                            }
                        }
                    }
                }
            });

            Services.AddSingleton <IBotTelemetryClient, NullBotTelemetryClient>();
            Services.AddSingleton(new MicrosoftAppCredentials("appId", "password"));
            Services.AddSingleton(new UserState(new MemoryStorage()));
            Services.AddSingleton(new ConversationState(new MemoryStorage()));
            Services.AddSingleton(sp =>
            {
                var userState         = sp.GetService <UserState>();
                var conversationState = sp.GetService <ConversationState>();
                return(new BotStateSet(userState, conversationState));
            });

            ResponseManager = new ResponseManager(
                new string[] { "en", "de", "es", "fr", "it", "zh" },
                new MainResponses(),
                new SharedResponses(),
                new SampleResponses());

            Services.AddSingleton(ResponseManager);
            Services.AddTransient <MainDialog>();
            Services.AddTransient <SampleDialog>();
            Services.AddSingleton <TestAdapter, DefaultTestAdapter>();
            Services.AddTransient <IBot, DialogBot <MainDialog> >();
        }