Changeset 882 for trunk/sources/HeuristicLab.PluginInfrastructure
- Timestamp:
- 12/01/08 14:42:57 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/PluginManager.cs
r766 r882 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Security.Policy; 25 using System.Reflection; 26 using System.Diagnostics; 27 using System.Security.Permissions; 28 using System.Security; 24 29 25 30 namespace HeuristicLab.PluginInfrastructure { … … 132 137 } 133 138 139 /// <summary> 140 /// Creates a new AppDomain with all plugins preloaded and Sandboxing capability 141 /// </summary> 142 /// <param name="assembly">Assembly reference</param> 143 /// <returns>the strongname of the assembly</returns> 144 private StrongName CreateStrongName(Assembly assembly) { 145 if (assembly == null) 146 throw new ArgumentNullException("assembly"); 147 148 AssemblyName assemblyName = assembly.GetName(); 149 Debug.Assert(assemblyName != null, "Could not get assembly name"); 150 151 // get the public key blob 152 byte[] publicKey = assemblyName.GetPublicKey(); 153 if (publicKey == null || publicKey.Length == 0) 154 throw new InvalidOperationException("Assembly is not strongly named"); 155 156 StrongNamePublicKeyBlob keyBlob = new StrongNamePublicKeyBlob(publicKey); 157 158 // and create the StrongName 159 return new StrongName(keyBlob, assemblyName.Name, assemblyName.Version); 160 } 161 162 public AppDomain CreateAndInitAppDomainWithSandbox(string friendlyName, bool sandboxed) { 163 164 PermissionSet pset; 165 if (sandboxed) { 166 pset = new PermissionSet(PermissionState.None); 167 pset.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); 168 } else { 169 pset = new PermissionSet(PermissionState.Unrestricted); 170 } 171 AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation; 172 setup.PrivateBinPath = pluginDir; 173 setup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; 174 AppDomain applicationDomain = AppDomain.CreateDomain(friendlyName, AppDomain.CurrentDomain.Evidence, setup, pset, CreateStrongName(Assembly.GetExecutingAssembly())); 175 176 Runner remoteRunner = (Runner)applicationDomain.CreateInstanceAndUnwrap(typeof(Runner).Assembly.GetName().Name, typeof(Runner).FullName); 177 NotifyListeners(PluginManagerAction.Initializing, "All plugins"); 178 if (remoteLoader != null) { 179 remoteRunner.LoadPlugins(remoteLoader.ActivePlugins); 180 } else if (LoadedPlugins != null && LoadedPlugins.Count > 0) { 181 remoteRunner.LoadPlugins(LoadedPlugins); 182 } 183 NotifyListeners(PluginManagerAction.Initialized, "All plugins"); 184 return applicationDomain; 185 } 134 186 135 187 /// <summary>
Note: See TracChangeset
for help on using the changeset viewer.