public async Task <CalculationResponseModel> Calculate(CalculationRequestModel requestModel)
        {
            var _plugin = await loader.Load();

            // The plugin is eagerly loaded (in-scope)
            return(new CalculationResponseModel
            {
                Result = _plugin.Calculate(requestModel.A, requestModel.B)
            });
        }
        public async Task <CalculationResponseModel> Calculate(CalculationRequestModel requestModel)
        {
            // Load the plugin on-demand
            var plugin = await _loader.Load();

            return(new CalculationResponseModel
            {
                Result = plugin.Calculate(requestModel.A, requestModel.B)
            });
        }
Exemple #3
0
        public async Task <IEnumerable <Product> > Get([FromQuery] string searchTerm)
        {
            var repository = await loader.Load();

            if (String.IsNullOrEmpty(searchTerm))
            {
                return(await repository.All());
            }

            return(await repository.Search(searchTerm));
        }
Exemple #4
0
        /// <summary>
        /// Load the plugin on-demand via the Load() or LoadAll() method
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <string> Get([FromQuery] string input)
        {
            var plugin = await _pluginLoader.Load();

            var response = plugin.SayHello(input);
            await _pluginLoader.Unload();

            return(response);
        }
Exemple #5
0
        public IPluginContainer LoadPlugin(string file)
        {
            if (File.Exists(file))
            {
                throw new FileNotFoundException("Plugin file not found", file);
            }

            var pluginContainer = Loader.Load(file);

            _loadedPlugins.Add(pluginContainer.GetName(), pluginContainer);
            return(pluginContainer);
        }
Exemple #6
0
        /// <summary>
        ///     Initializes this instance.
        /// </summary>
        public void Initialize()
        {
            _plugins.Clear();
            var items = _loader.Load();

            items.ForEach(
                plugin =>
            {
                plugin.Initialize();
                _plugins.Add(plugin.Key, plugin);
            });
        }
Exemple #7
0
        /// <summary>
        /// Process an already loaded <c>YamlDocument</c> and returns the loaded suite model.
        /// </summary>
        /// <param name="yaml">The yaml document to process.</param>
        /// <returns>Returns a loaded model if succeeds. On error it throws an exception, never
        /// returns <c>null</c>.</returns>
        protected Suite LoadYaml(YamlDocument yaml)
        {
            Contract.Requires(yaml != null);
            Contract.Requires(yaml.RootNode != null);
            Contract.Ensures(Contract.Result <Suite>() != null);

            log.Debug("Processing YAML document...");

            foreach (var pluginUri in LoadPlugins(yaml.RootNode))
            {
                pluginLoader.Load(pluginUri);
            }

            var goals       = LoadGoals(yaml.RootNode);
            var defaultGoal = LoadDefaultGoal(goals, yaml.RootNode) ?? Suite.DebugGoal;
            var suite       = suiteFactory.CreateSuite(new HashSet <Goal>(goals.Values), defaultGoal);

            parser.SetActiveGoal(suite.ActiveGoal);

            suite.Name      = parser.GetScalarValue(yaml.RootNode, "suite", "Error reading the name of the suite");
            suite.Version   = ParseVersion(parser.GetOptionalScalarValue(yaml.RootNode, "version", null));
            suite.Copyright = parser.GetOptionalScalarValue(yaml.RootNode, "copyright", null);

            LoadParameters(suite, suite, yaml.RootNode);

            foreach (KeyValuePair <string, YamlNode> item in parser.EnumerateNamedNodesOf(yaml.RootNode, "modules"))
            {
                var module = suite.GetModule(item.Key);

                if (item.Value != null)
                {
                    LoadModule(module, item.Value);
                }
            }

            foreach (KeyValuePair <string, YamlNode> item in parser.EnumerateNamedNodesOf(yaml.RootNode, "products"))
            {
                var product = suite.GetProduct(item.Key);

                if (item.Value != null)
                {
                    LoadProduct(suite, product, item.Value);
                }
            }

            LoadSourceSetIgnoreLists(suite.SourceSetIgnoreLists, yaml.RootNode);

            validator.Validate(suite);

            log.Debug("Finished processing YAML document.");
            return(suite);
        }
        public MainWindow()
        {
            try
            {
                eventBus = new EventBus();
                Container.Current.Register <IEventBus>(eventBus);

                //Fixes an issue with current directory being system32 for the plugin loader and not the application path as desired
                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Setting base directory...", EventLogEntryType.Information));
                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing components...", EventLogEntryType.Information));
                InitializeComponent();

                var logService = new LogService(eventBus);
                Container.Current.Register <ILogService>(logService);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing plugin loader...", EventLogEntryType.Information));
                pluginLoader = new PluginLoader(eventBus, Container.Current);
                Container.Current.Register <IPluginLoader>(pluginLoader);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing shortcut collection...", EventLogEntryType.Information));
                var shortcutCollection = new ShortcutCollection(pluginLoader, eventBus);
                Container.Current.Register <IShortcutCollection <string, ILaunchShortcut> >(shortcutCollection);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing shortcut executor...", EventLogEntryType.Information));
                var shortcutExecutor = new ShortcutExecutor(shortcutCollection);
                Container.Current.Register <IShortcutExecutor>(shortcutExecutor);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing setting collection...", EventLogEntryType.Information));
                var settingCollection = new SettingCollection(eventBus);
                Container.Current.Register <ISettingCollection>(settingCollection);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing plugins...", EventLogEntryType.Information));
                pluginLoader.Load();
                eventBus.Publish(new ProgramLoadedEvent());

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing main view model...", EventLogEntryType.Information));
                DataContext = new MainViewModel(eventBus, shortcutCollection, shortcutExecutor, settingCollection, pluginLoader);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing hooks...", EventLogEntryType.Information));
                hookId   = SetHook(proc);
                Closing += OnMainWindowClosing;

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initialization complete", EventLogEntryType.Information));
            }
            catch (Exception ex)
            {
                eventBus.Publish(new LogEntryPublished("Heibroch.Launch", ex.StackTrace, EventLogEntryType.Error));
                throw ex;
            }
        }
