public void LoadPlugins() { string[] dllFileNames = null; if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory)) { dllFileNames = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll"); ICollection <Assembly> assemblies = new List <Assembly>(dllFileNames.Length); foreach (string dllFile in dllFileNames) { AssemblyName an = AssemblyName.GetAssemblyName(dllFile); Assembly assembly = Assembly.Load(an); assemblies.Add(assembly); } Type pluginType = typeof(ISlideshow.ISlideshow); ICollection <Type> pluginTypes = new List <Type>(); foreach (Assembly assembly in assemblies) { if (assembly != null) { Type[] types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsInterface || type.IsAbstract) { continue; } else { if (type.GetInterface(pluginType.FullName) != null) { pluginTypes.Add(type); } } } } } foreach (Type type in pluginTypes) { ISlideshow.ISlideshow plugin = (ISlideshow.ISlideshow)Activator.CreateInstance(type); plugins.Add(plugin.Name, plugin); } List <string> pluginnames = new List <string>(); foreach (var plugin in plugins) { pluginnames.Add(plugin.Key); } effectComboBox.DataContext = plugins; MenuItem_Show_Click.DataContext = plugins; } }
private void MenuItem_Click_Start(object sender, RoutedEventArgs e) { if (plugins.Count > 0) { ISlideshow.ISlideshow tmp = plugins[(string)((System.Windows.Controls.MenuItem)sender).Header]; StartSlidesShow(tmp); } else { System.Windows.MessageBox.Show("There is no plugin or image", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void StartSlidesShow(ISlideshow.ISlideshow plugin) { if (this.DataContext is List <ImageInfo> && plugins.Count > 0) { if (((List <ImageInfo>) this.DataContext).Count > 0) { SlideWindow slideWindow = new SlideWindow(plugin); slideWindow.ShowDialog(); } else { System.Windows.MessageBox.Show("There is no plugin or image", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { System.Windows.MessageBox.Show("There is no plugin or image", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } }