- Timestamp:
- 11/12/09 17:45:45 (15 years ago)
- Location:
- branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure
- Files:
-
- 4 added
- 5 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Attributes/ApplicationAttribute.cs
r2475 r2488 30 30 /// </summary> 31 31 [AttributeUsage(AttributeTargets.Class)] 32 public class Application DescriptionAttribute : System.Attribute {32 public class ApplicationAttribute : System.Attribute { 33 33 private string name; 34 34 /// <summary> … … 40 40 } 41 41 42 private string version;43 /// <summary>44 /// Gets or sets the version of the application.45 /// </summary>46 public string Version {47 get { return version; }48 set { version = value; }49 }42 //private string version; 43 ///// <summary> 44 ///// Gets or sets the version of the application. 45 ///// </summary> 46 //public string Version { 47 // get { return version; } 48 // set { version = value; } 49 //} 50 50 51 51 private string description; … … 68 68 69 69 /// <summary> 70 /// Initializes a new instance of <see cref="Application DescriptionAttribute"/>.70 /// Initializes a new instance of <see cref="ApplicationAttribute"/>. 71 71 /// <param name="name">Name of the application</param> 72 72 /// </summary> 73 public Application DescriptionAttribute(string name)73 public ApplicationAttribute(string name) 74 74 : this(name, "") { 75 75 } 76 76 77 77 /// <summary> 78 /// Initializes a new instance of <see cref="Application DescriptionAttribute"/>.78 /// Initializes a new instance of <see cref="ApplicationAttribute"/>. 79 79 /// <param name="name">Name of the application</param> 80 80 /// <param name="description">Description of the application</param> 81 81 /// </summary> 82 public Application DescriptionAttribute(string name, string description)83 : this(name, description, "") {82 public ApplicationAttribute(string name, string description) 83 : this(name, description, false) { 84 84 } 85 85 86 /// <summary>87 /// Initializes a new instance of <see cref="ApplicationDescriptionAttribute"/>.88 /// <param name="name">Name of the application</param>89 /// <param name="description">Description of the application</param>90 /// <param name="version">Version string of the application</param>91 /// </summary>92 public ApplicationDescriptionAttribute(string name, string description, string version)93 : this(name, description, version, false) {94 }86 ///// <summary> 87 ///// Initializes a new instance of <see cref="ApplicationAttribute"/>. 88 ///// <param name="name">Name of the application</param> 89 ///// <param name="description">Description of the application</param> 90 ///// <param name="version">Version string of the application</param> 91 ///// </summary> 92 //public ApplicationAttribute(string name, string description, string version) 93 // : this(name, description, version, false) { 94 //} 95 95 96 96 /// <summary> 97 /// Initializes a new instance of <see cref="Application DescriptionAttribute"/>.97 /// Initializes a new instance of <see cref="ApplicationAttribute"/>. 98 98 /// <param name="name">Name of the application</param> 99 99 /// <param name="description">Description of the application</param> … … 101 101 /// <param name="restartOnErrors">Flag that indicates if the application should be restarted on exceptions (for services)</param> 102 102 /// </summary> 103 public Application DescriptionAttribute(string name, string description, string version, bool restartOnErrors) {103 public ApplicationAttribute(string name, string description, bool restartOnErrors) { 104 104 this.name = name; 105 this.version = version;106 105 this.description = description; 107 106 this.restartOnErrors = restartOnErrors; -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/Attributes/PluginAttribute.cs
r2481 r2488 30 30 /// </summary> 31 31 [AttributeUsage(AttributeTargets.Class)] 32 public class Plugin DescriptionAttribute : System.Attribute {32 public class PluginAttribute : System.Attribute { 33 33 private string name; 34 34 /// <summary> … … 49 49 //} 50 50 51 //private string description;52 /// //<summary>53 /// //Gets or sets the description of the plugin.54 /// //</summary>55 //public string Description {56 //get { return description; }57 //set { description = value; }58 //}51 private string description; 52 /// <summary> 53 /// Gets or sets the description of the plugin. 54 /// </summary> 55 public string Description { 56 get { return description; } 57 // set { description = value; } 58 } 59 59 60 60 /// <summary> 61 /// Initializes a new instance of <see cref="Plugin DescriptionAttribute"/>.61 /// Initializes a new instance of <see cref="PluginAttribute"/>. 62 62 /// <param name="name">Name of the plugin</param> 63 63 /// </summary> 64 public Plugin DescriptionAttribute(string name) {65 this.name = name;64 public PluginAttribute(string name) 65 : this(name, "") { 66 66 } 67 67 68 ///// <summary> 69 ///// Initializes a new instance of <see cref="PluginDescriptionAttribute"/>. 70 ///// <param name="name">Name of the plugin</param> 71 ///// <param name="description">Description of the plugin</param> 72 ///// </summary> 73 //public PluginDescriptionAttribute(string name, string description) 74 // : this(name, description, "") { 75 //} 68 /// <summary> 69 /// Initializes a new instance of <see cref="PluginAttribute"/>. 70 /// <param name="name">Name of the plugin</param> 71 /// <param name="description">Description of the plugin</param> 72 /// </summary> 73 public PluginAttribute(string name, string description) { 74 this.name = name; 75 this.description = description; 76 } 76 77 77 78 ///// <summary> -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/BaseClasses/ApplicationBase.cs
r2475 r2488 29 29 /// Default implementation for the IApplication interface. 30 30 /// </summary> 31 internalabstract class ApplicationBase : IApplication {31 public abstract class ApplicationBase : IApplication { 32 32 /// <summary> 33 33 /// Initializes a new instance of <see cref="ApplicationBase"/>. … … 35 35 public ApplicationBase() { } 36 36 37 private Application DescriptionAttribute ApplicationDescriptionAttribute {37 private ApplicationAttribute ApplicationAttribute { 38 38 get { 39 object[] app DescAttributes = this.GetType().GetCustomAttributes(typeof(ApplicationDescriptionAttribute), false);39 object[] appAttributes = this.GetType().GetCustomAttributes(typeof(ApplicationAttribute), false); 40 40 41 41 // exactly one attribute of the type ClassInfoAttribute must be given 42 if (app DescAttributes.Length != 1) {43 throw new InvalidPluginException("Found multiple Application DescriptionAttributes on type " + this.GetType());42 if (appAttributes.Length != 1) { 43 throw new InvalidPluginException("Found multiple ApplicationAttributes on type " + this.GetType()); 44 44 } 45 45 46 return (Application DescriptionAttribute)appDescAttributes[0];46 return (ApplicationAttribute)appAttributes[0]; 47 47 } 48 48 } … … 54 54 /// </summary> 55 55 public string Name { 56 get { return Application DescriptionAttribute.Name; }56 get { return ApplicationAttribute.Name; } 57 57 } 58 58 … … 62 62 public Version Version { 63 63 get { 64 var appDescAttribute = ApplicationDescriptionAttribute; 65 // if the version is not explicitly set in the attribute then the version of the assembly is used as default 66 if (string.IsNullOrEmpty(appDescAttribute.Version)) { 67 return this.GetType().Assembly.GetName().Version; 68 } else { 69 return new Version(appDescAttribute.Version); 70 } 64 return this.GetType().Assembly.GetName().Version; 71 65 } 72 66 } … … 77 71 public string Description { 78 72 get { 79 var appDescAttribute = Application DescriptionAttribute;73 var appDescAttribute = ApplicationAttribute; 80 74 // if the description is not explicitly set in the attribute then the name of the application is used as default 81 75 if (string.IsNullOrEmpty(appDescAttribute.Description)) { … … 92 86 public bool RestartOnErrors { 93 87 get { 94 return Application DescriptionAttribute.RestartOnErrors;88 return ApplicationAttribute.RestartOnErrors; 95 89 } 96 90 } -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/BaseClasses/PluginBase.cs
r2481 r2488 37 37 public PluginBase() { } 38 38 39 private Plugin DescriptionAttribute PluginDescriptionAttribute {39 private PluginAttribute PluginAttribute { 40 40 get { 41 object[] pluginAttributes = this.GetType().GetCustomAttributes(typeof(Plugin DescriptionAttribute), false);41 object[] pluginAttributes = this.GetType().GetCustomAttributes(typeof(PluginAttribute), false); 42 42 // exactly one attribute of the type PluginDescriptionAttribute must be given 43 43 if (pluginAttributes.Length != 1) { 44 throw new InvalidPluginException("Found multiple Plugin DescriptionAttributes on type " + this.GetType());44 throw new InvalidPluginException("Found multiple PluginAttributes on type " + this.GetType()); 45 45 } 46 return (Plugin DescriptionAttribute)pluginAttributes[0];46 return (PluginAttribute)pluginAttributes[0]; 47 47 } 48 48 } … … 52 52 public string Name { 53 53 get { 54 return Plugin DescriptionAttribute.Name;54 return PluginAttribute.Name; 55 55 } 56 56 } -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/ControlManager.cs
r2481 r2488 38 38 public static IControlManager Manager { 39 39 get { return controlManager; } 40 set { controlManager = value; } 40 } 41 42 public static void RegisterManager(IControlManager manager) { 43 if (controlManager != null) throw new InvalidOperationException("An control manager has already been set."); 44 controlManager = manager; 41 45 } 42 46 } -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/DiscoveryService.cs
r2481 r2488 24 24 using System.Text; 25 25 using System.Reflection; 26 using System.Linq; 26 27 27 28 namespace HeuristicLab.PluginInfrastructure { … … 30 31 /// </summary> 31 32 public class DiscoveryService { 33 //internal static IEnumerable<IPluginDescription> plugins; 32 34 33 //public PluginDescription[]Plugins {35 //public IEnumerable<IPluginDescription> Plugins { 34 36 // get { 35 // PluginInfo[] plugins = new PluginInfo[PluginManager.Manager.LoadedPlugins.Count]; 36 // PluginManager.Manager.LoadedPlugins.CopyTo(plugins, 0); 37 // return plugins; 37 // return DiscoveryService.plugins; 38 38 // } 39 39 //} 40 40 41 41 /// <summary> 42 /// Finds all types that are subtypes or equal to the specified type.42 /// Creates an instance of all types that are subtypes or the same type of the specified type and declared in <paramref name="plugin"/> 43 43 /// </summary> 44 /// <param name="type">Most general type for which to find matching types.</param> 45 /// <returns>The found types as array.</returns> 46 public Type[] GetTypes(Type type) { 47 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); 48 List<Type> types = new List<Type>(); 49 foreach (Assembly asm in assemblies) { 50 Array.ForEach<Type>(GetTypes(type, asm), delegate(Type t) { 51 types.Add(t); 52 }); 53 } 54 return types.ToArray(); 44 /// <typeparam name="T">Most general type.</typeparam> 45 /// <returns>Enumerable of the created instances.</returns> 46 public IEnumerable<T> GetInstances<T>(IPluginDescription plugin) where T : class { 47 return from t in GetTypes(typeof(T), plugin) 48 where !t.IsAbstract && !t.IsInterface && !t.HasElementType 49 select (T)Activator.CreateInstance(t); 55 50 } 56 57 51 /// <summary> 58 52 /// Creates an instance of all types that are subtypes or the same type of the specified type 59 53 /// </summary> 60 54 /// <typeparam name="T">Most general type.</typeparam> 61 /// <returns>The created instances as array.</returns> 62 public T[] GetInstances<T>() where T : class { 63 Type[] types = GetTypes(typeof(T)); 64 List<T> instances = new List<T>(); 65 foreach (Type t in types) { 66 if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) { 67 instances.Add((T)Activator.CreateInstance(t)); 68 } 69 } 70 return instances.ToArray(); 55 /// <returns>Enumerable of the created instances.</returns> 56 public IEnumerable<T> GetInstances<T>() where T : class { 57 return from i in GetInstances(typeof(T)) 58 select (T)i; 71 59 } 72 60 … … 75 63 /// </summary> 76 64 /// <typeparam name="type">Most general type.</typeparam> 77 /// <returns>The created instances as array.</returns> 78 public object[] GetInstances(Type type) { 79 Type[] types = GetTypes(type); 80 List<object> instances = new List<object>(); 81 foreach (Type t in types) { 82 if (!t.IsAbstract && !t.IsInterface && !t.HasElementType) { 83 instances.Add(Activator.CreateInstance(t)); 84 } 85 } 86 return instances.ToArray(); 65 /// <returns>Enumerable of the created instances.</returns> 66 public IEnumerable<object> GetInstances(Type type) { 67 return from t in GetTypes(type) 68 where !t.IsAbstract && !t.IsInterface && !t.HasElementType 69 select Activator.CreateInstance(t); 87 70 } 88 71 89 ///// <summary> 90 ///// Finds all types that are subtypes or equal to the specified type if they are part of the given 91 ///// <paramref name="plugin"/>. 92 ///// </summary> 93 ///// <param name="type">Most general type for which to find matching types.</param> 94 ///// <param name="plugin">The plugin the subtypes must be part of.</param> 95 ///// <returns>The found types as array.</returns> 96 //public Type[] GetTypes(Type type, PluginInfo plugin) { 97 // Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); 98 // List<Type> types = new List<Type>(); 99 // foreach (Assembly asm in assemblies) { 100 // if (plugin.Assemblies.Contains(asm.Location)) { 101 // Array.ForEach<Type>(GetTypes(type, asm), delegate(Type t) { 102 // types.Add(t); 103 // }); 104 // } 105 // } 72 /// <summary> 73 /// Finds all types that are subtypes or equal to the specified type. 74 /// </summary> 75 /// <param name="type">Most general type for which to find matching types.</param> 76 /// <returns>Enumerable of the discovered types.</returns> 77 public IEnumerable<Type> GetTypes(Type type) { 78 return from asm in AppDomain.CurrentDomain.GetAssemblies() 79 from t in GetTypes(type, asm) 80 select t; 81 } 106 82 107 // return types.ToArray(); 108 //} 83 /// <summary> 84 /// Finds all types that are subtypes or equal to the specified type if they are part of the given 85 /// <paramref name="plugin"/>. 86 /// </summary> 87 /// <param name="type">Most general type for which to find matching types.</param> 88 /// <param name="plugin">The plugin the subtypes must be part of.</param> 89 /// <returns>Enumerable of the discovered types.</returns> 90 public IEnumerable<Type> GetTypes(Type type, IPluginDescription pluginDescription) { 91 return from asm in AppDomain.CurrentDomain.GetAssemblies() 92 where pluginDescription.Assemblies.Contains(asm.Location) 93 from t in GetTypes(type, asm) 94 select t; 95 } 109 96 110 97 ///// <summary> … … 130 117 /// <param name="type">Most general type we want to find.</param> 131 118 /// <param name="assembly">Assembly that should be searched for types.</param> 132 /// <returns>The found types as array.</returns> 133 internal Type[] GetTypes(Type type, Assembly assembly) { 134 List<Type> types = new List<Type>(); 135 foreach (Type t in assembly.GetTypes()) { 136 if (type.IsAssignableFrom(t)) { 137 types.Add(t); 138 } 139 } 140 return types.ToArray(); 119 /// <returns>Enumerable of the discovered types.</returns> 120 private IEnumerable<Type> GetTypes(Type type, Assembly assembly) { 121 return from t in assembly.GetTypes() 122 where type.IsAssignableFrom(t) 123 select t; 141 124 } 142 125 -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/HeuristicLab.PluginInfrastructure.csproj
r2481 r2488 86 86 </ItemGroup> 87 87 <ItemGroup> 88 <Compile Include="Attributes\Application DescriptionAttribute.cs" />88 <Compile Include="Attributes\ApplicationAttribute.cs" /> 89 89 <Compile Include="Attributes\AssemblyBuildDateAttribute.cs" /> 90 <Compile Include="Attributes\PluginAttribute.cs" /> 90 91 <Compile Include="Attributes\PluginDependencyAttribute.cs" /> 91 <Compile Include="Attributes\PluginDescriptionAttribute.cs" />92 92 <Compile Include="Attributes\PluginFileAttribute.cs" /> 93 93 <Compile Include="BaseClasses\ApplicationBase.cs" /> 94 94 <Compile Include="BaseClasses\PluginBase.cs" /> 95 <Compile Include="Interfaces\IApplicationManager.cs" /> 96 <Compile Include="Interfaces\IApplicationDescription.cs" /> 95 97 <Compile Include="Interfaces\IApplication.cs" /> 96 98 <Compile Include="Interfaces\IControl.cs" /> 97 99 <Compile Include="Interfaces\IControlManager.cs" /> 98 100 <Compile Include="Interfaces\IPlugin.cs" /> 99 <Compile Include="DiscoveryService.cs" />100 101 <Compile Include="ControlManager.cs" /> 102 <Compile Include="Interfaces\IPluginDescription.cs" /> 101 103 <Compile Include="InvalidPluginException.cs" /> 104 <Compile Include="PluginDescriptionIterator.cs" /> 105 <Compile Include="ApplicationManager.cs" /> 106 <Compile Include="PluginState.cs" /> 102 107 <Compile Include="Properties\AssemblyInfo.cs" /> 103 108 <EmbeddedResource Include="Properties\Resources.resx"> -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/PluginDescriptionIterator.cs
r2481 r2488 24 24 using System.Text; 25 25 26 namespace HeuristicLab.PluginInfrastructure .Manager{26 namespace HeuristicLab.PluginInfrastructure { 27 27 public static class PluginDescriptionIterator { 28 public static IEnumerable< PluginDescription> IterateInDependencyOrder(IEnumerable<PluginDescription> pluginDescriptions) {28 public static IEnumerable<IPluginDescription> IterateInDependencyOrder(IEnumerable<IPluginDescription> pluginDescriptions) { 29 29 // list to make sure we yield each description only once 30 List< PluginDescription> yieldedDescriptions = new List<PluginDescription>();30 List<IPluginDescription> yieldedDescriptions = new List<IPluginDescription>(); 31 31 foreach (var desc in pluginDescriptions) { 32 32 foreach (var dependency in IterateInDependencyOrder(desc.Dependencies)) { … … 35 35 yield return dependency; 36 36 } 37 if (!yieldedDescriptions.Contains(desc)) {38 yieldedDescriptions.Add(desc);39 yield return desc;40 }37 } 38 if (!yieldedDescriptions.Contains(desc)) { 39 yieldedDescriptions.Add(desc); 40 yield return desc; 41 41 } 42 42 } -
branches/PluginInfrastructure Refactoring/HeuristicLab.PluginInfrastructure/PluginState.cs
r2481 r2488 24 24 using System.Text; 25 25 26 namespace HeuristicLab.PluginInfrastructure .Manager{26 namespace HeuristicLab.PluginInfrastructure { 27 27 [Serializable] 28 28 public enum PluginState {
Note: See TracChangeset
for help on using the changeset viewer.