public LocalhostAppServer(string connectionString, int port = SignalRConstants.LocalhostAppServerPort)
        {
            bool useLocalSignalR      = false;
            var  useLocalSignalRValue = Environment.GetEnvironmentVariable("useLocalSignalR");

            if (!string.IsNullOrEmpty(useLocalSignalRValue))
            {
                if (Boolean.TryParse(useLocalSignalRValue, out var result))
                {
                    useLocalSignalR = result;
                }
            }
            var config = new AppServerConfig()
            {
                SignalRType      = useLocalSignalR ? 0 : 1,
                ConnectionString = connectionString
            };

            _host = new WebHostBuilder()
                    .ConfigureLogging((context, logging) =>
            {
                logging.AddSerilog();
                logging.SetMinimumLevel(LogLevel.Warning);
            })
                    .ConfigureAppConfiguration(ConfigurationConfig)
                    .ConfigureServices(s => s.AddSingleton(config))
                    .UseKestrel(KestrelConfig)
                    .UseStartup(typeof(Startup))
                    .Build();
        }
Ejemplo n.º 2
0
        public void Configure(object serverConfig)
        {
            config = serverConfig as AppServerConfig;

            physicalRoot = Environment.CurrentDirectory;

            if (config != null)
            {
                if (!String.IsNullOrEmpty(config.PhysycalRoot))
                {
                    Environment.CurrentDirectory = config.PhysycalRoot;
                    physicalRoot = config.PhysycalRoot;
                }

                if (config.ThreadsConfig != null)
                {
                    ThreadHelper.SetThreads(
                        config.ThreadsConfig.MinWorkerThreads,
                        config.ThreadsConfig.MinIOThreads,
                        config.ThreadsConfig.MaxWorkerThreads,
                        config.ThreadsConfig.MaxIOThreads
                        );
                }

                if (!String.IsNullOrEmpty(config.HostFactoryType))
                {
                    Type factoryType = Type.GetType(config.HostFactoryType);
                    if (factoryType == null)
                    {
                        Logger.Write(LogLevel.Error, "Could not find factory type '{0}'", config.HostFactoryType);
                        return;
                    }
                    hostFactory = (IApplicationHostFactory)Activator.CreateInstance(factoryType);
                }
                else
                {
                    hostFactory = new SystemWebHostFactory();
                }
            }

            Logger.Write(LogLevel.Debug, "Root directory: {0}", physicalRoot);
        }