Пример #1
0
        private static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureWebHost((options) =>
        {
            options.UseStartup <Startup>();
            options.UseKestrel();
            options.ConfigureKestrel(options =>
            {
                PiraeusConfig config = GetPiraeusConfig();
                options.Limits.MaxConcurrentConnections         = config.MaxConnections;
                options.Limits.MaxConcurrentUpgradedConnections = config.MaxConnections;
                options.Limits.MaxRequestBodySize     = config.MaxBufferSize;
                options.Limits.MinRequestBodyDataRate =
                    new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
                options.Limits.MinResponseDataRate =
                    new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));

                if (!string.IsNullOrEmpty(config.ServerCertificateFilename))
                {
                    Console.WriteLine("Port for cert with filename");
                    options.ListenAnyIP(config.GetPorts()[0], (a) => a.UseHttps(config.ServerCertificateFilename, config.ServerCertificatePassword));
                }
                else if (!string.IsNullOrEmpty(config.ServerCertificateStore))
                {
                    Console.WriteLine("Port for cert with store");
                    X509Certificate2 cert = config.GetServerCerticate();
                    options.ListenAnyIP(config.GetPorts()[0], (a) => a.UseHttps(cert));
                }
                else
                {
                    Console.WriteLine("Hard coded port 8081");
                    options.ListenAnyIP(8081);
                }
            });
        });
Пример #2
0
        private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .UseStartup <Startup>()
        .UseKestrel(options =>
        {
            PiraeusConfig config = GetPiraeusConfig();
            options.Limits.MaxConcurrentConnections         = config.MaxConnections;
            options.Limits.MaxConcurrentUpgradedConnections = config.MaxConnections;
            options.Limits.MaxRequestBodySize     = config.MaxBufferSize;
            options.Limits.MinRequestBodyDataRate =
                new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
            options.Limits.MinResponseDataRate =
                new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));

            X509Certificate2 cert = config.GetServerCerticate();
            int[] ports           = config.GetPorts();

            foreach (int port in ports)
            {
                if (cert != null)
                {
                    options.ListenAnyIP(port, (a) => a.UseHttps(cert));
                }
                else
                {
                    options.ListenAnyIP(port);
                }
            }
        });
Пример #3
0
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)
                   .ConfigureServices(services => services.AddPiraeusConfiguration())
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                PiraeusConfig config = WebApiHelpers.GetPiraeusConfig();
                webBuilder
                .ConfigureKestrel(options =>
                {
                    options.Limits.MaxConcurrentConnections = config.MaxConnections;
                    options.Limits.MaxConcurrentUpgradedConnections = config.MaxConnections;
                    options.Limits.MaxRequestBodySize = config.MaxBufferSize;
                    options.Limits.MinRequestBodyDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));
                    options.Limits.MinResponseDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));
                    X509Certificate2 cert = config.GetServerCerticate();
                    int[] ports = config.GetPorts();

                    foreach (int port in ports)
                    {
                        if (cert != null)
                        {
                            options.ListenAnyIP(port, a => a.UseHttps(cert));
                        }
                        else
                        {
                            IPAddress address = GetIPAddress(Dns.GetHostName());
                            options.Listen(address, port);
                        }
                    }

                    if (!string.IsNullOrEmpty(config.ServerCertificateFilename))
                    {
                        string[] portStrings = config.Ports.Split(";", StringSplitOptions.RemoveEmptyEntries);

                        foreach (string portString in portStrings)
                        {
                            options.ListenAnyIP(Convert.ToInt32(portString),
                                                a => a.UseHttps(config.ServerCertificateFilename,
                                                                config.ServerCertificatePassword));
                        }
                    }
                });
                webBuilder.UseStartup <Startup>();
            }));
        }
