Ejemplo n.º 1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            Tools.Add(new Hammer());
            var appSettings                     = new AppSettings();
            var logger                          = PluginLoaderLogger.Factory(appSettings);
            var appDomain                       = new AppDomainWrapper(AppDomain.CurrentDomain, logger);
            var settings                        = new PluginLoaderSettings(appSettings);
            var typeLoader                      = new TypeLoader <ITool>(PluginLoaderSettings.Default, logger);
            var assemblyNameReader              = new AssemblyNameReader();
            var assemblyCache                   = new AssemblyCache(appDomain, assemblyNameReader, logger);
            var assemblyLoader                  = new AssemblyLoader(appDomain, settings, assemblyCache, assemblyNameReader, logger);
            var waiter                          = new Waiter(logger);
            var assemblyResolveCache            = new AssemblyResolveCache();
            var pluginDependencyObjectCreator   = new PluginDependencyResolverObjectCreator(appDomain, settings, assemblyLoader, waiter, assemblyResolveCache, logger);
            var pluginDependencyResolverFactory = new PluginDependencyResolverCacheFactory(pluginDependencyObjectCreator, logger);
            var pluginCacheFactory              = new PluginCacheFactory <ITool>(typeLoader, pluginDependencyResolverFactory, assemblyLoader, logger);
            var pluginPaths                     = new StaticPluginPaths(new[] { "Plugins" });
            var pluginLoader                    = new PluginLoader <ITool>(pluginPaths, pluginCacheFactory);
            var plugins                         = pluginLoader.LoadPlugins();
            var objectCreator                   = new ObjectCreator <ITool>();
            var toolPluginObjectCreator         = new PluginObjectCreator <ITool>(settings, objectCreator, logger);

            Tools.AddRange(plugins.CreatePluginObjects(toolPluginObjectCreator));
        }
Ejemplo n.º 2
0
        static void Main()
        {
            var tools = new List <ITool>
            {
                new Hammer()
            };

            // Common objects
            var appSettings = new AppSettings();
            var logger      = PluginLoaderLogger.Factory(appSettings);
            var appDomain   = new AppDomainWrapper(AppDomain.CurrentDomain, logger);

            PluginLoaderSettings.Default = new MyPluginLoaderSettings(appSettings);
            var settings             = PluginLoaderSettings.Default;
            var assemblyNameReader   = new AssemblyNameReader();
            var assemblyCache        = new AssemblyCache(appDomain, assemblyNameReader, logger);
            var assemblyLoader       = new AssemblyLoader(appDomain, settings, assemblyCache, assemblyNameReader, logger);
            var pluginPaths          = new AppPluginPaths(settings.AppName, settings.PluginFolder, appDomain, logger);
            var waiter               = new Waiter(logger);
            var assemblyResolveCache = new AssemblyResolveCache();
            var pluginDependencyResolverObjectCreator = new PluginDependencyResolverObjectCreator(appDomain, settings, assemblyLoader, waiter, assemblyResolveCache, logger);
            var pluginDependencyResolverFactory       = new PluginDependencyResolverCacheFactory(pluginDependencyResolverObjectCreator, logger);

            // ITool plugin loader objects
            var typeLoader              = new TypeLoader <ITool>(settings, logger);
            var objectCreator           = new ObjectCreator <ITool>();
            var pluginCacheFactory      = new PluginCacheFactory <ITool>(typeLoader, pluginDependencyResolverFactory, assemblyLoader, logger);
            var pluginLoader            = new PluginLoader <ITool>(pluginPaths, pluginCacheFactory);
            var plugins                 = pluginLoader.LoadPlugins();
            var toolPluginObjectCreator = new PluginObjectCreator <ITool>(settings, objectCreator, logger);

            tools.AddRange(plugins.CreatePluginObjects(toolPluginObjectCreator));

            // ICaveManTool<Hammer> plugin loader objects - using RuntimePluginLoader
            var caveManHammerRuntimePluginLoader = RuntimePluginLoaderFactory.Instance.Create <CavemanHammerRuntimePluginLoader, ICaveManTool <Hammer> >();
            var caveManObjectCreator             = new ObjectCreator <ICaveManTool <Hammer> >();
            var caveManToolPluginObjectCreator   = new PluginObjectCreator <ICaveManTool <Hammer> >(settings, caveManObjectCreator, logger);

            tools.AddRange(caveManHammerRuntimePluginLoader.PluginCollection.CreatePluginObjects(caveManToolPluginObjectCreator));

            ShowPrompt(tools);
            // Only 4 plugins will show as this doesn't support plugins with Constructor parameters
            int input = ReadLine(tools);

            while (input != 0)
            {
                if (input <= tools.Count)
                {
                    Console.WriteLine(tools[input - 1].DoWork());
                }
                ShowPrompt(tools);
                input = ReadLine(tools);
            }
        }
Ejemplo n.º 3
0
 public SingletonObjects()
 {
     Settings             = PluginLoaderSettings.Default;
     AppSettings          = new AppSettings();
     Logger               = PluginLoaderLogger.Factory(AppSettings);
     AppDomain            = new AppDomainWrapper(System.AppDomain.CurrentDomain, Logger);
     AssemblyNameReader   = new AssemblyNameReader();
     AssemblyCache        = new AssemblyCache(AppDomain, AssemblyNameReader, Logger);
     AssemblyLoader       = new AssemblyLoader(AppDomain, Settings, AssemblyCache, AssemblyNameReader, Logger);
     PluginPaths          = new AppPluginPaths(Settings.AppName, Settings.PluginFolder, AppDomain, Logger);
     Waiter               = new Waiter(Logger);
     AssemblyResolveCache = new AssemblyResolveCache();
     PluginDependencyResolverObjectCreator = new PluginDependencyResolverObjectCreator(AppDomain, Settings, AssemblyLoader, Waiter, AssemblyResolveCache, Logger);
     PluginDependencyResolverFactory       = new PluginDependencyResolverCacheFactory(PluginDependencyResolverObjectCreator, Logger);
 }