Changeset 2922 for trunk/sources/HeuristicLab.PluginInfrastructure/Manager
- Timestamp:
- 03/03/10 18:08:26 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.PluginInfrastructure/Manager
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/ApplicationDescription.cs
r2790 r2922 86 86 87 87 public override string ToString() { 88 return Name ;88 return Name + " " + Version; 89 89 } 90 90 } -
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginDescription.cs
r2815 r2922 48 48 /// Gets or sets the description of the plugin. 49 49 /// </summary> 50 internalstring Description {50 public string Description { 51 51 get { return description; } 52 set { description = value; }52 internal set { description = value; } 53 53 } 54 54 private Version version; … … 188 188 /// <returns>The name of the plugin.</returns> 189 189 public override string ToString() { 190 return Name ;190 return Name + " " + Version; 191 191 } 192 192 -
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginInfrastructureCancelEventArgs.cs
r2790 r2922 29 29 [Serializable] 30 30 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) 34 33 : base() { 35 this.Action = action; 36 this.Entity = entity; 34 this.Entities = entities; 37 35 } 38 36 } -
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginInfrastructureEventArgs.cs
r2790 r2922 28 28 [Serializable] 29 29 internal sealed class PluginInfrastructureEventArgs : EventArgs { 30 internal string Action { get; private set; }31 30 internal object Entity { get; private set; } 32 internal PluginInfrastructureEventArgs(string action, object entity) { 33 this.Action = action; 31 internal PluginInfrastructureEventArgs(object entity) { 34 32 this.Entity = entity; 33 } 34 35 private static PluginInfrastructureEventArgs emptyArgs = new PluginInfrastructureEventArgs(string.Empty); 36 internal static PluginInfrastructureEventArgs Empty { 37 get { return emptyArgs; } 35 38 } 36 39 } -
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginManager.cs
r2790 r2922 36 36 /// </summary> 37 37 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; 42 44 43 45 private string pluginDir; … … 66 68 plugins = new List<PluginDescription>(); 67 69 applications = new List<ApplicationDescription>(); 68 Reset();69 }70 71 internal void Reset() {72 70 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();76 71 } 77 72 … … 80 75 /// </summary> 81 76 internal void DiscoverAndCheckPlugins() { 82 On Action(new PluginInfrastructureEventArgs("Initializing", "PluginInfrastructure"));77 OnInitializing(PluginInfrastructureEventArgs.Empty); 83 78 AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; 84 79 setup.PrivateBinPath = pluginDir; … … 92 87 remoteValidator.PluginLoaded += 93 88 delegate(object sender, PluginInfrastructureEventArgs e) { 94 On Action(e);89 OnPluginLoaded(e); 95 90 }; 96 91 // get list of plugins and applications from the validator … … 98 93 plugins.AddRange(remoteValidator.Plugins); 99 94 applications.AddRange(remoteValidator.Applications); 100 OnAction(new PluginInfrastructureEventArgs("Initialized", "PluginInfrastructure"));101 95 } 102 96 finally { … … 104 98 AppDomain.Unload(pluginDomain); 105 99 // 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)) { 107 101 pluginDescription.Unload(); 102 OnPluginUnloaded(new PluginInfrastructureEventArgs(pluginDescription)); 103 } 108 104 initialized = true; 105 OnInitialized(PluginInfrastructureEventArgs.Empty); 109 106 } 110 107 } … … 122 119 // and remotely tell it to start the application 123 120 124 OnA ction(new PluginInfrastructureEventArgs("Starting application",appInfo));121 OnApplicationStarting(new PluginInfrastructureEventArgs(appInfo)); 125 122 AppDomain applicationDomain = null; 126 123 try { … … 134 131 applicationManager.PluginUnloaded += applicationManager_PluginUnloaded; 135 132 applicationManager.PrepareApplicationDomain(applications, plugins); 136 OnA ction(new PluginInfrastructureEventArgs("Started application",appInfo));133 OnApplicationStarted(new PluginInfrastructureEventArgs(appInfo)); 137 134 applicationManager.Run(appInfo); 138 135 } … … 150 147 // can be started or stopped at the same time 151 148 lock (locker) { 149 // also unload the matching plugin description in this AppDomain 152 150 plugins.First(x => x.Equals(desc)).Unload(); 153 151 } 154 On Action(new PluginInfrastructureEventArgs(e.Action, e.Entity));152 OnPluginUnloaded(e); 155 153 } 156 154 … … 161 159 // can be started or stopped at the same time 162 160 lock (locker) { 161 // also load the matching plugin description in this AppDomain 163 162 plugins.First(x => x.Equals(desc)).Load(); 164 163 } 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 173 204 174 205 // infinite lease time 175 206 /// <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) 177 208 /// </summary> 178 209 /// <returns><c>null</c>.</returns> -
trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginValidator.cs
r2815 r2922 504 504 IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginType); 505 505 plugin.OnLoad(); 506 OnPluginLoaded(new PluginInfrastructureEventArgs( "Plugin loaded", plugin.Name));506 OnPluginLoaded(new PluginInfrastructureEventArgs(desc)); 507 507 } 508 508 }
Note: See TracChangeset
for help on using the changeset viewer.