Ejemplo n.º 1
0
        private IApplicationHost CreateAppHost(Type appHostType, object appHostConfig,
                                               WebAppConfig appConfig,
                                               IListenerTransport listenerTransport, Type appHostTransportType, object appHostTransportConfig)
        {
            Logger.Write(LogLevel.Debug, "SimpleApplicationServer.CreateAppHost vhost={0}, vport={1}", appConfig.VHost, appConfig.VPort);
            try
            {
                IApplicationHost host = hostFactory.CreateApplicationHost(appHostType, appConfig.VHost, appConfig.VPort, appConfig.VPath, appConfig.RealPath);
                host.Configure(appHostConfig, appConfig, this, listenerTransport, appHostTransportType, appHostTransportConfig);
                //subscribe to Unload event only after run host.Configure
                //because apphost transport must unregister himself first
                host.HostUnload += OnHostUnload;

                lock (hosts) {
                    hosts.Add(new HostInfo()
                    {
                        Host                   = host,
                        AppHostType            = appHostType,
                        AppHostConfig          = appHostConfig,
                        AppConfig              = appConfig,
                        ListenerTransport      = listenerTransport,
                        AppHostTransportType   = appHostTransportType,
                        AppHostTransportConfig = appHostTransportConfig
                    });
                }
                return(host);
            } catch (Exception ex) {
                Logger.Write(LogLevel.Error, "Can't create host {0}", ex);
                return(null);
            }
        }