예제 #1
0
 private void ProcessDllRepository(DirectoryInfo dllDirectory)
 {
     foreach (FileInfo file in dllDirectory.GetFiles("*.dll"))
     {
         Assembly assembly = Assembly.LoadFile(file.FullName);
         foreach (Type type in assembly.GetTypes())
         {
             if (typeof(IProductImporter).IsAssignableFrom(type) && !type.IsInterface)
             {
                 ReflectionComboItem comboItemImporter = new ReflectionComboItem()
                 {
                     LoadClass = type.FullName, AssemblyPath = file.FullName, ShowName = GetImporterType(type)
                 };
                 productImporterTypeComboBox.Items.Add(comboItemImporter);
             }
         }
     }
 }
예제 #2
0
        private void invokeProductImporterButton_Click(object sender, EventArgs e)
        {
            logListBox.Items.Clear();
            if (productImporterTypeComboBox.SelectedItem != null)
            {
                ReflectionComboItem selectedImporter = (ReflectionComboItem)productImporterTypeComboBox.SelectedItem;

                try
                {
                    string assemblyPath = selectedImporter.AssemblyPath;
                    string className    = selectedImporter.LoadClass;

                    Assembly assembly = Assembly.LoadFile(assemblyPath);
                    Type     type     = assembly.GetType(className);

                    MethodInfo method   = type.GetMethod("LoadProducts");
                    var        instance = Activator.CreateInstance(type);

                    object productsLoaded = method.Invoke(instance, null);

                    ICollection <ProductToImport> productsToImport = (ICollection <ProductToImport>)productsLoaded;

                    if (productsToImport != null)
                    {
                        ImportProduct(productsToImport);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Error interno de libreria, seleccione otra.", "ERROR");
                    productImporterTypeComboBox.Items.Remove(selectedImporter);
                }
            }
            else
            {
                MessageBox.Show("Debe seleccionar un tipo de importador");
            }
        }