From: <tor...@us...> - 2008-06-11 14:17:47
|
Revision: 245 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=245&view=rev Author: torax777 Date: 2008-06-11 07:17:19 -0700 (Wed, 11 Jun 2008) Log Message: ----------- PluginsLoader works now with both interface and abstract class derived classes. Renamed source file from PluginLoader.cs to PluginsLoader.cs Modified Paths: -------------- ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginsFramework.csproj Added Paths: ----------- ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginsLoader.cs Removed Paths: ------------- ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginLoader.cs Deleted: ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginLoader.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginLoader.cs 2008-06-11 09:15:49 UTC (rev 244) +++ ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginLoader.cs 2008-06-11 14:17:19 UTC (rev 245) @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.IO; - -namespace AcmContester.Plugins.PluginsFramework -{ - public static class PluginsLoader<T> where T : class - { - /// <summary> - /// Try to load all the instances of type T in all the DLLs, - /// found at path - /// </summary> - /// <param name="path">Path where to find appropriate DLLs</param> - /// <returns>List of all instaces found</returns> - public static List<T> Load(string path) - { - List<T> plugins = new List<T>(); - if (!Directory.Exists(path)) - throw new ArgumentException("Specified path does not exists!"); - string[] allFiles = Directory.GetFiles(path, "*.dllx", SearchOption.TopDirectoryOnly); - foreach (string file in allFiles) - { - ScanAndLoad(file, plugins); - } - return plugins; - } - - /// <summary> - /// Load all instances of type T in specified file and - /// add them to provided list - /// </summary> - /// <param name="filename">Which file to scan</param> - /// <param name="lst">Where to add found objects</param> - private static void ScanAndLoad(string filename, List<T> lst) - { - Assembly assembly = Assembly.LoadFrom(filename); - if (assembly != null) - { - Type[] types = assembly.GetExportedTypes(); - - foreach (Type t in types) - { - try - { - if (t.IsClass && !t.IsAbstract) - if (t.GetInterface(typeof(T).FullName) != null || t.GetMember(typeof(T).FullName) != null) - lst.Add((T)Activator.CreateInstance(t)); - } - catch (System.Reflection.TargetInvocationException ex) - { - //throw ex; - } - catch (System.MissingMethodException ex) - { - //throw ex; - } - catch (System.InvalidCastException ex) - { - //throw ex; - } - catch (Exception ex) - { - //throw ex; - } - } - } - } - } -} Modified: ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginsFramework.csproj =================================================================== --- ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginsFramework.csproj 2008-06-11 09:15:49 UTC (rev 244) +++ ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginsFramework.csproj 2008-06-11 14:17:19 UTC (rev 245) @@ -32,7 +32,7 @@ </ItemGroup> <ItemGroup> <Compile Include="BaseMediatorPlugin.cs" /> - <Compile Include="PluginLoader.cs" /> + <Compile Include="PluginsLoader.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> Added: ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginsLoader.cs =================================================================== --- ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginsLoader.cs (rev 0) +++ ACMServer/trunk/ACMServer/Plugin/PluginsFramework/PluginsLoader.cs 2008-06-11 14:17:19 UTC (rev 245) @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.IO; + +namespace AcmContester.Plugins.PluginsFramework +{ + public static class PluginsLoader<T> where T : class + { + /// <summary> + /// Try to load all the instances of type T in all the DLLs, + /// found at path + /// </summary> + /// <param name="path">Path where to find appropriate DLLs</param> + /// <returns>List of all instaces found</returns> + public static List<T> Load(string path) + { + List<T> plugins = new List<T>(); + if (!Directory.Exists(path)) + throw new ArgumentException("Specified path does not exists!"); + string[] allFiles = Directory.GetFiles(path, "*.dllx", SearchOption.TopDirectoryOnly); + foreach (string file in allFiles) + { + ScanAndLoad(file, plugins); + } + return plugins; + } + + /// <summary> + /// Load all instances of type T in specified file and + /// add them to provided list + /// </summary> + /// <param name="filename">Which file to scan</param> + /// <param name="lst">Where to add found objects</param> + private static void ScanAndLoad(string filename, List<T> lst) + { + Assembly assembly = Assembly.LoadFrom(filename); + if (assembly != null) + { + Type[] types = assembly.GetExportedTypes(); + + foreach (Type t in types) + { + try + { + if (t.IsClass && !t.IsAbstract) + if (t.GetInterface(typeof(T).FullName) != null || t.IsSubclassOf(typeof(T))) + lst.Add((T)Activator.CreateInstance(t)); + } + catch (System.Reflection.TargetInvocationException ex) + { + //throw ex; + } + catch (System.MissingMethodException ex) + { + //throw ex; + } + catch (System.InvalidCastException ex) + { + //throw ex; + } + catch (Exception ex) + { + //throw ex; + } + } + } + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |