Exemple #1
0
 private static void loadPlugins() 
 {
     if (plugings == null)
     {
         plugings = new List<GrepPlugin>();
         if (Directory.Exists(Utils.GetCurrentPath() + "\\Plugins"))
         {
             foreach (string pluginFile in Directory.GetFiles(Utils.GetCurrentPath() + "\\Plugins", "*.plugin", SearchOption.AllDirectories))
             {
                 try
                 {
                     GrepPlugin plugin = new GrepPlugin(pluginFile);
                     if (plugin.LoadPluginSettings())
                     {
                         plugings.Add(plugin);
                     }
                 }
                 catch (Exception ex)
                 {
                     failedEngines[Path.GetFileNameWithoutExtension(pluginFile)] = ex.Message;
                     logger.LogException(LogLevel.Error, "Failed to initialize " + Path.GetFileNameWithoutExtension(pluginFile) + " engine.", ex);
                 }
             }
         }
     }
 }
Exemple #2
0
 private static void loadPlugins()
 {
     if (plugings == null)
     {
         plugings = new List <GrepPlugin>();
         if (Directory.Exists(Utils.GetCurrentPath() + "\\Plugins"))
         {
             foreach (string pluginFile in Directory.GetFiles(Utils.GetCurrentPath() + "\\Plugins", "*.plugin", SearchOption.AllDirectories))
             {
                 try
                 {
                     GrepPlugin plugin = new GrepPlugin(pluginFile);
                     if (plugin.LoadPluginSettings())
                     {
                         plugings.Add(plugin);
                     }
                 }
                 catch (Exception ex)
                 {
                     failedEngines[Path.GetFileNameWithoutExtension(pluginFile)] = ex.Message;
                     logger.Log <Exception>(LogLevel.Error, "Failed to initialize " + Path.GetFileNameWithoutExtension(pluginFile) + " engine.", ex);
                 }
             }
         }
     }
 }
Exemple #3
0
        private static void LoadPlugins()
        {
            lock (lockObj)
            {
                if (plugins == null)
                {
                    plugins = new List <GrepPlugin>();
                    disabledPlugins.Clear();
                    string pluginPath = Path.Combine(Utils.GetCurrentPath(), "Plugins");
                    if (Directory.Exists(pluginPath))
                    {
                        foreach (string pluginFile in Directory.GetFiles(pluginPath, "*.plugin", SearchOption.AllDirectories))
                        {
                            try
                            {
                                GrepPlugin plugin = new GrepPlugin(pluginFile);
                                if (plugin.LoadPluginSettings())
                                {
                                    if (FrameworkVersionsAreCompatible(plugin.FrameworkVersion, FrameworkVersion))
                                    {
                                        if (plugin.Enabled)
                                        {
                                            plugins.Add(plugin);

                                            // many file extensions will map to the same pool of engines,
                                            // so keep a common key for the set of extensions
                                            foreach (string ext in plugin.Extensions)
                                            {
                                                string fileExtension = ext.TrimStart('.');
                                                if (!poolKeys.ContainsKey(fileExtension))
                                                {
                                                    poolKeys.Add(fileExtension, plugin.PluginName);
                                                }
                                            }

                                            logger.Debug(string.Format("Loading plugin: {0} for extensions {1}",
                                                                       plugin.DllFilePath, string.Join(", ", plugin.Extensions.ToArray())));
                                        }
                                        else
                                        {
                                            disabledPlugins.Add(plugin);
                                            logger.Debug(string.Format("Plugin skipped, not enabled: {0}", plugin.DllFilePath));
                                        }
                                    }
                                    else
                                    {
                                        logger.Error(string.Format("Plugin '{0}' developed under outdated framework. Please update the plugin.", Path.GetFileNameWithoutExtension(pluginFile)));
                                    }
                                }
                                else
                                {
                                    logger.Error(string.Format("Plugin {0} failed to load", plugin.DllFilePath));
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.Log <Exception>(LogLevel.Error, "Failed to initialize " + Path.GetFileNameWithoutExtension(pluginFile) + " engine.", ex);
                            }
                        }
                    }

                    foreach (GrepPlugin plugin in plugins)
                    {
                        foreach (string extension in plugin.Extensions)
                        {
                            if (extension != null)
                            {
                                string fileExtension = extension.TrimStart('.');
                                if (!string.IsNullOrWhiteSpace(fileExtension) && !fileTypeEngines.ContainsKey(fileExtension))
                                {
                                    fileTypeEngines.Add(fileExtension, plugin);
                                }
                            }
                        }
                    }
                }
            }
        }