Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/03/10 18:08:26 (15 years ago)
Author:
gkronber
Message:

Worked on GUI for plugin management. #891 (Refactor GUI for plugin management)

Location:
trunk/sources/HeuristicLab.PluginInfrastructure/Manager
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/ApplicationDescription.cs

    r2790 r2922  
    8686
    8787    public override string ToString() {
    88       return Name;
     88      return Name + " " + Version;
    8989    }
    9090  }
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginDescription.cs

    r2815 r2922  
    4848    /// Gets or sets the description of the plugin.
    4949    /// </summary>
    50     internal string Description {
     50    public string Description {
    5151      get { return description; }
    52       set { description = value; }
     52      internal set { description = value; }
    5353    }
    5454    private Version version;
     
    188188    /// <returns>The name of the plugin.</returns>
    189189    public override string ToString() {
    190       return Name;
     190      return Name + " " + Version;
    191191    }
    192192
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginInfrastructureCancelEventArgs.cs

    r2790 r2922  
    2929  [Serializable]
    3030  internal sealed class PluginInfrastructureCancelEventArgs : CancelEventArgs {
    31     internal string Action { get; private set; }
    32     internal object Entity { get; private set; }
    33     internal PluginInfrastructureCancelEventArgs(string action, object entity)
     31    internal IEnumerable<string> Entities { get; private set; }
     32    internal PluginInfrastructureCancelEventArgs(IEnumerable<string> entities)
    3433      : base() {
    35       this.Action = action;
    36       this.Entity = entity;
     34      this.Entities = entities;
    3735    }
    3836  }
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginInfrastructureEventArgs.cs

    r2790 r2922  
    2828  [Serializable]
    2929  internal sealed class PluginInfrastructureEventArgs : EventArgs {
    30     internal string Action { get; private set; }
    3130    internal object Entity { get; private set; }
    32     internal PluginInfrastructureEventArgs(string action, object entity) {
    33       this.Action = action;
     31    internal PluginInfrastructureEventArgs(object entity) {
    3432      this.Entity = entity;
     33    }
     34
     35    private static PluginInfrastructureEventArgs emptyArgs = new PluginInfrastructureEventArgs(string.Empty);
     36    internal static PluginInfrastructureEventArgs Empty {
     37      get { return emptyArgs; }
    3538    }
    3639  }
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginManager.cs

    r2790 r2922  
    3636  /// </summary>
    3737  internal sealed class PluginManager : MarshalByRefObject {
    38     /// <summary>
    39     /// Event handler for actions in the plugin manager.
    40     /// </summary>
    41     internal event EventHandler<PluginInfrastructureEventArgs> Action;
     38    internal event EventHandler<PluginInfrastructureEventArgs> PluginLoaded;
     39    internal event EventHandler<PluginInfrastructureEventArgs> PluginUnloaded;
     40    internal event EventHandler<PluginInfrastructureEventArgs> Initializing;
     41    internal event EventHandler<PluginInfrastructureEventArgs> Initialized;
     42    internal event EventHandler<PluginInfrastructureEventArgs> ApplicationStarting;
     43    internal event EventHandler<PluginInfrastructureEventArgs> ApplicationStarted;
    4244
    4345    private string pluginDir;
     
    6668      plugins = new List<PluginDescription>();
    6769      applications = new List<ApplicationDescription>();
    68       Reset();
    69     }
    70 
    71     internal void Reset() {
    7270      initialized = false;
    73       if (plugins != null && plugins.Any(x => x.PluginState == PluginState.Loaded)) throw new InvalidOperationException("Reset() is not allowed while applications are active.");
    74       plugins.Clear();
    75       applications.Clear();
    7671    }
    7772
     
    8075    /// </summary>
    8176    internal void DiscoverAndCheckPlugins() {
    82       OnAction(new PluginInfrastructureEventArgs("Initializing", "PluginInfrastructure"));
     77      OnInitializing(PluginInfrastructureEventArgs.Empty);
    8378      AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
    8479      setup.PrivateBinPath = pluginDir;
     
    9287        remoteValidator.PluginLoaded +=
    9388          delegate(object sender, PluginInfrastructureEventArgs e) {
    94             OnAction(e);
     89            OnPluginLoaded(e);
    9590          };
    9691        // get list of plugins and applications from the validator
     
    9893        plugins.AddRange(remoteValidator.Plugins);
    9994        applications.AddRange(remoteValidator.Applications);
    100         OnAction(new PluginInfrastructureEventArgs("Initialized", "PluginInfrastructure"));
    10195      }
    10296      finally {
     
    10498        AppDomain.Unload(pluginDomain);
    10599        // unload all plugins
    106         foreach (var pluginDescription in plugins.Where(x => x.PluginState == PluginState.Loaded))
     100        foreach (var pluginDescription in plugins.Where(x => x.PluginState == PluginState.Loaded)) {
    107101          pluginDescription.Unload();
     102          OnPluginUnloaded(new PluginInfrastructureEventArgs(pluginDescription));
     103        }
    108104        initialized = true;
     105        OnInitialized(PluginInfrastructureEventArgs.Empty);
    109106      }
    110107    }
     
    122119      // and remotely tell it to start the application
    123120
    124       OnAction(new PluginInfrastructureEventArgs("Starting application", appInfo));
     121      OnApplicationStarting(new PluginInfrastructureEventArgs(appInfo));
    125122      AppDomain applicationDomain = null;
    126123      try {
     
    134131        applicationManager.PluginUnloaded += applicationManager_PluginUnloaded;
    135132        applicationManager.PrepareApplicationDomain(applications, plugins);
    136         OnAction(new PluginInfrastructureEventArgs("Started application", appInfo));
     133        OnApplicationStarted(new PluginInfrastructureEventArgs(appInfo));
    137134        applicationManager.Run(appInfo);
    138135      }
     
    150147      // can be started or stopped at the same time
    151148      lock (locker) {
     149        // also unload the matching plugin description in this AppDomain
    152150        plugins.First(x => x.Equals(desc)).Unload();
    153151      }
    154       OnAction(new PluginInfrastructureEventArgs(e.Action, e.Entity));
     152      OnPluginUnloaded(e);
    155153    }
    156154
     
    161159      // can be started or stopped at the same time
    162160      lock (locker) {
     161        // also load the matching plugin description in this AppDomain
    163162        plugins.First(x => x.Equals(desc)).Load();
    164163      }
    165       OnAction(new PluginInfrastructureEventArgs(e.Action, e.Entity));
    166     }
    167 
    168     private void OnAction(PluginInfrastructureEventArgs e) {
    169       if (Action != null) {
    170         Action(this, e);
    171       }
    172     }
     164      OnPluginLoaded(e);
     165    }
     166
     167    #region event raising methods
     168    private void OnPluginLoaded(PluginInfrastructureEventArgs e) {
     169      if (PluginLoaded != null) {
     170        PluginLoaded(this, e);
     171      }
     172    }
     173
     174    private void OnPluginUnloaded(PluginInfrastructureEventArgs e) {
     175      if (PluginUnloaded != null) {
     176        PluginUnloaded(this, e);
     177      }
     178    }
     179
     180    private void OnInitializing(PluginInfrastructureEventArgs e) {
     181      if (Initializing != null) {
     182        Initializing(this, e);
     183      }
     184    }
     185
     186    private void OnInitialized(PluginInfrastructureEventArgs e) {
     187      if (Initialized != null) {
     188        Initialized(this, e);
     189      }
     190    }
     191
     192    private void OnApplicationStarting(PluginInfrastructureEventArgs e) {
     193      if (ApplicationStarting != null) {
     194        ApplicationStarting(this, e);
     195      }
     196    }
     197
     198    private void OnApplicationStarted(PluginInfrastructureEventArgs e) {
     199      if (ApplicationStarted != null) {
     200        ApplicationStarted(this, e);
     201      }
     202    }
     203    #endregion
    173204
    174205    // infinite lease time
    175206    /// <summary>
    176     /// Initializes the life time service with infinite lease time.
     207    /// Make sure that the plugin manager is never disposed (necessary for cross-app-domain events)
    177208    /// </summary>
    178209    /// <returns><c>null</c>.</returns>
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginValidator.cs

    r2815 r2922  
    504504            IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginType);
    505505            plugin.OnLoad();
    506             OnPluginLoaded(new PluginInfrastructureEventArgs("Plugin loaded", plugin.Name));
     506            OnPluginLoaded(new PluginInfrastructureEventArgs(desc));
    507507          }
    508508        }
Note: See TracChangeset for help on using the changeset viewer.