- Timestamp:
- 03/03/10 18:08:26 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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>
Note: See TracChangeset
for help on using the changeset viewer.