コード例 #1
0
        public static AppDomain Assemble(
            string friendlyName,
            AppDomainResolutionPaths resolutionPaths)
        {
            {
                Lokad.Enforce.Argument(() => resolutionPaths);
            }

            var domain = Create(friendlyName, resolutionPaths);

            // Attach to the assembly file resolve event
            // We check for a null reference but not for an empty one,
            // there is after all no reason why the collection couldn't fill up later.
            if (resolutionPaths.Files != null)
            {
                var resolver = Activator.CreateInstanceFrom(
                    domain,
                    typeof(FileBasedResolver).Assembly.LocalFilePath(),
                    typeof(FileBasedResolver).FullName).Unwrap() as FileBasedResolver;

                Debug.Assert(resolver != null, "Somehow we didn't create a resolver.");
                resolver.StoreFilePaths(resolutionPaths.Files);
                resolver.Attach();
            }

            // Attach to the assembly directory resolve event
            // We check for a null reference but not for an empty one,
            // there is after all no reason why the collection couldn't fill up later.
            if (resolutionPaths.Directories != null)
            {
                var resolver = Activator.CreateInstanceFrom(
                    domain,
                    typeof(DirectoryBasedResolver).Assembly.LocalFilePath(),
                    typeof(DirectoryBasedResolver).FullName).Unwrap() as DirectoryBasedResolver;

                Debug.Assert(resolver != null, "Somehow we didn't create a resolver.");
                resolver.StoreDirectoryPaths(resolutionPaths.Directories);
                resolver.Attach();
            }

            // Attach the exception handler
            {
                var attacher = Activator.CreateInstanceFrom(
                    domain,
                    typeof(ExceptionHandlerAttacher).Assembly.LocalFilePath(),
                    typeof(ExceptionHandlerAttacher).FullName).Unwrap() as ExceptionHandlerAttacher;

                Debug.Assert(attacher != null, "Somehow we didn't create an exception handler attacher.");
                attacher.Attach();
            }

            return(domain);
        }
コード例 #2
0
        public static AppDomain Assemble(
            string friendlyName,
            AppDomainResolutionPaths resolutionPaths)
        {
            {
                Lokad.Enforce.Argument(() => resolutionPaths);
            }

            var domain = Create(friendlyName, resolutionPaths);

            // Attach to the assembly file resolve event
            // We check for a null reference but not for an empty one,
            // there is after all no reason why the collection couldn't fill up later.
            if (resolutionPaths.Files != null)
            {
                var resolver = Activator.CreateInstanceFrom(
                    domain,
                    typeof(FileBasedResolver).Assembly.LocalFilePath(),
                    typeof(FileBasedResolver).FullName).Unwrap() as FileBasedResolver;

                Debug.Assert(resolver != null, "Somehow we didn't create a resolver.");
                resolver.StoreFilePaths(resolutionPaths.Files);
                resolver.Attach();
            }

            // Attach to the assembly directory resolve event
            // We check for a null reference but not for an empty one,
            // there is after all no reason why the collection couldn't fill up later.
            if (resolutionPaths.Directories != null)
            {
                var resolver = Activator.CreateInstanceFrom(
                    domain,
                    typeof(DirectoryBasedResolver).Assembly.LocalFilePath(),
                    typeof(DirectoryBasedResolver).FullName).Unwrap() as DirectoryBasedResolver;

                Debug.Assert(resolver != null, "Somehow we didn't create a resolver.");
                resolver.StoreDirectoryPaths(resolutionPaths.Directories);
                resolver.Attach();
            }

            // Attach the exception handler
            {
                var attacher = Activator.CreateInstanceFrom(
                    domain,
                    typeof(ExceptionHandlerAttacher).Assembly.LocalFilePath(),
                    typeof(ExceptionHandlerAttacher).FullName).Unwrap() as ExceptionHandlerAttacher;

                Debug.Assert(attacher != null, "Somehow we didn't create an exception handler attacher.");
                attacher.Attach();
            }

            return domain;
        }
コード例 #3
0
        /// <summary>
        /// Creates a new <see cref="AppDomain"/>.
        /// </summary>
        /// <param name="name">The friendly name of the new <c>AppDomain</c>.</param>
        /// <param name="resolutionPaths">The assembly resolution paths for the new <c>AppDomain</c>.</param>
        /// <returns>The newly created <c>AppDomain</c>.</returns>
        private static AppDomain Create(string name, AppDomainResolutionPaths resolutionPaths)
        {
            {
                Debug.Assert(resolutionPaths != null, "The base path must be defined");
            }

            var setup = new AppDomainSetup
            {
                ApplicationName      = Assembly.GetCallingAssembly().GetName().Name,
                ApplicationBase      = resolutionPaths.BasePath,
                ShadowCopyFiles      = "false",
                DisallowCodeDownload = true
            };

            var result = AppDomain.CreateDomain(
                string.IsNullOrEmpty(name) ? GenerateNewAppDomainName() : name,
                null,
                setup);

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Creates a new <see cref="AppDomain"/>.
        /// </summary>
        /// <param name="name">The friendly name of the new <c>AppDomain</c>.</param>
        /// <param name="resolutionPaths">The assembly resolution paths for the new <c>AppDomain</c>.</param>
        /// <returns>The newly created <c>AppDomain</c>.</returns>
        private static AppDomain Create(string name, AppDomainResolutionPaths resolutionPaths)
        {
            {
                Debug.Assert(resolutionPaths != null, "The base path must be defined");
            }

            var setup = new AppDomainSetup
                {
                    ApplicationName = Assembly.GetCallingAssembly().GetName().Name,
                    ApplicationBase = resolutionPaths.BasePath,
                    ShadowCopyFiles = "false",
                    DisallowCodeDownload = true
                };

            var result = AppDomain.CreateDomain(
                string.IsNullOrEmpty(name) ? GenerateNewAppDomainName() : name,
                null,
                setup);
            return result;
        }