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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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>
Note: See TracChangeset for help on using the changeset viewer.