Exemplo n.º 1
0
        private List <ProcessorDTO> LoadProcessors(string processorPath)
        {
            List <ProcessorDTO> lstProcessors = new List <ProcessorDTO>();
            DirectoryInfo       di            = new DirectoryInfo(processorPath);

            FileInfo[] fileInfos = di.GetFiles("*.dll");

            foreach (FileInfo fi in fileInfos)
            {
                //using (var fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read))
                //{
                try
                {
                    var context = new CollectibleAssemblyLoadContext(processorPath);
                    //var assembly = context.LoadFromStream(fs);
                    var assembly = context.LoadFromAssemblyPath(fi.FullName);
                    //Can have multiple processors implmented in a single assembly
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (typeof(DataProcessor).IsAssignableFrom(type))
                        {
                            DataProcessor result = Activator.CreateInstance(type) as DataProcessor;
                            if (result != null)
                            {
                                ProcessorDTO pdto = new ProcessorDTO(result);
                                pdto.Path = fi.FullName;
                                lstProcessors.Add(pdto);
                            }
                        }
                    }
                    context.Unload();
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                //Handle unloadable libraries
                catch (Exception ex)
                {
                    string msg = ex.Message;
                }
                //}
            }

            return(lstProcessors);
        }
Exemplo n.º 2
0
        private IReadOnlyCollection <string> FindPluginsInAssemblies(string pluginsPath, string[] assemblyPaths)
        {
            var assemblyPluginInfos = new List <string>();
            //var pluginFinderAssemblyContext = new PluginAssemblyLoadingContext("PluginFinderAssemblyContext");
            var pluginFinderAssemblyContext = new CollectibleAssemblyLoadContext(pluginsPath);
            //var pluginFinderAssemblyContext = new AssemblyLoadContext(name: "PluginFinderAssemblyContext");
            var cwd = System.IO.Directory.GetCurrentDirectory();

            foreach (var assemblyPath in assemblyPaths)
            {
                var fullAssemblyPath = System.IO.Path.Combine(cwd, assemblyPath);
                var assembly         = pluginFinderAssemblyContext.LoadFromAssemblyPath(fullAssemblyPath);
                if (GetPluginTypes(assembly).Any())
                {
                    assemblyPluginInfos.Add(assembly.Location);
                }
            }
            pluginFinderAssemblyContext.Unload();
            return(assemblyPluginInfos);
        }
Exemplo n.º 3
0
        //private readonly AssemblyLoadContext _pluginAssemblyLoadingContext;

        public PluginHost(string pluginsPath)
        {
            _pluginAssemblyLoadingContext = new CollectibleAssemblyLoadContext(pluginsPath);
            //_pluginAssemblyLoadingContext = new AssemblyLoadContext("PluginAssemblyContext");
        }