Example #1
0
        public IEnumerable<IPluginManager> Refresh()
        {
            var infos = _repo.List<PluginInfo>();

            // Load all plugins from path
            var path = HdknConfig.GetPath("Paths.Plugins");

            foreach(var info in _fs.GetFileSystemInfos(path))
            {
                if(_loaders.Any(l => l.CanLoad(info.FullName)) && infos.All(i => i.Path != info.FullName))
                {
                    Logger.Info("Found new plugin {0}", info.FullName);

                    var pluginInfo = new PluginInfo {Path = info.FullName};
                    _repo.Save(pluginInfo);
                    infos.Add(pluginInfo);
                }
            }

            // load all PluginInfo where Name not in _managers.Keys
            var ret = new List<IPluginManager>();

            foreach (PluginInfo info in infos)
            {
                try
                {
                    var manager = new DefaultPluginManager(info, _mbus, _runner, _loaders);

                    if (!_managers.ContainsKey(manager.Name))
                    {
                        manager.Initialize();
                        manager.Install();

                        _managers.Add(manager.Name, manager);

                        ret.Add(manager);
                    }
                }
                catch(Exception e)
                {
                    Logger.ErrorException(String.Format("Could not create plugin from path {0}", info.Path), e);
                }
            }

            return ret;
        }
Example #2
0
        internal DefaultPluginManager(PluginInfo info, IMessageBus mbus, IMigrationRunner runner, IPluginLoader[] loaders)
        {
            _info = info;

            _mbus = mbus;
            _runner = runner;
            _loaders = loaders;

            var loader = (from l in _loaders
                          where l.CanLoad(_info.Path)
                          select l).First();

            if (loader != null)
            {
                _pluginType = loader.Load(_info.Path).First();

                if (_pluginType == null)
                {
                    throw new ArgumentException("Could not find plugin type in given PluginInfo.Path", "info");
                }
            }
        }