public IEnumerable <BankGetExchange> LoadExchange()
        {
            var loaders    = new List <PluginLoader>();
            var pluginsDir = Path.Combine(AppContext.BaseDirectory, folder);

            foreach (var dir in Directory.GetDirectories(pluginsDir))
            {
                var dirName   = Path.GetFileName(dir);
                var pluginDll = Path.Combine(dir, dirName + ".dll");
                if (File.Exists(pluginDll))
                {
                    var loader = PluginLoader.CreateFromAssemblyFile(
                        pluginDll,
                        config => config.PreferSharedTypes = true
                                                             //sharedTypes: new[] {
                                                             //    typeof(BankGetExchange),
                                                             //    typeof(ExchangeRates)
                                                             //}
                        );
                    loaders.Add(loader);
                }
            }
            Console.WriteLine(loaders.Count());
            // Create an instance of plugin types
            foreach (var loader in loaders)
            {
                BankGetExchange plugin = null;
                try{
                    foreach (var pluginType in loader
                             .LoadDefaultAssembly()
                             .GetTypes()
                             .Where(t => typeof(BankGetExchange).IsAssignableFrom(t) && !t.IsAbstract))
                    {
                        // This assumes the implementation of IPlugin has a parameterless constructor
                        plugin = Activator.CreateInstance(pluginType) as BankGetExchange;
                    }
                }
                catch (Exception ex) {
                    Console.WriteLine($"{ex.Message}");
                    continue;
                }
                yield return(plugin);
            }
        }
Beispiel #2
0
        public static async Task <ExchangeRates[]> Rates(BankGetExchange bank)
        {
            var list = await bank.GetActualRates();

            return(list.ToArray());
        }