Exemple #9
0
 private void LoadPlugins(string dllFileName)
 {
     // TODO: can be done via UI at runtime
     try
     {
         // TODO: add a plugin manager or smth
         Assembly assembly = GetAssembly(dllFileName);
         pluginLoader_.Load(assembly);
     }
     catch (Exception e)
     {
         // TODO: log
     }
 }
Exemple #10
0
        public bool LoadPlugin <TPlugin>(FileInfo fileInfo, IPluginLoader <TPlugin> pluginLoader = null) where TPlugin : class, IPlugin
        {
            pluginLoader ??= new PluginLoader <TPlugin>(this);
            TPlugin plugin = pluginLoader.Load(fileInfo);

            if (plugin == null)
            {
                return(false);
            }
            ListPlugins.Add(plugin);
            PluginLoadedEventArgs loadedEventArgs = new PluginLoadedEventArgs(plugin);

            EventsManager.CallEvent(loadedEventArgs);
            return(true);
        }
        public void InitializePlugins()
        {
            lock (PluginInitializationLocker)
            {
                _log.Trace(Resources.Resources.PluginInitializer_InitializePlugins_Plugins_initialization_started);

                var pluginInstances = _pluginLoader.Load();

                var initialized = 0;

                foreach (var plugin in pluginInstances)
                {
                    _pluginProvider.Initialize(plugin);

                    initialized++;
                }

                _log.Debug(
                    Resources.Resources.PluginInitializer_InitializePlugins_Plugins_Initialization_finished.FormatWith(initialized));
            }
        }
Exemple #12
0
        public void ShouldLoadItPlugin()
        {
            var result = _pluginLoader.Load().ToArray();

            result.Should().NotBeNullOrEmpty();
        }
 public async Task <CalculationResponseModel> Calculate(CalculationRequestModel requestModel)
 {
     // Load the plugin on-demand
     base.SetPlugin(await _loader.Load());
     return(base.Calculate(requestModel));
 }
Exemple #14
0
        public async Task Delete(int productId)
        {
            var repository = await deleterLoader.Load();

            await repository.Delete(productId);
        }
Exemple #15
0
        public async Task <Product> Create(Product product)
        {
            var repository = await writerLoader.Load();

            return(await repository.Create(product));
        }
Exemple #16
0
        /// <summary>
        /// Load the plugin on-demand via the Load() or LoadAll() method
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <string> Get([FromQuery] string input)
        {
            var plugin = await _pluginLoader.Load();

            return(plugin.SayHello(input));
        }