예제 #1
0
        public IEnumerable<PluginPair> LoadPlugin(List<PluginMetadata> pluginMetadatas)
        {
            var plugins = new List<PluginPair>();
            List<PluginMetadata> CSharpPluginMetadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();

            foreach (PluginMetadata metadata in CSharpPluginMetadatas)
            {
                try
                {
                    // Check if the plugin has an app.config
                    if(File.Exists(metadata.ExecuteFilePath + ".config"))
                    {
                        using (var reader = XmlReader.Create(metadata.ExecuteFilePath + ".config"))
                        {
                            // Can't do redirects properly, so we're gonna fake it.
                            while(reader.ReadToFollowing("assemblyIdentity"))
                            {
                                var name = reader.GetAttribute("name");
                                this.RedirectAssembly(name, metadata.PluginDirectory);
                            }
                        }
                    }

                    Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
                    List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract &&  o.GetInterfaces().Contains(typeof(IPlugin))).ToList();
                    if (types.Count == 0)
                    {
                        Log.Warn(string.Format("Couldn't load plugin {0}: didn't find the class that implement IPlugin", metadata.Name));
                        continue;
                    }

                    foreach (Type type in types)
                    {
                        PluginPair pair = new PluginPair()
                        {
                            Plugin = Activator.CreateInstance(type) as IPlugin,
                            Metadata = metadata
                        };

                        plugins.Add(pair);
                    }
                }
                catch (System.Exception e)
                {
                    Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
            #if (DEBUG)
                    {
                        throw;
                    }
            #endif
                }
            }

            return plugins;
        }
예제 #2
0
 internal static void ExecutePluginQuery(PluginPair pair, Query query)
 {
     try
     {
         Stopwatch sw = new Stopwatch();
         sw.Start();
         List<Result> results = pair.Plugin.Query(query) ?? new List<Result>();
         results.ForEach(o =>
         {
             o.PluginID = pair.Metadata.ID;
         });
         sw.Stop();
         DebugHelper.WriteLine(string.Format("Plugin query: {0} - {1}", pair.Metadata.Name, sw.ElapsedMilliseconds));
         pair.QueryCount += 1;
         if (pair.QueryCount == 1)
         {
             pair.AvgQueryTime = sw.ElapsedMilliseconds;
         }
         else
         {
             pair.AvgQueryTime = (pair.AvgQueryTime + sw.ElapsedMilliseconds) / 2;
         }
         API.PushResults(query, pair.Metadata, results);
     }
     catch (System.Exception e)
     {
         throw new BloopPluginException(pair.Metadata.Name, e);
     }
 }
예제 #3
0
 internal void UpdatePluginMetadataTranslations(PluginPair pluginPair)
 {
     var pluginI18n = pluginPair.Plugin as IPluginI18n;
     if (pluginI18n == null) return;
     try
     {
         pluginPair.Metadata.Name = pluginI18n.GetTranslatedPluginTitle();
         pluginPair.Metadata.Description = pluginI18n.GetTranslatedPluginDescription();
     }
     catch (System.Exception e)
     {
         Log.Warn("Update Plugin metadata translation failed:" + e.Message);
     #if (DEBUG)
         {
             throw;
         }
     #endif
     }
 }