/// <summary>
        /// Initializes a new instance of the <see cref="PartAppDomainHost"/> class.
        /// </summary>
        /// <param name="description">The description.</param>
        public PartAppDomainHost(ActivationHostDescription description)
            : base(description)
        {
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            AppDomainSetup appDomainSetup = new AppDomainSetup();

            appDomainSetup.ApplicationBase = description.HostWorkingDirectory;
            appDomainSetup.PrivateBinPath  = description.HostWorkingDirectory;

            string configFilePath = Path.Combine(description.HostWorkingDirectory, description.ConfigFileBaseName);

            configFilePath = Path.ChangeExtension(configFilePath, "config");
            if (!File.Exists(configFilePath))
            {
                configFilePath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
            }

            appDomainSetup.ConfigurationFile = configFilePath;
            this._appDomain = AppDomain.CreateDomain("Plugin_" + description.Id, AppDomain.CurrentDomain.Evidence, appDomainSetup);

            AppDomain.CurrentDomain.UnhandledException += OnCurrentDomainUnhandledException;
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PartActivationHostBase"/> class.
        /// </summary>
        /// <param name="description">The description.</param>
        protected PartActivationHostBase(ActivationHostDescription description)
        {
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            this.Description    = description;
            this.ActivatedTypes = new HashSet <Type>();
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActivationHostEventArgs"/> class.
        /// </summary>
        /// <param name="description">The description.</param>
        /// <param name="cause">The cause.</param>
        public ActivationHostEventArgs(ActivationHostDescription description, Exception cause)
        {
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }

            Description = description;
            Cause       = cause;
        }
Esempio n. 4
0
        private static IPartActivationHost CreateActivationHost(Type type, string configFileBaseName)
        {
            // use two variables to satisfy CA disposable object exception path....
            PartActivationHostBase selectedHost     = null;
            PartActivationHostBase tempSelectedHost = null;

            try
            {
                lock (_hosts)
                {
                    // find an appropriate existing host if any...
                    var query = from host in _hosts
                                let workDirectory = Path.GetDirectoryName(type.Assembly.Location)
                                                    where host.ActivatedTypes.Contains(type) || host.Description.HostWorkingDirectory == workDirectory
                                                    select host;

                    tempSelectedHost = query.FirstOrDefault();

                    // if a host was found, return it...
                    if (tempSelectedHost != null)
                    {
                        selectedHost     = tempSelectedHost;
                        tempSelectedHost = null;
                        return(selectedHost);
                    }

                    // if no host found, create a new one...

                    string location    = Path.GetDirectoryName(type.Assembly.Location);
                    var    description = new ActivationHostDescription(location, configFileBaseName);

                    tempSelectedHost = new PartAppDomainHost(description);

                    _hosts.Add(tempSelectedHost);
                }

                // start the host...
                tempSelectedHost.Start();

                selectedHost     = tempSelectedHost;
                tempSelectedHost = null;
            }
            finally
            {
                if (tempSelectedHost != null)
                {
                    tempSelectedHost.Dispose();
                }
            }

            return(selectedHost);
        }