예제 #1
0
        public AppDomain createAppDomain(string appDomainName, AppDomainSetup appDomainSetup)
        {
            try
            {
                if (AppDomains_ControledByO2Kernel.ContainsKey(appDomainName))
                {
                    PublicDI.log.error("in createAppDomain, appDomainName provided has already been used, appDomainNames must be unique: {0}", appDomainName);
                }
                else
                {
                    PublicDI.log.info("Creating AppDomain {0} with Base Directory {1}", appDomainName,
                                      appDomainSetup.ApplicationBase);
                    // ensure target directory exits
                    O2Kernel_Files.checkIfDirectoryExistsAndCreateIfNot(appDomainSetup.ApplicationBase);

                    // give our appDomain full trust :)
                    var permissionSet = new PermissionSet(PermissionState.Unrestricted);

                    AppDomains_ControledByO2Kernel.Add(appDomainName, this);

                    //Create domain
                    AppDomain = AppDomain.CreateDomain(appDomainName, null, appDomainSetup, permissionSet);
                    //        appDomain.AssemblyResolve += new ResolveEventHandler(assemblyResolve);
                    BaseDirectory = AppDomain.BaseDirectory;

                    AppDomain.DomainUnload += (sender, e) => this.removeDomainFromManagedList();
                    return(AppDomain);
                }
            }
            catch (Exception ex)
            {
                PublicDI.log.ex(ex, "could not load createAppDomain: " + appDomainName);
            }
            return(null);
        }