public ICollection <ISecondMonitorPlugin> GetPluginsFromAssembly(string assemblyPath, bool includeDisabled)
        {
            Type secondMonitorPluginType        = typeof(ISecondMonitorPlugin);
            List <ISecondMonitorPlugin> plugins = new List <ISecondMonitorPlugin>();

            try
            {
                Assembly assembly = Assembly.UnsafeLoadFrom(assemblyPath);
                Logger.Info("Searching Assembly: " + assemblyPath);


                var types = assembly.GetTypes().Where(c => !c.IsInterface && secondMonitorPluginType.IsAssignableFrom(c));
                foreach (Type type in types)
                {
                    ISecondMonitorPlugin plugin = Activator.CreateInstance(type) as ISecondMonitorPlugin;
                    if (!includeDisabled && !IsPluginEnabled(plugin))
                    {
                        continue;
                    }
                    plugins.Add(plugin);
                    Logger.Info("Found plugin:" + type);
                }

                return(plugins);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Error getting plugins from assembly");
                return(new List <ISecondMonitorPlugin>());
            }
        }
Beispiel #2
0
        public ICollection <ISecondMonitorPlugin> GetPluginsFromAssembly(string assemblyPath)
        {
            var      secondMonitorPluginType = typeof(ISecondMonitorPlugin);
            var      plugins = new List <ISecondMonitorPlugin>();
            Assembly assembly;

            try
            {
                assembly = Assembly.UnsafeLoadFrom(assemblyPath);
                Logger.Info("Searching Assembly: " + assemblyPath);
            }
            catch (Exception)
            {
                return(new List <ISecondMonitorPlugin>());
            }

            var types = assembly.GetTypes().Where(c => !c.IsInterface && secondMonitorPluginType.IsAssignableFrom(c));

            foreach (Type type in types)
            {
                ISecondMonitorPlugin plugin = Activator.CreateInstance(type) as ISecondMonitorPlugin;
                plugins.Add(plugin);
                Logger.Info("Found plugin:" + type);
            }

            return(plugins);
        }
 private bool IsPluginEnabled(ISecondMonitorPlugin plugin)
 {
     if (PluginSettingsProvider.TryIsPluginEnabled(plugin.PluginName, out bool isEnabled))
     {
         Logger.Info($"Plugin {plugin.PluginName} is Enabled: {isEnabled}");
         return(isEnabled);
     }
     PluginSettingsProvider.SetPluginEnabled(plugin.PluginName, plugin.IsEnabledByDefault);
     Logger.Info($"Plugin {plugin.PluginName} is Enabled: {plugin.IsEnabledByDefault}");
     return(plugin.IsEnabledByDefault);
 }
Beispiel #4
0
        public void DeletePlugin(ISecondMonitorPlugin plugin)
        {
            lock (_plugins)
            {
                Logger.Info("Plugin " + plugin.GetType() + " closed");
                _plugins.Remove(plugin);
                bool allDaemons = _plugins.Aggregate(true, (current, activePlugin) => current && activePlugin.IsDaemon);
                if (!allDaemons)
                {
                    return;
                }

                Logger.Info("------------------------------All plugins closed - application exiting-------------------------------\n\n\n");
                Application.Exit();
            }
        }
        public async Task DeletePlugin(ISecondMonitorPlugin plugin, List <Exception> experiencedExceptions)
        {
            lock (_plugins)
            {
                Logger.Info("Plugin " + plugin.GetType() + " closed");
                _plugins.Remove(plugin);

                experiencedExceptions.ForEach(e => Logger.Error(e));

                bool allDaemons = _plugins.Aggregate(true, (current, activePlugin) => current && activePlugin.IsDaemon);
                if (!allDaemons)
                {
                    return;
                }
            }

            if (_activeConnector != null)
            {
                await _activeConnector.FinnishConnectorAsync();
            }

            Logger.Info("------------------------------All plugins closed - application exiting-------------------------------\n\n\n");
            Application.Exit(new CancelEventArgs(true));
        }