Beispiel #1
0
        public List <ProcessorDTO> GetProcessors(string processorsPath)
        {
            List <ProcessorDTO> lstProcessors = new List <ProcessorDTO>();
            var pluginFinder  = new PluginFinder <DataProcessor>();
            var assemblyPaths = pluginFinder.FindAssemliesWithPlugins(processorsPath);

            GC.Collect();
            GC.WaitForPendingFinalizers();

            var pluginHost = new PluginHost <DataProcessor>(processorsPath);

            pluginHost.LoadPlugins(assemblyPaths);

            foreach (var processor in pluginHost.GetPlugins())
            {
                ProcessorDTO pdto = new ProcessorDTO(processor);
                lstProcessors.Add(pdto);
            }

            //string[] assemblies = Directory.GetFiles(processorsPath, "*.dll", new EnumerationOptions() { RecurseSubdirectories = true });
            //DirectoryInfo dirInfo = new DirectoryInfo(processorsPath);
            //DirectoryInfo[] dirInfos = dirInfo.GetDirectories();
            //foreach (DirectoryInfo di in dirInfos)
            //{
            //    List<ProcessorDTO> processors = LoadProcessors(di.FullName);
            //    lstProcessors.AddRange(processors);
            //}

            return(lstProcessors);
        }
Beispiel #2
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);
        }