The Labs \ Source Viewer \ SSCLI \ System \ AppDomainManager

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. //
  16. // An AppDomainManager gives a hosting application the chance to
  17. // participate in the creation and control the settings of new AppDomains.
  18. //
  19. namespace System
  20. {
  21.     using System.Collections;
  22.     using System.Globalization;
  23.     using System.IO;
  24.     using System.Reflection;
  25.     using System.Runtime.CompilerServices;
  26.     using System.Security;
  27.     using System.Security.Permissions;
  28.     using System.Security.Policy;
  29.     using System.Threading;
  30.     using System.Runtime.Hosting;
  31.    
  32.     [Flags()]
  33.     [System.Runtime.InteropServices.ComVisible(true)]
  34.     public enum AppDomainManagerInitializationOptions
  35.     {
  36.         None = 0,
  37.         RegisterWithHost = 1
  38.     }
  39.    
  40.     [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
  41.     [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
  42.     [System.Runtime.InteropServices.ComVisible(true)]
  43.     public class AppDomainManager : MarshalByRefObject
  44.     {
  45.         public AppDomainManager()
  46.         {
  47.         }
  48.        
  49.         public virtual AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
  50.         {
  51.             return CreateDomainHelper(friendlyName, securityInfo, appDomainInfo);
  52.         }
  53.        
  54.         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.Infrastructure)]
  55.         [SecurityPermissionAttribute(SecurityAction.Demand, ControlAppDomain = true)]
  56.         protected static AppDomain CreateDomainHelper(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
  57.         {
  58.             if (friendlyName == null)
  59.                 throw new ArgumentNullException(Environment.GetResourceString("ArgumentNull_String"));
  60.            
  61.             // If evidence is provided, we check to make sure that is allowed.
  62.             if (securityInfo != null)
  63.                 new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand();
  64.            
  65.             return AppDomain.nCreateDomain(friendlyName, appDomainInfo, securityInfo, securityInfo == null ? AppDomain.CurrentDomain.InternalEvidence : null, AppDomain.CurrentDomain.GetSecurityDescriptor());
  66.         }
  67.        
  68.         public virtual void InitializeNewDomain(AppDomainSetup appDomainInfo)
  69.         {
  70.             // By default, InitializeNewDomain does nothing.
  71.         }
  72.        
  73.         private AppDomainManagerInitializationOptions m_flags = AppDomainManagerInitializationOptions.None;
  74.         public AppDomainManagerInitializationOptions InitializationFlags {
  75.             get { return m_flags; }
  76.             set { m_flags = value; }
  77.         }
  78.        
  79.        
  80.         public virtual HostSecurityManager HostSecurityManager {
  81.             get { return null; }
  82.         }
  83.        
  84.         public virtual HostExecutionContextManager HostExecutionContextManager {
  85. // By default, the AppDomainManager returns the HostExecutionContextManager.
  86.             get { return HostExecutionContextManager.GetInternalHostExecutionContextManager(); }
  87.         }
  88.        
  89.         private Assembly m_entryAssembly = null;
  90.         public virtual Assembly EntryAssembly {
  91.             get {
  92.                 // The default AppDomainManager sets the EntryAssembly depending on whether the
  93.                 // AppDomain is a manifest application domain or not. In the first case, we parse
  94.                 // the application manifest to find out the entry point assembly and return that assembly.
  95.                 // In the second case, we maintain the old behavior by calling nGetEntryAssembly().
  96.                 if (m_entryAssembly == null) {
  97.                     AppDomain domain = AppDomain.CurrentDomain;
  98.                     m_entryAssembly = nGetEntryAssembly();
  99.                 }
  100.                 return m_entryAssembly;
  101.             }
  102.         }
  103.        
  104.         static internal AppDomainManager CurrentAppDomainManager {
  105.             get { return AppDomain.CurrentDomain.DomainManager; }
  106.         }
  107.        
  108.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  109.         internal extern void nRegisterWithHost();
  110.        
  111.         [MethodImplAttribute(MethodImplOptions.InternalCall)]
  112.         private static extern Assembly nGetEntryAssembly();
  113.     }
  114. }

Developer Fusion