Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public DataTableResponseMessage ExecuteProcessor(string processorsPath, string processorName, string inputFile)
        {
            DataTableResponseMessage   dtRespMsg  = null;
            PluginHost <DataProcessor> pluginHost = null;

            try
            {
                List <string> lstPlugin = new List <string>();
                lstPlugin.Add(processorsPath);
                pluginHost = new PluginHost <DataProcessor>(processorsPath);
                pluginHost.LoadPlugins(lstPlugin);

                DataProcessor proc = pluginHost.GetPlugin(processorName);
                if (proc != null)
                {
                    proc.input_file = inputFile;
                    dtRespMsg       = proc.Execute();
                }
                //foreach (var processor in pluginHost.GetPlugins())
                //{
                //    if (string.Compare(processor.name, processorName, true) == 0)
                //    {
                //        processor.input_file = inputFile;
                //        //result.OutputFile = outputFile;
                //        dtRespMsg = processor.Execute();
                //        break;
                //    }

                //}
            }
            catch (Exception ex)
            {
                if (dtRespMsg == null)
                {
                    dtRespMsg = new DataTableResponseMessage();
                }
                dtRespMsg.LogMessage   = string.Format("Error processing file: {0}  with Exception - {1}", inputFile, ex.Message);
                dtRespMsg.ErrorMessage = string.Format("Error processing file: {0}  with Exception - {1}", inputFile, ex.Message);
            }

            if (pluginHost != null)
            {
                pluginHost.Unload();
            }
            return(dtRespMsg);



            //using (var fs = new FileStream(processorsPath, FileMode.Open, FileAccess.Read))
            //{
            //    try
            //    {
            //        var context = new CollectibleAssemblyLoadContext(processorsPath);
            //        var assembly = context.LoadFromStream(fs);
            //        //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)
            //                {
            //                    if (string.Compare(result.id, processorID, true) == 0)
            //                    {
            //                        result.input_file = inputFile;
            //                        //result.OutputFile = outputFile;
            //                        dtRespMsg = result.Execute();
            //                        break;
            //                    }
            //                }
            //            }
            //        }
            //        context.Unload();
            //        GC.Collect();
            //        GC.WaitForPendingFinalizers();

            //    }
            //    //Handle unloadable libraries
            //    catch (Exception ex)
            //    {
            //        if (dtRespMsg == null)
            //            dtRespMsg = new DataTableResponseMessage();
            //        dtRespMsg.LogMessage = string.Format("Error processing file: {0}  with Exception - {1}", inputFile,  ex.Message);
            //    }
            //    return dtRespMsg;
        }