private void CreateHost()
        {
            this._hostCreationPending = true;
            BuildManagerHost host = null;

            try
            {
                string str;
                host = (BuildManagerHost)ApplicationManager.GetApplicationManager().CreateObjectWithDefaultAppHostAndAppId(this._physicalPath, this._virtualPath, typeof(BuildManagerHost), false, this._hostingParameters, out str);
                host.AddPendingCall();
                host.Configure(this);
                this._host  = host;
                this._appId = str;
                this._hostCreationException = this._host.InitializationException;
            }
            catch (Exception exception)
            {
                this._hostCreationException = exception;
                this._host = host;
            }
            finally
            {
                this._hostCreationPending = false;
                if (host != null)
                {
                    if (this.AppDomainStarted != null)
                    {
                        this.AppDomainStarted(this, EventArgs.Empty);
                    }
                    host.RemovePendingCall();
                }
            }
        }
        private void CreateHost()
        {
            Debug.Trace("CBM", "CreateHost");
            Debug.Assert(_host == null);

            Debug.Assert(!_hostCreationPending, "CreateHost: creation already pending");

            _hostCreationPending = true;

            // Use a local to avoid having a partially created _host
            BuildManagerHost host = null;

            try {
                string           appId;
                IApplicationHost appHost;

                ApplicationManager appManager = ApplicationManager.GetApplicationManager();

                host = (BuildManagerHost)appManager.CreateObjectWithDefaultAppHostAndAppId(
                    _physicalPath, _virtualPath,
                    typeof(BuildManagerHost), false /*failIfExists*/,
                    _hostingParameters, out appId, out appHost);

                // host appdomain cannot be unloaded during creation.
                host.AddPendingCall();

                host.Configure(this);

                _host    = host;
                _appId   = appId;
                _appHost = appHost;

                _hostCreationException = _host.InitializationException;
            }
            catch (Exception e) {
                // If an exception happens, keep track of it
                _hostCreationException = e;

                // Even though the host initialization failed, keep track of it so subsequent
                // request will see the error
                _host = host;
            }
            finally {
                _hostCreationPending = false;

                if (host != null)
                {
                    // Notify the client that the host is ready
                    if (AppDomainStarted != null)
                    {
                        AppDomainStarted(this, EventArgs.Empty);
                    }

                    // The host can be unloaded safely now.
                    host.RemovePendingCall();
                }
            }

            Debug.Trace("CBM", "CreateHost LEAVE");
        }
 internal void OnAppDomainUnloaded(ApplicationShutdownReason reason)
 {
     this._host = null;
     this._hostCreationException = null;
     this._reason          = reason;
     this._waitForCallBack = false;
     ThreadPool.QueueUserWorkItem(this._onAppDomainUnloadedCallback);
 }
 internal void ResetHost()
 {
     lock (_lock) {
         // Though _appId and _appHost are created along with _host,
         // we need not reset those here as they always correspond to
         // default app id and app host.
         _host = null;
         _hostCreationException = null;
     }
 }
        public bool Unload()
        {
            BuildManagerHost host = this._host;

            if (host != null)
            {
                this._host = null;
                return(host.UnloadAppDomain());
            }
            return(false);
        }
        public bool Unload()
        {
            Debug.Trace("CBM", "Unload");

            BuildManagerHost host = _host;

            if (host != null)
            {
                _host = null;
                return(host.UnloadAppDomain());
            }

            return(false);
        }
 internal void ResetHost() {
     lock (_lock) {
         // Though _appId and _appHost are created along with _host,
         // we need not reset those here as they always correspond to 
         // default app id and app host.
         _host = null;
         _hostCreationException = null;
     }
 }
    private void CreateHost() {
        Debug.Trace("CBM", "CreateHost");
        Debug.Assert(_host == null);

        Debug.Assert(!_hostCreationPending, "CreateHost: creation already pending");

        _hostCreationPending = true;

        // Use a local to avoid having a partially created _host
        BuildManagerHost host = null;

        try {
            string appId;
            IApplicationHost appHost;

            ApplicationManager appManager = ApplicationManager.GetApplicationManager();

            host = (BuildManagerHost) appManager.CreateObjectWithDefaultAppHostAndAppId(
                _physicalPath, _virtualPath,
                typeof(BuildManagerHost), false /*failIfExists*/, 
                _hostingParameters, out appId, out appHost);

            // host appdomain cannot be unloaded during creation.
            host.AddPendingCall();

            host.Configure(this);

            _host = host;
            _appId = appId;
            _appHost = appHost;

            _hostCreationException = _host.InitializationException;
        }
        catch (Exception e) {
            // If an exception happens, keep track of it
            _hostCreationException = e;

            // Even though the host initialization failed, keep track of it so subsequent
            // request will see the error
            _host = host;
        }
        finally {
            _hostCreationPending = false;

            if (host != null) {
                // Notify the client that the host is ready
                if (AppDomainStarted != null) {
                    AppDomainStarted(this, EventArgs.Empty);
                }

                // The host can be unloaded safely now.
                host.RemovePendingCall();
            }
        }

        Debug.Trace("CBM", "CreateHost LEAVE");
    }
    public bool Unload() {
        Debug.Trace("CBM", "Unload");

        BuildManagerHost host = _host;
        if (host != null) {
            _host = null;
            return host.UnloadAppDomain();
        }

        return false;
    }
 public bool Unload()
 {
     BuildManagerHost host = this._host;
     if (host != null)
     {
         this._host = null;
         return host.UnloadAppDomain();
     }
     return false;
 }
 internal void OnAppDomainUnloaded(ApplicationShutdownReason reason)
 {
     this._host = null;
     this._hostCreationException = null;
     this._reason = reason;
     this._waitForCallBack = false;
     ThreadPool.QueueUserWorkItem(this._onAppDomainUnloadedCallback);
 }
 private void CreateHost()
 {
     this._hostCreationPending = true;
     BuildManagerHost host = null;
     try
     {
         string str;
         host = (BuildManagerHost) ApplicationManager.GetApplicationManager().CreateObjectWithDefaultAppHostAndAppId(this._physicalPath, this._virtualPath, typeof(BuildManagerHost), false, this._hostingParameters, out str);
         host.AddPendingCall();
         host.Configure(this);
         this._host = host;
         this._appId = str;
         this._hostCreationException = this._host.InitializationException;
     }
     catch (Exception exception)
     {
         this._hostCreationException = exception;
         this._host = host;
     }
     finally
     {
         this._hostCreationPending = false;
         if (host != null)
         {
             if (this.AppDomainStarted != null)
             {
                 this.AppDomainStarted(this, EventArgs.Empty);
             }
             host.RemovePendingCall();
         }
     }
 }