internal Bot(Ini config, IEnumerable <SiteProvider> siteProviders, ExecutorInformation executorInformation) { Configuration = config; Providers = siteProviders.ToHashSet(); ReplyMarkupKeyboard.PreviousButtonText = Configuration["buttons"]["previous"]; ReplyMarkupKeyboard.NextButtonText = Configuration["buttons"]["next"]; ReplyMarkupKeyboard.MenuText = Configuration["buttons"]["menu"]; LoadExecutors(executorInformation); }
public static Bot Create(string pathToConfiguration, SiteProvider[] providers, ExecutorInformation executorInformation) { Ini ini; if (!File.Exists(pathToConfiguration)) { ini = CreateDefaultIniConfiguration(pathToConfiguration); } else { ini = new Ini(File.ReadAllText(pathToConfiguration)); } return(Create(ini, providers, executorInformation)); }
public Bot(string config, IEnumerable <SiteProvider> siteProviders, ExecutorInformation executorInformation) { if (!File.Exists(config)) { Configuration = CreateDefaultIniConfiguration(config); } else { Configuration = Ini.FromFile(File.ReadAllText(config)); } Providers = siteProviders.ToHashSet(); ReplyMarkupKeyboard.PreviousButtonText = Configuration["buttons"]["previous"]; ReplyMarkupKeyboard.NextButtonText = Configuration["buttons"]["next"]; LoadExecutors(executorInformation); }
/// <summary> /// Load CommandExecutors using reflection from custom namespace and Jubi.Executors /// </summary> private void LoadExecutors(ExecutorInformation executorInformation) { CommandExecutors = executorInformation.Assembly.GetTypes().Where( t => t.IsSubclassOf(typeof(CommandExecutor)) && !t.IsAbstract && (t.Namespace?.StartsWith(executorInformation.Namespace) ?? false) ) .Select(t => Activator.CreateInstance(t) as CommandExecutor).ToHashSet(); foreach (var command in Assembly.GetExecutingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(CommandExecutor)) && !t.IsAbstract && (t.Namespace?.StartsWith("Jubi.Executors") ?? false))) { CommandExecutors.Add(Activator.CreateInstance(command) as CommandExecutor); } }
/// <summary> /// Load CommandExecutors using reflection from custom namespace and Jubi.Executors /// </summary> private void LoadExecutors(ExecutorInformation executorInformation) { lock (_commandExecutorsLock) { _commandExecutors = GetCommandExecutorsViaReflection(Assembly.GetExecutingAssembly(), "Jubi.Executors"); foreach (var command in GetCommandExecutorsViaReflection(executorInformation.Assembly, executorInformation.Namespace)) { if (_commandExecutors.ContainsKey(command.Key)) { _commandExecutors[command.Key] = command.Value; } else { _commandExecutors.Add(command.Key, command.Value); } } } }
public static Bot Create(Ini configuration, SiteProvider[] providers, ExecutorInformation executorInformation) { return(new Bot(configuration, providers, executorInformation)); }