Example #1
0
 private static void BuildIndex(string pluginPath, DataTable dtExporters, DataTable dtImporters)
 {
     if (!Directory.Exists(pluginPath))
     {
         return;
     }
     string[] files = Directory.GetFiles(pluginPath, "*.dll", SearchOption.AllDirectories);
     string[] array = files;
     for (int i = 0; i < array.Length; i++)
     {
         string   filename      = array[i];
         Assembly assembly      = Assembly.Load(TransferContainer.LoadPluginFile(filename));
         Type[]   exportedTypes = assembly.GetExportedTypes();
         for (int j = 0; j < exportedTypes.Length; j++)
         {
             Type type = exportedTypes[j];
             if (type.BaseType != null)
             {
                 if (type.BaseType.Name == "ExportAdapter")
                 {
                     TransferContainer.AddToExportIndex(type, filename, dtExporters);
                 }
                 else
                 {
                     if (type.BaseType.Name == "ImportAdapter")
                     {
                         TransferContainer.AddToImportIndex(type, filename, dtImporters);
                     }
                 }
             }
         }
     }
 }
Example #2
0
        private static Type GetPlugin(string fullName, string tableName)
        {
            DataSet dataSet = TransferContainer.TransferCache.Get(transferIndexesCacheKey) as DataSet;

            DataRow[] array = dataSet.Tables[tableName].Select("fullName='" + fullName.ToLower() + "'");
            if (array.Length == 0 || !File.Exists(array[0]["filePath"].ToString()))
            {
                return(null);
            }
            Assembly assembly = Assembly.Load(TransferContainer.LoadPluginFile(array[0]["filePath"].ToString()));

            return(assembly.GetType(fullName, false, true));
        }
Example #3
0
        public static ExportAdapter GetExporter(string fullName, params object[] exportParams)
        {
            if (string.IsNullOrEmpty(fullName))
            {
                return(null);
            }
            Type exporter = TransferContainer.Instance().GetExporter(fullName);

            if (exporter == null)
            {
                return(null);
            }
            if (exportParams != null && exportParams.Length > 0)
            {
                return(Activator.CreateInstance(exporter, exportParams) as ExportAdapter);
            }
            return(Activator.CreateInstance(exporter) as ExportAdapter);
        }
Example #4
0
 internal static TransferContainer Instance()
 {
     if (TransferContainer._instance == null)
     {
         object lockHelper;
         Monitor.Enter(lockHelper = TransferContainer.LockHelper);
         try
         {
             if (TransferContainer._instance == null)
             {
                 TransferContainer._instance = new TransferContainer();
             }
         }
         finally
         {
             Monitor.Exit(lockHelper);
         }
     }
     TransferContainer.Init();
     return(TransferContainer._instance);
 }
Example #5
0
        private static void Init()
        {
            if (TransferContainer.TransferCache.Get(transferIndexesCacheKey) != null)
            {
                return;
            }
            string    text       = HttpContext.Current.Request.MapPath("~/plugins/transfer");
            DataSet   dataSet    = new DataSet();
            DataTable dataTable  = new DataTable("Exporters");
            DataTable dataTable2 = new DataTable("Importers");

            TransferContainer.InitTable(dataTable);
            TransferContainer.InitTable(dataTable2);
            dataTable.Columns.Add(new DataColumn("exportToName"));
            dataTable.Columns.Add(new DataColumn("exportToVersion"));
            dataTable2.Columns.Add(new DataColumn("importToName"));
            dataTable2.Columns.Add(new DataColumn("importToVersion"));
            dataSet.Tables.Add(dataTable);
            dataSet.Tables.Add(dataTable2);
            TransferContainer.BuildIndex(text, dataTable, dataTable2);
            TransferContainer.TransferCache.Insert(transferIndexesCacheKey, dataSet, new CacheDependency(text));
        }
Example #6
0
        public static Dictionary <string, string> GetImportAdapters(Target importTo, string sourceName)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            DataRow[] importerList = TransferContainer.Instance().GetImporterList(sourceName, importTo.Name);
            if (importerList == null || importerList.Length == 0)
            {
                return(dictionary);
            }
            string value = null;
            int    num   = 0;

            do
            {
                Version v = new Version(importerList[num]["importToVersion"].ToString());
                if (v <= importTo.Version)
                {
                    value = importerList[num]["importToVersion"].ToString();
                }
                num++;
            }while (string.IsNullOrEmpty(value) && num < importerList.Length);
            if (!string.IsNullOrEmpty(value))
            {
                DataRow[] array = importerList;
                for (int i = 0; i < array.Length; i++)
                {
                    DataRow dataRow = array[i];
                    string  text    = dataRow["importToVersion"].ToString();
                    if (text.Equals(value))
                    {
                        dictionary.Add(dataRow["fullName"].ToString(), dataRow["sourceName"].ToString() + dataRow["sourceVersion"].ToString());
                    }
                }
            }
            return(dictionary);
        }
Example #7
0
 internal Type GetImporter(string fullName)
 {
     return(TransferContainer.GetPlugin(fullName, "Importers"));
 }