Ejemplo n.º 1
0
        public void PublishEvent(string name, object data)
        {
            // Get all plugins with event handlers for the current event
            // or for <all> events.
            var handlers = _pluginEngine.GetAll()
                           .Where(p => p.State == PluginState.Loaded)
                           .Select(p => p.Package.GetManifest())
                           .SelectMany(
                m => m.EventHandlers.Where(e => e.Name == name || e.Name == All))
                           .ToList();

            _logger.Debug("Publishing event {EventName} to {Count} handlers.", name, handlers.Count());

            foreach (var handler in handlers)
            {
                // These are the handlers for our event
                try
                {
                    _logger.Debug("Calling {Target} for event {EventName}.", handler.Target, name);

                    if (handler.Name == All)
                    {
                        _rpcClient.Call(handler.Target, new[] { name, data });
                    }
                    else
                    {
                        _rpcClient.Call(handler.Target, new[] { data });
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Error when calling event handler {EventHandler}", handler);
                }
            }
        }
Ejemplo n.º 2
0
 public ApiModule(IPluginEngine pluginEngine)
 {
     Get["/api/scripts"] = _ => (from pluginManager in pluginEngine.GetAll()
         where pluginManager.State == PluginState.Loaded
         let manifest = pluginManager.Manifest
         where manifest.UserInterface != null
         where manifest.UserInterface.BackgroundScripts.Any()
         from backgroundScript in manifest.UserInterface.BackgroundScripts
         select string.Concat("plugins/", pluginManager.Package.Id, "/", backgroundScript)).ToArray();
 }
Ejemplo n.º 3
0
 public ApiModule(IPluginEngine pluginEngine)
 {
     Get["/api/scripts"] = _ => (from pluginManager in pluginEngine.GetAll()
                                 where pluginManager.State == PluginState.Loaded
                                 let manifest = pluginManager.Manifest
                                                where manifest.UserInterface != null
                                                where manifest.UserInterface.BackgroundScripts.Any()
                                                from backgroundScript in manifest.UserInterface.BackgroundScripts
                                                select string.Concat("plugins/", pluginManager.Package.Id, "/", backgroundScript)).ToArray();
 }
Ejemplo n.º 4
0
        public IEnumerable <PluginListItem> ListPlugins()
        {
            var plugins = _pluginEngine.GetAll();

            return(from plugin in plugins
                   let packageName = new PackageName(plugin.Package.Id, plugin.Package.Version)
                                     let updatedPackage = (from update in _packageRepository.GetUpdates(new[] { packageName }, false, false)
                                                           orderby update.Version descending
                                                           select update).FirstOrDefault()
                                                          select new PluginListItem
            {
                Id = plugin.Package.Id,
                Name = plugin.Package.Title ?? plugin.Package.Id,
                State = plugin.State.ToString(),
                Version = plugin.Package.Version.ToString(),
                UpdateVersion = updatedPackage == null ? string.Empty : updatedPackage.Version.ToString()
            });
        }