Esempio n. 1
0
        public DataTableResponseMessage VerifyInputFile()
        {
            DataTableResponseMessage rm = new DataTableResponseMessage();

            //Verify that the file exists
            if (!File.Exists(input_file))
            {
                rm.ErrorMessage = string.Format("Input data file not found: {0}", input_file);
                rm.LogMessage   = string.Format("Input data file not found: {0}", input_file);
                return(rm);
            }

            //Verify the file type extension is correct
            FileInfo fi  = new FileInfo(input_file);
            string   ext = fi.Extension;

            if (string.Compare(ext, file_type, StringComparison.OrdinalIgnoreCase) != 0)
            {
                rm.ErrorMessage = string.Format("Input data file not correct file type. Need {0} , found {1}", file_type, ext);
                rm.LogMessage   = string.Format("Input data file not correct file type: {0}", input_file);
                return(rm);
            }

            //Nothing to see here
            return(null);
        }
Esempio 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;
        }