private void plus_Click(object sender, EventArgs e) { openFileDialog1.InitialDirectory = "D:\\учеба\\4 семестр\\ООТПиСП\\3 лаба\\WindowsFormsApplication1\\WindowsFormApplication\\bin\\Debug"; openFileDialog1.Filter = "ZIP files (*.zip)|*.zip"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { String compressedFile = openFileDialog1.FileName; // сжатый файл String targetFile = compressedFile.Substring(0, compressedFile.LastIndexOf(".")) + ".dll"; // восстановленный файл // чтение из сжатого файла archive.Strategy = new UnzipOperation(); archive.operate(compressedFile, targetFile); Assembly asm = Assembly.Load(File.ReadAllBytes(targetFile)); type = asm.GetTypes().Where(t => (t.GetInterface("ICarInt") != null)).First(); if (plugins.ContainsKey(type.Name.ToLower())) { MessageBox.Show("Plugin already exist"); return; } plugins.Add(type.Name.ToLower(), type); brand.Items.Add(type.Name.ToLower()); asms[type.Name.ToLower()] = asm; ICarInt plug = (ICarInt)Activator.CreateInstance(plugins[type.Name.ToLower()]); plug.Show(); } }
public NewCar() { InitializeComponent(); CenterToScreen(); plugins.Add("audi", typeof(Audi)); plugins.Add("peel", typeof(PeelP50)); plugins.Add("nissan", typeof(Nissan)); plugins.Add("tesla", typeof(Tesla)); asms["citroen"] = Assembly.Load(File.ReadAllBytes("CitroenC5.dll")); type = asms["citroen"].GetTypes().Where(t => (t.GetInterface("ICarInt") != null)).First(); plugins.Add(type.Name.ToLower(), type); brand.Items.Add(type.Name.ToLower()); //ICarInt plug = (ICarInt)Activator.CreateInstance(plugins["citroen"], 4, "citroen", "diesel", 120); //plug.Show(); ICarInt plug1 = (ICarInt)Activator.CreateInstance(plugins["citroen"]); plug1.Show(); asms["zotye"] = Assembly.Load(File.ReadAllBytes("ZotyeE200.dll")); type = asms["zotye"].GetTypes().Where(t => (t.GetInterface("ICarInt") != null)).First(); plugins.Add(type.Name.ToLower(), type); brand.Items.Add(type.Name.ToLower()); ICarInt plug2 = (ICarInt)Activator.CreateInstance(plugins["zotye"]); plug2.Show(); }
public Form1(ICarInt plugin) { InitializeComponent(); this.plugin = plugin; }