- Timestamp:
- 10/08/08 22:54:02 (16 years ago)
- Location:
- branches/HL-3.2-MonoMigration
- Files:
-
- 9 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/ApplicationInfo.cs
r242 r638 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Runtime.Serialization; 25 26 26 27 namespace HeuristicLab.PluginInfrastructure { … … 69 70 set { pluginType = value; } 70 71 } 72 73 public override string ToString() { 74 return Name + " " + Version + " " + Description + " " + pluginAssembly + " " + pluginType; 75 } 71 76 } 72 77 } -
branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/BaseClasses/ApplicationBase.cs
r242 r638 34 34 public ApplicationBase() { 35 35 ReadAttributes(); 36 Run(); 36 37 } 37 38 -
branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/ClassInfoAttribute.cs
r242 r638 59 59 60 60 public ClassInfoAttribute() {} 61 62 public ClassInfoAttribute(string name) { 63 Name = name; 64 } 61 65 } 62 66 } -
branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/DiscoveryService.cs
r29 r638 33 33 public PluginInfo[] Plugins { 34 34 get { 35 PluginInfo[] plugins = new PluginInfo[PluginManager.Manager.LoadedPlugins.Count]; 36 PluginManager.Manager.LoadedPlugins.CopyTo(plugins, 0); 37 return plugins; 35 try { 36 PluginInfo[] plugins = new PluginInfo[PluginManager.Manager.LoadedPlugins.Count]; 37 PluginManager.Manager.LoadedPlugins.CopyTo(plugins, 0); 38 return plugins; 39 } catch(Exception ex) { 40 Console.WriteLine(ex); 41 return new PluginInfo[] { }; 42 } 38 43 } 39 44 } -
branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/InvalidPluginException.cs
r96 r638 23 23 using System.Collections.Generic; 24 24 using System.Text; 25 using System.Runtime.Serialization; 25 26 26 27 namespace HeuristicLab.PluginInfrastructure { 28 [Serializable] 27 29 class InvalidPluginException : Exception { 30 public InvalidPluginException() : base() { } 31 32 public InvalidPluginException(SerializationInfo info, StreamingContext context) : base(info, context) { } 28 33 } 29 34 } -
branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/Loader.cs
r535 r638 98 98 return null; 99 99 } 100 100 }; 101 101 allPlugins.Clear(); 102 102 disabledPlugins.Clear(); … … 161 161 } 162 162 } 163 } catch(InvalidPluginException ex) { 164 PluginInfo info = new PluginInfo(); 165 AssemblyName name = assembly.GetName(); 166 info.Name = name.Name; 167 info.Version = name.Version; 168 info.Assemblies.Add(assembly.FullName); 169 info.Files.Add(assembly.Location); 170 info.Message = "Plugin doesn't have necessary meta-information: "; 171 disabledPlugins.Add(info); 163 172 } catch(FileNotFoundException ex) { 164 173 PluginInfo info = new PluginInfo(); … … 198 207 // iterate through all custom attributes and search for named arguments that we are interested in 199 208 foreach(CustomAttributeData attributeData in attributes) { 200 List<CustomAttributeNamedArgument> namedArguments = new List<CustomAttributeNamedArgument>(attributeData.NamedArguments); 201 // if the current attribute contains a named argument with the name "Name" then extract the plugin name 202 CustomAttributeNamedArgument pluginNameArgument = namedArguments.Find(delegate(CustomAttributeNamedArgument arg) { 203 return arg.MemberInfo.Name == "Name"; 204 }); 205 if(pluginNameArgument.MemberInfo != null) { 206 pluginName = (string)pluginNameArgument.TypedValue.Value; 207 } 208 // if the current attribute contains a named argument with the name "Dependency" then extract the dependency 209 // and store it in the list of all dependencies 210 CustomAttributeNamedArgument dependencyNameArgument = namedArguments.Find(delegate(CustomAttributeNamedArgument arg) { 211 return arg.MemberInfo.Name == "Dependency"; 212 }); 213 if(dependencyNameArgument.MemberInfo != null) { 214 pluginDependencies.Add((string)dependencyNameArgument.TypedValue.Value); 215 } 216 // if the current attribute has a named argument "Filename" then find if the argument "Filetype" is also supplied 217 // and if the filetype is Assembly then store the name of the assembly in the list of assemblies 218 CustomAttributeNamedArgument filenameArg = namedArguments.Find(delegate(CustomAttributeNamedArgument arg) { 219 return arg.MemberInfo.Name == "Filename"; 220 }); 221 CustomAttributeNamedArgument filetypeArg = namedArguments.Find(delegate(CustomAttributeNamedArgument arg) { 222 return arg.MemberInfo.Name == "Filetype"; 223 }); 209 CustomAttributeNamedArgument filenameArg; 210 CustomAttributeNamedArgument filetypeArg; 211 foreach(CustomAttributeNamedArgument arg in attributeData.NamedArguments) { 212 if(arg.MemberInfo.Name == "Name") { 213 // if the current attribute contains a named argument with the name "Name" then extract the plugin name 214 pluginName = (string)arg.TypedValue.Value; 215 } else if(arg.MemberInfo.Name == "Dependency") { 216 // if the current attribute contains a named argument with the name "Dependency" then extract the dependency 217 // and store it in the list of all dependencies 218 pluginDependencies.Add((string)arg.TypedValue.Value); 219 } else if(arg.MemberInfo.Name == "Filename") { 220 // if the current attribute has a named argument "Filename" then find if the argument "Filetype" is also supplied 221 // and if the filetype is Assembly then store the name of the assembly in the list of assemblies 222 filenameArg = arg; 223 } else if(arg.MemberInfo.Name == "Filetype") { 224 filetypeArg = arg; 225 } 226 } 224 227 if(filenameArg.MemberInfo != null && filetypeArg.MemberInfo != null) { 225 228 pluginFiles.Add(pluginDir + "/" + (string)filenameArg.TypedValue.Value); … … 229 232 } 230 233 } 231 232 234 // minimal sanity check of the attribute values 233 235 if(pluginName != "" && pluginAssemblies.Count > 0) { … … 393 395 internal void OnDelete(PluginInfo pluginInfo) { 394 396 IPlugin plugin = FindPlugin(pluginInfo); 395 if(plugin !=null) plugin.OnDelete();397 if(plugin != null) plugin.OnDelete(); 396 398 } 397 399 -
branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/PluginFileAttribute.cs
r5 r638 49 49 50 50 public PluginFileAttribute() { } 51 public PluginFileAttribute(string name, PluginFileType type) { 52 this.Filename = name; 53 this.Filetype = type; 54 } 51 55 } 52 56 } -
branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/PluginManager.cs
r316 r638 27 27 // must extend MarshalByRefObject because of event passing between Loader and PluginManager (each in it's own AppDomain) 28 28 public class PluginManager : MarshalByRefObject { 29 30 29 // singleton: only one manager allowed in each AppDomain 31 private static PluginManager manager = new PluginManager(); 30 private static readonly PluginManager manager = PluginManager.manager==null?new PluginManager():PluginManager.manager; 31 static PluginManager() { Console.WriteLine("static ctor called "); } 32 32 public static PluginManager Manager { 33 get { return manager; } 33 get { 34 return manager; 35 } 34 36 } 35 37 36 // singleton: only one control manager allowed in each applicat oin (i.e. AppDomain)38 // singleton: only one control manager allowed in each application (i.e. AppDomain) 37 39 private static IControlManager controlManager; 38 40 public static IControlManager ControlManager { … … 71 73 private ICollection<PluginInfo> loadedPlugins; 72 74 public ICollection<PluginInfo> LoadedPlugins { 73 get { return loadedPlugins; } 74 internal set { loadedPlugins = value; } 75 get { 76 Console.WriteLine(AppDomain.CurrentDomain.Id); 77 Console.WriteLine(this.GetHashCode()); 78 if(loadedPlugins != null) Console.WriteLine(loadedPlugins.Count); else Console.WriteLine("Loaded plugins==null!"); 79 return loadedPlugins; 80 } 81 internal set { 82 Console.WriteLine(AppDomain.CurrentDomain.Id); 83 Console.WriteLine(value.Count); 84 Console.WriteLine(this.GetHashCode()); 85 loadedPlugins = new List<PluginInfo>(value); 86 } 75 87 } 76 88 … … 82 94 AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; 83 95 setup.PrivateBinPath = pluginDir; 84 pluginDomain = AppDomain.CreateDomain("plugin domain", null, setup); 96 pluginDomain = AppDomain.CreateDomain("plugin domain"); 97 pluginDomain.SetupInformation.PrivateBinPath = pluginDir; 85 98 remoteLoader = (Loader)pluginDomain.CreateInstanceAndUnwrap("HeuristicLab.PluginInfraStructure", "HeuristicLab.PluginInfrastructure.Loader"); 86 remoteLoader.PluginAction += delegate(object sender, PluginManagerActionEventArgs args) { if(Action != null) Action(this, args); };99 remoteLoader.PluginAction += new PluginManagerActionEventHandler(remoteLoader_PluginAction); 87 100 remoteLoader.Init(); 88 101 NotifyListeners(PluginManagerAction.Initialized, "-"); 102 } 103 104 public void remoteLoader_PluginAction(object sender, PluginManagerActionEventArgs e) { 105 if(Action != null) Action(this, e); 89 106 } 90 107 … … 98 115 // activate a PluginRunner instance in the application 99 116 // and remotely tell it to start the application 100 117 Console.WriteLine(appInfo); 101 118 NotifyListeners(PluginManagerAction.Starting, appInfo.Name); 102 119 AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; 103 120 setup.PrivateBinPath = pluginDir; 104 AppDomain applicationDomain = AppDomain.CreateDomain(appInfo.Name + " AppDomain", null, setup); 121 AppDomain applicationDomain = AppDomain.CreateDomain(appInfo.Name + " AppDomain"); 122 applicationDomain.SetupInformation.PrivateBinPath = pluginDir; 105 123 try { 106 124 Runner remoteRunner = (Runner)applicationDomain.CreateInstanceAndUnwrap("HeuristicLab.PluginInfrastructure", "HeuristicLab.PluginInfrastructure.Runner"); … … 108 126 remoteRunner.LoadPlugins(remoteLoader.ActivePlugins); 109 127 NotifyListeners(PluginManagerAction.Initialized, "All plugins"); 110 remoteRunner.Run(appInfo );128 remoteRunner.Run(appInfo.PluginAssembly, appInfo.PluginType); 111 129 } finally { 112 130 // make sure domain is unloaded in all cases -
branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/Runner.cs
r29 r638 24 24 using System.Text; 25 25 using System.Reflection; 26 using System.Runtime.Remoting; 27 using System.Runtime.Serialization; 26 28 27 29 namespace HeuristicLab.PluginInfrastructure { … … 29 31 30 32 public void LoadPlugins(ICollection<PluginInfo> plugins) { 33 List<string> loadedNames = new List<string>(); 31 34 foreach(PluginInfo pluginInfo in plugins) { 32 35 foreach(string assemblyName in pluginInfo.Assemblies) { 33 Assembly.LoadFrom(assemblyName); 36 if(!loadedNames.Contains(assemblyName)) { 37 Console.WriteLine("Loading assembly " + assemblyName); 38 loadedNames.Add(assemblyName); 39 Assembly.LoadFrom(assemblyName); 40 } 34 41 } 35 42 } 43 Console.WriteLine(AppDomain.CurrentDomain.Id); 36 44 PluginManager.Manager.LoadedPlugins = plugins; 37 45 } 38 46 39 public void Run( ApplicationInfo appInfo) {40 IApplication runnablePlugin = (IApplication)Activator.CreateInstance(appInfo.PluginAssembly, appInfo.PluginType).Unwrap();41 runnablePlugin.Run();47 public void Run(string assembly, string type) { 48 Console.WriteLine(AppDomain.CurrentDomain.Id); 49 object proxy = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(assembly, type); 42 50 } 43 51
Note: See TracChangeset
for help on using the changeset viewer.