コード例 #1
0
ファイル: Introspection.cs プロジェクト: forki/aardvark.base
 private static bool IsPlugin(string file)
 {
     try
     {
         var a     = Assembly.LoadFile(file);
         var empty = Introspection.GetAllMethodsWithAttribute <OnAardvarkInitAttribute>(a).IsEmpty();
         if (!empty)
         {
             Report.Line(3, "[GetPluginAssemblyPaths] found plugins in: {0}", file);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (FileLoadException e)
     {
         Report.Line(3, "[GetPluginAssemblyPaths] IsPlugin({0}) failed.", file);
         Report.Line(3, "[GetPluginAssemblyPaths] (FileLoad) Could not load potential plugin assembly (not necessarily an error. proceeding): {0}", e.Message);
         Report.Line(5, "[GetPluginAssemblyPaths] StackTrace (outer): {0}", e.StackTrace.ToString());
         try {
             Report.Line(5, "[GetPluginAssemblyPaths] FusionLog: {0}", e.FusionLog);
             if (e.InnerException != null)
             {
                 Report.Line(5, "[GetPluginAssemblyPaths] Inner message: {0}", e.InnerException.Message);
                 Report.Line(5, "[GetPluginAssemblyPaths] Inner stackTrace: {0}", e.InnerException.StackTrace.ToString());
             }
         } catch (Exception)
         {
             Report.Line(5, "[GetPluginAssemblyPaths] could not print details for FileLoadException (most likely BadImageFormat)");
         }
         return(false);
     }
     catch (Exception e)
     {
         Report.Line(3, "[GetPluginAssemblyPaths] IsPlugin({0}) failed.", file);
         Report.Line(3, "[GetPluginAssemblyPaths] Could not load potential plugin assembly (not necessarily an error. proceeding): {0}", e.Message);
         Report.Line(5, "[GetPluginAssemblyPaths] {0}", e.StackTrace.ToString());
         return(false);
     }
 }
コード例 #2
0
ファイル: Introspection.cs プロジェクト: forki/aardvark.base
        private static void LoadAll(IEnumerable <Assembly> xs)
        {
            var assemblies = Enumerable.Concat(Introspection.AllAssemblies, xs).GroupBy(a => a.FullName).Select(x => x.First()).ToArray();

            foreach (var ass in assemblies)
            {
                var initMethods = Introspection.GetAllMethodsWithAttribute <OnAardvarkInitAttribute>(ass).Select(t => t.E0).Distinct().ToArray();

                foreach (var mi in initMethods)
                {
                    var parameters = mi.GetParameters();

                    Report.BeginTimed("initializing {1}", mi.Name, mi.DeclaringType.Name);

                    try
                    {
                        if (parameters.Length == 0)
                        {
                            mi.Invoke(null, null);
                        }
                        else if (parameters.Length == 1 && parameters[0].ParameterType == typeof(IEnumerable <Assembly>))
                        {
                            mi.Invoke(null, new object[] { Introspection.AllAssemblies });
                        }
                        else
                        {
                            Report.Warn("Strange aardvark init method found: {0}, should be Init : IEnumberable<Assembly> -> unit or unit -> unit", mi);
                        }
                    }
                    catch (Exception e)
                    {
                        Report.Warn("failed: {0}", e);
                    }

                    Report.End();
                }
            }
        }