/// <summary> /// Adds the contents of another 'PluginCollection' at the end of this instance. /// </summary> /// <param name='pluValue'> /// A 'PluginCollection' containing the objects to add to the collection. /// </param> public void AddRange(PluginCollection pluValue) { for (int intCounter = 0; (intCounter < pluValue.Count); intCounter = (intCounter + 1)) { this.Add(pluValue[intCounter]); } }
//Loads the possible plugin assemblies in a separate AppDomain //in order to allow unloading of unneeded assemblies public void LoadPlugins() { m_Plugins = new PluginCollection(); if (SearchDirectory == null || !Directory.Exists(SearchDirectory)) { throw new DirectoryNotFoundException("Could not find plugin directory"); } //The class actually created a new instance of the same class //only in a different AppDomain. It then passes it all the needed //parameters such as search path and file extensions. AppDomain domain = AppDomain.CreateDomain("DynamicPluginLoader"); Assembly asm = domain.Load(Assembly.GetExecutingAssembly().FullName); DynamicFindPluginProvider finder = (DynamicFindPluginProvider )asm.CreateInstance(typeof(DynamicFindPluginProvider).ToString()); //DynamicFindPluginProvider finder = (DynamicFindPluginProvider )domain.CreateInstanceFromAndUnwrap(,typeof(DynamicFindPluginProvider).ToString() ); finder.FileExtensionFilter = this.FileExtensionFilter; finder.SearchDirectory = this.SearchDirectory; ArrayList FoundPluginTypes = finder.SearchPath(this.SearchDirectory); AppDomain.Unload(domain); foreach (Type t in FoundPluginTypes) { try { if (t.IsAbstract) { continue; } //do not instantiate if this type has the "GenericPlugin" attribute object[] customAttribs = t.GetCustomAttributes(typeof(GenericPluginAttribute), false); if (customAttribs.Length > 0) { continue; } IPlugin plugin = (IPlugin )Activator.CreateInstance(t); m_Plugins.Add(plugin); } catch (Exception e) {} } }
//Loads the possible plugin assemblies in a separate AppDomain //in order to allow unloading of unneeded assemblies public void LoadPlugins() { m_Plugins= new PluginCollection(); if(SearchDirectory==null || !Directory.Exists(SearchDirectory)) { throw new DirectoryNotFoundException("Could not find plugin directory"); } //The class actually created a new instance of the same class //only in a different AppDomain. It then passes it all the needed //parameters such as search path and file extensions. AppDomain domain = AppDomain.CreateDomain("DynamicPluginLoader"); Assembly asm= domain.Load(Assembly.GetExecutingAssembly().FullName); DynamicFindPluginProvider finder = (DynamicFindPluginProvider )asm.CreateInstance(typeof(DynamicFindPluginProvider).ToString()); //DynamicFindPluginProvider finder = (DynamicFindPluginProvider )domain.CreateInstanceFromAndUnwrap(,typeof(DynamicFindPluginProvider).ToString() ); finder.FileExtensionFilter= this.FileExtensionFilter; finder.SearchDirectory = this.SearchDirectory; ArrayList FoundPluginTypes = finder.SearchPath(this.SearchDirectory); AppDomain.Unload(domain); foreach(Type t in FoundPluginTypes) { try { if(t.IsAbstract) { continue; } //do not instantiate if this type has the "GenericPlugin" attribute object[] customAttribs = t.GetCustomAttributes(typeof(GenericPluginAttribute),false); if(customAttribs.Length>0) { continue; } IPlugin plugin =(IPlugin )Activator.CreateInstance(t); m_Plugins.Add(plugin); } catch(Exception e){} } }
/// <summary> /// Initializes a new instance of 'PluginCollection' based on an already existing instance. /// </summary> /// <param name='pluValue'> /// A 'PluginCollection' from which the contents is copied /// </param> public PluginCollection(PluginCollection pluValue) { this.AddRange(pluValue); }
/// <summary> /// Enumerator constructor /// </summary> public IPluginEnumerator(PluginCollection pluMappings) { this.iEnLocal = ((System.Collections.IEnumerable)(pluMappings)); this.iEnBase = iEnLocal.GetEnumerator(); }