Esempio n. 1
0
        /// <summary>
        /// Create an instance of <see cref="ModulesStartup"/>
        /// </summary>
        /// <param name="configuration">
        /// Application configuration containing modules configuration
        /// </param>
        public ModulesStartup(IConfiguration configuration)
        {
            this._configuration = configuration ??
                                  throw new ArgumentNullException(nameof(configuration));
            ModulesOptions options = configuration.Get <ModulesOptions>();

            this._modules = options.Modules
                            .Select(s =>
            {
                Type type = Type.GetType($"{s.Type}.ModuleInjector, {s.Type}");

                if (type == null)
                {
                    /* hard to debug in docker */

                    /* throw new TypeLoadException(
                     *  $"Cannot load type \"{s.Type}\"");*/
                    Console.WriteLine($"Cannot load type \"{s.Type}\"", Color.Red);
                    return(null);
                }
                else
                {
                    IModule module = (IModule)Activator.CreateInstance(type);
                    return(module);
                }
            }
                                    );
        }
Esempio n. 2
0
        /// <summary>
        /// Create an instance of <see cref="ModulesStartup"/>
        /// </summary>
        /// <param name="configuration">
        /// Application configuration containing modules configuration
        /// </param>
        public ModulesStartup(IConfiguration configuration)
        {
            this._configuration = configuration ??
                                  throw new ArgumentNullException(nameof(configuration));
            ModulesOptions options = configuration.Get <ModulesOptions>();

            if (options.Modules.Count == 0)
            {
                options.Modules.Add(new ModuleOptions
                {
                    Name = "DialogflowAi",
                    Type = "BotSharp.Platform.Dialogflow"
                });

                Console.WriteLine($"Platform emulator not found.", Color.Red);
                Console.WriteLine($"Using default emulator: DialogflowAi, BotSharp.Platform.Dialogflow.");
            }

            Console.WriteLine($"Note: The red part information shown below can be ignored because the corresponding item is not referenced.", Color.Yellow);

            this._modules = options.Modules
                            .Select(s =>
            {
                Type type = Type.GetType($"{s.Type}.ModuleInjector, {s.Type}");

                if (type == null)
                {
                    /* hard to debug in docker */

                    /* throw new TypeLoadException(
                     *  $"Cannot load type \"{s.Type}\"");*/
                    Console.WriteLine($"Cannot load type \"{s.Type}\"", Color.Red);
                    return(null);
                }
                else
                {
                    IModule module = (IModule)Activator.CreateInstance(type);
                    Console.WriteLine($"Loaded {s.Type.Split('.')[1]} \"{s.Type}\"", Color.Green);
                    return(module);
                }
            }
                                    );
        }