Example #1
0
        /// <summary>
        /// Register default LG file as language generation.
        /// </summary>
        /// <param name="botAdapter">The <see cref="BotAdapter"/> to add services to.</param>
        /// <param name="resourceExplorer">resource explorer to use for .lg based resources.</param>
        /// <param name="defaultLg">Default LG Resource Id (default: main.lg).</param>
        /// <returns>The BotAdapter.</returns>
        public static BotAdapter UseLanguageGeneration(
            this BotAdapter botAdapter,
            ResourceExplorer resourceExplorer = null,
            string defaultLg = null)
        {
            if (defaultLg == null)
            {
                defaultLg = "main.lg";
            }

            if (resourceExplorer == null)
            {
                resourceExplorer = new ResourceExplorer();
            }

            if (resourceExplorer.TryGetResource(defaultLg, out var resource))
            {
                botAdapter.UseLanguageGeneration(resourceExplorer, new ResourceMultiLanguageGenerator(defaultLg));
            }
            else
            {
                botAdapter.UseLanguageGeneration(resourceExplorer, new TemplateEngineLanguageGenerator(string.Empty, defaultLg, LanguageGeneratorManager.MultiLanguageResolverDelegate(resourceExplorer)));
            }

            return(botAdapter);
        }
Example #2
0
        private async Task <ITurnContext> GetTurnContext(string lgFile)
        {
            var context = new TurnContext(new TestAdapter(), new Activity());
            var lgText  = await resourceExplorer.GetResource(lgFile).ReadTextAsync();

            context.TurnState.Add <ILanguageGenerator>(new TemplateEngineLanguageGenerator(lgText, "test", LanguageGeneratorManager.MultiLanguageResolverDelegate(resourceExplorer)));
            return(context);
        }