Пример #4
0
        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .UseStartup <Startup>()
        .UseKestrel(options =>
        {
            PiraeusConfig config = GetPiraeusConfig();
            options.Limits.MaxConcurrentConnections         = config.MaxConnections;
            options.Limits.MaxConcurrentUpgradedConnections = config.MaxConnections;
            options.Limits.MaxRequestBodySize     = config.MaxBufferSize;
            options.Limits.MinRequestBodyDataRate =
                new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));
            options.Limits.MinResponseDataRate =
                new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10));

            X509Certificate2 cert = config.GetServerCerticate();
            int[] ports           = config.GetPorts();

            foreach (int port in ports)
            {
                if (cert != null)
                {
                    options.ListenAnyIP(port, (a) => a.UseHttps(cert));
                }
                else
                {
                    IPAddress address = GetIPAddress(Dns.GetHostName());
                    options.Listen(address, port);
                    //options.Listen(IPAddress.Loopback, port);
                    //options.ListenAnyIP(port);
                }
            }


            if (!string.IsNullOrEmpty(config.ServerCertificateFilename))
            {
                string[] portStrings = config.Ports.Split(";", StringSplitOptions.RemoveEmptyEntries);

                foreach (var portString in portStrings)
                {
                    options.ListenAnyIP(Convert.ToInt32(portString), (a) => a.UseHttps(config.ServerCertificateFilename, config.ServerCertificatePassword));
                }
            }
            //else
            //{
            //    options.ListenAnyIP(config.Channels.Http.ListenPort, (a) => a.UseHttps(".\\localhost.pfx", "pass@word1"));
            //}
        });
Пример #5
0
        private static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)
                   .ConfigureServices((hostContext, services) =>
            {
                services.AddPiraeusConfiguration(out config);
            })
                   .ConfigureWebHost(options =>
            {
                options.UseStartup <Startup>();
                options.UseKestrel();
                options.ConfigureKestrel(options =>
                {
                    options.Limits.MaxConcurrentConnections = config.MaxConnections;
                    options.Limits.MaxConcurrentUpgradedConnections = config.MaxConnections;
                    options.Limits.MaxRequestBodySize = config.MaxBufferSize;
                    options.Limits.MinRequestBodyDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));
                    options.Limits.MinResponseDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));

                    X509Certificate2 cert = config.GetServerCerticate();
                    int[] ports = config.GetPorts();

                    foreach (int port in ports)
                    {
                        if (cert != null)
                        {
                            Console.WriteLine($"Listening on {port} using certificate.");
                            options.ListenAnyIP(port, a => a.UseHttps(cert));
                        }
                        else
                        {
                            Console.WriteLine($"Listening on {port}.");
                            options.ListenAnyIP(port);
                        }
                    }
                });
            }));
        }
Пример #6
0
        private static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)
                   .ConfigureLogging(builder =>
            {
                PiraeusConfig pconfig = GetPiraeusConfig();
                LogLevel logLevel = Enum.Parse <LogLevel>(pconfig.LogLevel);
                var loggers = pconfig.GetLoggerTypes();

                if (loggers.HasFlag(LoggerType.Console))
                {
                    builder.AddConsole();
                }

                if (loggers.HasFlag(LoggerType.Debug))
                {
                    builder.AddDebug();
                }

                if (loggers.HasFlag(LoggerType.AppInsights) && !string.IsNullOrEmpty(pconfig.InstrumentationKey))
                {
                    builder.AddApplicationInsights(pconfig.InstrumentationKey);
                }

                builder.SetMinimumLevel(logLevel);
                builder.Services.AddSingleton <ILog, Logger>();
            })
                   .ConfigureWebHost(options =>
            {
                options.UseStartup <Startup>();
                options.UseKestrel();
                options.ConfigureKestrel(options =>
                {
                    PiraeusConfig config = GetPiraeusConfig();
                    options.Limits.MaxConcurrentConnections = config.MaxConnections;
                    options.Limits.MaxConcurrentUpgradedConnections = config.MaxConnections;
                    options.Limits.MaxRequestBodySize = config.MaxBufferSize;
                    options.Limits.MinRequestBodyDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));
                    options.Limits.MinResponseDataRate =
                        new MinDataRate(100, TimeSpan.FromSeconds(10));

                    if (!string.IsNullOrEmpty(config.ServerCertificateFilename))
                    {
                        Console.WriteLine("Port for cert with filename");
                        options.ListenAnyIP(config.GetPorts()[0],
                                            a => a.UseHttps(config.ServerCertificateFilename, config.ServerCertificatePassword));
                    }
                    else if (!string.IsNullOrEmpty(config.ServerCertificateStore))
                    {
                        Console.WriteLine("Port for cert with store");
                        X509Certificate2 cert = config.GetServerCerticate();
                        options.ListenAnyIP(config.GetPorts()[0], a => a.UseHttps(cert));
                    }
                    else
                    {
                        Console.WriteLine("Hard coded port 8081");
                        options.ListenAnyIP(8081);
                    }
                });
            }));
        }