Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/08/08 22:54:02 (16 years ago)
Author:
gkronber
Message:

created a branch for changes needed to run HL3 on Mono 2.0
(ticket #298)

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  
    2323using System.Collections.Generic;
    2424using System.Text;
     25using System.Runtime.Serialization;
    2526
    2627namespace HeuristicLab.PluginInfrastructure {
     
    6970      set { pluginType = value; }
    7071    }
     72
     73    public override string ToString() {
     74      return Name + " " + Version + " " + Description + " " + pluginAssembly + " " + pluginType;
     75    }
    7176  }
    7277}
  • branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/BaseClasses/ApplicationBase.cs

    r242 r638  
    3434    public ApplicationBase() {
    3535      ReadAttributes();
     36      Run();
    3637    }
    3738
  • branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/ClassInfoAttribute.cs

    r242 r638  
    5959
    6060    public ClassInfoAttribute() {}
     61
     62    public ClassInfoAttribute(string name) {
     63      Name = name;
     64    }
    6165  }
    6266}
  • branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/DiscoveryService.cs

    r29 r638  
    3333    public PluginInfo[] Plugins {
    3434      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        }
    3843      }
    3944    }
  • branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/InvalidPluginException.cs

    r96 r638  
    2323using System.Collections.Generic;
    2424using System.Text;
     25using System.Runtime.Serialization;
    2526
    2627namespace HeuristicLab.PluginInfrastructure {
     28  [Serializable]
    2729  class InvalidPluginException : Exception {
     30    public InvalidPluginException() : base() { }
     31
     32    public InvalidPluginException(SerializationInfo info, StreamingContext context) : base(info, context) { }
    2833  }
    2934}
  • branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/Loader.cs

    r535 r638  
    9898          return null;
    9999        }
    100         };
     100      };
    101101      allPlugins.Clear();
    102102      disabledPlugins.Clear();
     
    161161            }
    162162          }
     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);
    163172        } catch(FileNotFoundException ex) {
    164173          PluginInfo info = new PluginInfo();
     
    198207      // iterate through all custom attributes and search for named arguments that we are interested in
    199208      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        }
    224227        if(filenameArg.MemberInfo != null && filetypeArg.MemberInfo != null) {
    225228          pluginFiles.Add(pluginDir + "/" + (string)filenameArg.TypedValue.Value);
     
    229232        }
    230233      }
    231 
    232234      // minimal sanity check of the attribute values
    233235      if(pluginName != "" && pluginAssemblies.Count > 0) {
     
    393395    internal void OnDelete(PluginInfo pluginInfo) {
    394396      IPlugin plugin = FindPlugin(pluginInfo);
    395       if(plugin!=null) plugin.OnDelete();
     397      if(plugin != null) plugin.OnDelete();
    396398    }
    397399
  • branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/PluginFileAttribute.cs

    r5 r638  
    4949
    5050    public PluginFileAttribute() { }
     51    public PluginFileAttribute(string name, PluginFileType type) {
     52      this.Filename = name;
     53      this.Filetype = type;
     54    }
    5155  }
    5256}
  • branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/PluginManager.cs

    r316 r638  
    2727  // must extend MarshalByRefObject because of event passing between Loader and PluginManager (each in it's own AppDomain)
    2828  public class PluginManager : MarshalByRefObject {
    29 
    3029    // 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 "); }
    3232    public static PluginManager Manager {
    33       get { return manager; }
     33      get {
     34        return manager;
     35      }
    3436    }
    3537
    36     // singleton: only one control manager allowed in each applicatoin (i.e. AppDomain)
     38    // singleton: only one control manager allowed in each application (i.e. AppDomain)
    3739    private static IControlManager controlManager;
    3840    public static IControlManager ControlManager {
     
    7173    private ICollection<PluginInfo> loadedPlugins;
    7274    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      }
    7587    }
    7688
     
    8294      AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
    8395      setup.PrivateBinPath = pluginDir;
    84       pluginDomain = AppDomain.CreateDomain("plugin domain", null, setup);
     96      pluginDomain = AppDomain.CreateDomain("plugin domain");
     97      pluginDomain.SetupInformation.PrivateBinPath = pluginDir;
    8598      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);
    87100      remoteLoader.Init();
    88101      NotifyListeners(PluginManagerAction.Initialized, "-");
     102    }
     103
     104    public void remoteLoader_PluginAction(object sender, PluginManagerActionEventArgs e) {
     105      if(Action != null) Action(this, e);
    89106    }
    90107
     
    98115      // activate a PluginRunner instance in the application
    99116      // and remotely tell it to start the application
    100 
     117      Console.WriteLine(appInfo);
    101118      NotifyListeners(PluginManagerAction.Starting, appInfo.Name);
    102119      AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
    103120      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;
    105123      try {
    106124        Runner remoteRunner = (Runner)applicationDomain.CreateInstanceAndUnwrap("HeuristicLab.PluginInfrastructure", "HeuristicLab.PluginInfrastructure.Runner");
     
    108126        remoteRunner.LoadPlugins(remoteLoader.ActivePlugins);
    109127        NotifyListeners(PluginManagerAction.Initialized, "All plugins");
    110         remoteRunner.Run(appInfo);
     128        remoteRunner.Run(appInfo.PluginAssembly, appInfo.PluginType);
    111129      } finally {
    112130        // make sure domain is unloaded in all cases
  • branches/HL-3.2-MonoMigration/HeuristicLab.PluginInfrastructure/Runner.cs

    r29 r638  
    2424using System.Text;
    2525using System.Reflection;
     26using System.Runtime.Remoting;
     27using System.Runtime.Serialization;
    2628
    2729namespace HeuristicLab.PluginInfrastructure {
     
    2931
    3032    public void LoadPlugins(ICollection<PluginInfo> plugins) {
     33      List<string> loadedNames = new List<string>();
    3134      foreach(PluginInfo pluginInfo in plugins) {
    3235        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          }
    3441        }
    3542      }
     43      Console.WriteLine(AppDomain.CurrentDomain.Id);
    3644      PluginManager.Manager.LoadedPlugins = plugins;
    3745    }
    3846
    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);
    4250    }
    4351
Note: See TracChangeset for help on using the changeset viewer.