Пример #1
0
        internal static List <Assembly> FindPlugins(PluginsConfiguration configuration)
        {
            var assemblies = new List <Assembly>();

            if (configuration.Directories.Count == 0 && configuration.Assemblies.Count == 0)
            {
                var rootPath = AppDomain.CurrentDomain.BaseDirectory ?? typeof(AutofacMefProvider).Assembly.Location;
                foreach (var f in Directory.GetFiles(rootPath, "*.Plugins.*.dll", SearchOption.TopDirectoryOnly))
                {
                    try { assemblies.Add(Assembly.LoadFrom(f)); }
                    catch (Exception aex)
                    {
                        System.Diagnostics.Debug.WriteLine(aex.ToString());
                        throw new FrameworkException("Error loading plugin: " + f, aex);
                    }
                }
            }

            foreach (var directory in configuration.Directories)
            {
                if (directory != null)
                {
                    foreach (var f in Directory.EnumerateFiles(directory, "*.dll"))
                    {
                        try
                        {
                            if (!Plugins.ExcludeFile(f))
                            {
                                var asm = Assembly.LoadFrom(f);
                                if (!Plugins.ExcludeAssembly(asm))
                                {
                                    assemblies.Add(asm);
                                }
                            }
                        }
                        catch (Exception aex)
                        {
                            System.Diagnostics.Debug.WriteLine(aex.ToString());
                            throw new FrameworkException("Error loading plugin: " + f, aex);
                        }
                    }
                }
            }
            foreach (var asm in configuration.Assemblies)
            {
                if (asm != null)
                {
                    assemblies.Add(asm);
                }
            }
            return(assemblies);
        }