Example #1
0
        public static void Main(string[] args)
        {
            var isService = !(Debugger.IsAttached || args.Contains("--console"));

            if (isService)
            {
                var pathToExe         = Process.GetCurrentProcess().MainModule.FileName;
                var pathToContentRoot = Path.GetDirectoryName(pathToExe);
                Directory.SetCurrentDirectory(pathToContentRoot);
            }

            var host = new WebHostBuilder()
                       .UseUrls("http://0.0.0.0:5001")
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseKestrel()
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .ConfigureKestrel((context, options) => { })
                       .Build();

            if (isService)
            {
                host.RunAsService();
            }
            else
            {
                host.Run();
            }
        }
    public static void Main(string[] args)
    {
        IWebHost host = new WebHostBuilder()
                        .UseKestrel()
                        .UseContentRoot(Directory.GetCurrentDirectory())
                        .UseIISIntegration()
                        .UseStartup <Startup>()
                        .Build();

        if (args.Contains("--windows-service"))
        {
            host = new WebHostBuilder()
                   .UseKestrel()
                   .UseContentRoot("<directory-containing-wwwroot>")
                   .UseIISIntegration()
                   .UseStartup <Startup>()
                   .UseUrls("http://+:5000")
                   .Build();

            Startup.is_service = true;
            host.RunAsService();
        }
        else
        {
            host.Run();
        }
    }
Example #3
0
        public static void Main(string[] args)
        {
            var runAsService = args.Any() && args[0].Contains("--service");

            var pathToContentRoot = Directory.GetCurrentDirectory();

            if (runAsService)
            {
                var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
                pathToContentRoot = Path.GetDirectoryName(pathToExe);
            }

            var host = new WebHostBuilder()
                       .UseKestrel(options => options.Listen(IPAddress.Loopback, 7400))
                       .ConfigureServices(services => services.AddAutofac())
                       .UseContentRoot(pathToContentRoot)
                       .UseStartup <Startup>()
                       .Build();

            if (runAsService)
            {
                host.RunAsService();
            }
            else
            {
                host.Run();
            }
        }
Example #4
0
        static async Task Main(string[] args)
        {
            if (WindowsServiceHelpers.IsWindowsService())
            {
                Directory.SetCurrentDirectory(
                    Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName)
                    );
            }

            var host = new WebHostBuilder()
                       .ConfigureAppConfiguration(Startup.CreateConfiguration(args))
                       .UseKestrel((context, options) => options.Configure(context.Configuration.GetSection("Kestrel")))
                       .UseStartup <Startup>()
                       .Build();

            if (WindowsServiceHelpers.IsWindowsService())
            {
                host.RunAsService();
            }
            else
            {
                await host.RunAsync();
            }

            //var avalonia = AppBuilder
            //    .Configure(new Application())
            //    .UsePlatformDetect()
            //    .UseReactiveUI()
            //    .SetupWithoutStarting()
            //    .Start<MainWindow>();
        }
Example #5
0
        public static void Main(string[] args)
        {
            string contentPath;

            if (Debugger.IsAttached || args.Contains("--console"))
            {
                contentPath = Directory.GetCurrentDirectory();
            }
            else
            {
                contentPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
            }

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(contentPath)
                       .UseStartup <Startup>()
                       .Build();

            if (Debugger.IsAttached || args.Contains("--console"))
            {
                host.Run();
            }
            else
            {
                host.RunAsService();
            }
        }
Example #6
0
        public static void Main(string[] args)
        {
            var basePath = AppDomain.CurrentDomain.BaseDirectory;

            if (Debugger.IsAttached)
            {
                basePath = Directory.GetCurrentDirectory();
            }

            var config = new ConfigurationBuilder()
                         .SetBasePath(basePath)
                         .AddJsonFile("hosting.json", optional: true)
                         .Build();

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseConfiguration(config)
                       .UseContentRoot(basePath)
                       .UseStartup <Startup>()
                       .Build();

            if (Debugger.IsAttached)
            {
                host.Run();
            }
            else
            {
                host.RunAsService();
            }
        }
Example #7
0
        public static void Main(string[] args)
        {
            var isService = true;

            if (Debugger.IsAttached || args.Contains("--console"))
            {
                isService = false;
            }

            var pathToContentRoot = Directory.GetCurrentDirectory();

            if (isService)
            {
                var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
                pathToContentRoot = Path.GetDirectoryName(pathToExe);
            }

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(pathToContentRoot)
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .Build();

            if (isService)
            {
                host.RunAsService();
            }
            else
            {
                host.Run();
            }
        }
        public static void Main(string[] args)
        {
            if (Debugger.IsAttached || args.Contains("--debug"))
            {
                var host = new WebHostBuilder()
                           .UseKestrel()
                           .UseContentRoot(Directory.GetCurrentDirectory())
                           .UseIISIntegration()
                           .UseStartup <Startup>()
                           .UseApplicationInsights()
                           .Build();

                host.Run();
            }
            else
            {
                var cert = new X509Certificate2(args[1], args[2]);

                var host = new WebHostBuilder()
                           .UseKestrel(cfg => cfg.UseHttps(cert))
                           .UseUrls(args[0])
                           .UseContentRoot(args[3])
                           .UseIISIntegration()
                           .UseStartup <Startup>()
                           .UseApplicationInsights()
                           .Build();

                host.RunAsService();
            }
        }
Example #9
0
        public static void Main(string[] args)
        {
            var    isDebug = Debugger.IsAttached || ((IList)args).Contains("--debug");
            string runPath;

            if (isDebug)
            {
                runPath = Directory.GetCurrentDirectory();
            }
            else
            {
                var exePath = Process.GetCurrentProcess().MainModule.FileName;
                runPath = Path.GetDirectoryName(exePath);
            }

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(runPath)
                       .UseStartup <Startup>()
                       .Build();

            if (isDebug)
            {
                host.Run();
            }
            else
            {
                host.RunAsService();
            }
        }
Example #10
0
        public static void Main(string[] args)
        {
            var isService = !(Debugger.IsAttached || args.Contains("--console"));


            var hostingPort = "5000";

            if (args.Contains("--port"))
            {
                var idx = args.ToList().IndexOf("--port");
                hostingPort = args[idx + 1];
                if (Int32.Parse(hostingPort) < 1024 || Int32.Parse(hostingPort) > 65535)
                {
                    Console.WriteLine("Invalid port. Please choose a port between 1024 and 65535");
                    throw new InvalidDataException();
                }
            }

            if (isService)
            {
                var pathToExe         = Process.GetCurrentProcess().MainModule.FileName;
                var pathToContentRoot = Path.GetDirectoryName(pathToExe);
                Directory.SetCurrentDirectory(pathToContentRoot);
            }

            var staticContentPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "..\\client\\dist"));

            Console.WriteLine("Static content served from: " + staticContentPath);
            var host = new WebHostBuilder()
                       .UseUrls("http://0.0.0.0:" + hostingPort)
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseKestrel()
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .UseWebRoot(staticContentPath)
                       .ConfigureKestrel((context, options) =>
            {
                // Set properties and call methods on options
            })
                       .Build();


            if (isService)
            {
                // To run the app without the CustomWebHostService change the
                // next line to host.RunAsService();
                host.RunAsService();
            }
            else
            {
                host.Run();
            }
        }
Example #11
0
        public static void Main(string[] args)
        {
            bool   isConsole;
            string contentPath;

            if (Debugger.IsAttached || args.Contains("--console"))
            {
                isConsole = true;
            }
            else
            {
                isConsole = false;
            }

            //set ContenRoot directory
            if (isConsole)
            {
                contentPath = Directory.GetCurrentDirectory();
            }
            else
            {
                contentPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
            }

            var host = new WebHostBuilder()
                       .UseKestrel()
                       //.UseUrls("http://*:1234")  //Uncomment this line if you would like to change port. Default is 5000, but in production you probably would like to set this to a different port (from config file or commandline parameters maybe). Avoid hard-coding!
                       .UseContentRoot(contentPath)
                       //.UseIISIntegration()       //If you want to use IIS Express during deveplopment debug/testing you can uncomment this line but remember that RunAsService can ONLY use Kestrel.
                       .UseStartup <Startup>()
                       .Build();

            //run
            if (isConsole)
            {
                host.Run();
            }
            else
            {
                host.RunAsService();
            }

            /*
             *
             * To install as a Windows Service you need to run (with Administrator privileges):
             * sc create [service name] [binPath= ]   (Change ServiceName and binPath to match yours)
             * Example:
             *
             * sc create AspNetCoreWindowsService binPath= "FullPathToOutputPath\AspNetCoreWindowsService.exe"
             *
             */
        }
        public static void Main(string[] args)
        {
            var pathToExe         = Process.GetCurrentProcess().MainModule.FileName;
            var pathToContentRoot = Path.GetDirectoryName(pathToExe);
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(pathToContentRoot)
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .Build();

            host.RunAsService();
        }
Example #13
0
        public static void Main(string[] args)
        {
            var pathToExe         = Process.GetCurrentProcess().MainModule.FileName;
            var pathToContentRoot = Path.GetDirectoryName(pathToExe);

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(pathToContentRoot)
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .Build();

            // See https://docs.microsoft.com/en-us/aspnet/core/hosting/windows-service
            host.RunAsService();
        }
Example #14
0
        public static void Main(string[] args)
        {
            var exePath       = Process.GetCurrentProcess().MainModule.FileName;
            var directoryPath = Path.GetDirectoryName(exePath);
            var host          = new WebHostBuilder()
                                .UseKestrel()
                                .UseContentRoot(directoryPath)
                                .UseStartup <Startup>()
                                .UseUrls("http://*:9000")
                                .Build();

            //host.Run();

            host.RunAsService();
        }
        public static void Main(string[] args)
        {
            //
            // Build Config
            var            configHelper = new ConfigurationHelper(args);
            IConfiguration config       = configHelper.Build();

            //
            // Host
            using (var host = new WebHostBuilder()
                              .UseContentRoot(configHelper.RootPath)
                              .UseUrls("https://*:55539")                     // Config can override it. Use "urls":"https://*:55539"
                              .UseConfiguration(config)
                              .ConfigureServices(s => s.AddSingleton(config)) // Configuration Service
                              .UseStartup <Startup>()
                              .UseHttpSys(o => {
                //
                // Kernel mode Windows Authentication
                o.Authentication.Schemes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;

                //
                // Need anonymous to allow CORS preflight requests
                // app.UseWindowsAuthentication ensures (if needed) the request is authenticated to proceed
                o.Authentication.AllowAnonymous = true;
            })
                              .Build()
                              .UseHttps()) {
                string serviceName = config.GetValue <string>("serviceName")?.Trim();

                if (!string.IsNullOrEmpty(serviceName))
                {
                    //
                    // Run as a Service
                    Log.Information($"Running as service: {serviceName}");
                    host.RunAsService();
                }
                else
                {
                    //
                    // Run interactive
                    host.Run();
                }
            }
        }
Example #16
0
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .UseApplicationInsights()
                       .UseUrls("http://0.0.0.0:5000")
                       .Build();


            if (Debugger.IsAttached || args.Contains("--debug"))
            {
                host.Run();
            }
            else
            {
                host.RunAsService();
            }
        }
Example #17
0
        public static void Main(string[] args)
        {
            var isService = !(Debugger.IsAttached || args.Contains("--console"));

            if (isService)
            {
                var pathToExe         = Process.GetCurrentProcess().MainModule.FileName;
                var pathToContentRoot = Path.GetDirectoryName(pathToExe);
                Directory.SetCurrentDirectory(pathToContentRoot);
            }

            // var builder = CreateWebHostBuilder(
            //    args.Where(arg => arg != "--console").ToArray());
            // var host = builder.Build();

            var host = new WebHostBuilder()
                       .UseUrls("http://0.0.0.0:5000")
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseKestrel()
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .UseWebRoot(Path.Combine(Directory.GetCurrentDirectory(), "..\\client\\build"))
                       .ConfigureKestrel((context, options) =>
            {
                // Set properties and call methods on options
            })
                       .Build();


            if (isService)
            {
                // To run the app without the CustomWebHostService change the
                // next line to host.RunAsService();
                host.RunAsService();
            }
            else
            {
                host.Run();
            }
        }
Example #18
0
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                       .UseKestrel()//.UseUrls("http://*:5000")
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .Build();

#if NET461
            if (args.Contains("--windows-service"))
            {
                host.RunAsService();
            }
            else
            {
                host.Run();
            }
#else
            host.Run();
#endif
        }
Example #19
0
        /// <summary>
        /// Eintrittspunkt des Programms.
        /// </summary>
        /// <param name="args">Enthält die Kommandozeilenargumente.</param>
        public static void Main(string[] args)
        {
            try {
                string contentRoot = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
                Directory.SetCurrentDirectory(contentRoot);

                IConfigurationRoot configuration = new ConfigurationBuilder()
                                                   .SetBasePath(contentRoot)
                                                   .AddCommandLine(args)
                                                   .Build();

                IWebHost host = new WebHostBuilder()
                                .UseContentRoot(contentRoot)
                                .UseConfiguration(configuration)
                                .ConfigureLogging(logging =>
                                                  logging.AddConsole())
                                .UseStartup <Startup>()
                                .UseHttpSys(options => {
                    options.Authentication.Schemes        = AuthenticationSchemes.None;
                    options.Authentication.AllowAnonymous = true;
                })
                                .Build();

                if (Environment.UserInteractive)
                {
                    host.Run();
                }
                else
                {
                    host.RunAsService();
                }
            }
            catch (Exception e) {
                new LoggerFactory()
                .AddConsole()
                .CreateLogger <Program>()
                .LogCritical(e.Message);
            }
        }
Example #20
0
        public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseIISIntegration()
                       .UseStartup <Startup>()
                       .Build();

            if (args.Contains("--service", StringComparer.OrdinalIgnoreCase))
            {
#if NET461
                host.RunAsService();
#else
                Console.Error.WriteLine("ERROR --service not supported on this platform");
                Environment.Exit(1);
#endif
            }
            else
            {
                host.Run();
            }
        }
Example #21
0
        private static void GoGoGo(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;

            var exePath       = Process.GetCurrentProcess().MainModule.FileName;
            var directoryPath = Path.GetDirectoryName(exePath);

            IWebHost host = new WebHostBuilder()
                            .UseKestrel()
                            .UseContentRoot(directoryPath)
                            .UseStartup <Startup>()
                            .UseUrls("http://+:4444")
                            .Build();

            if (Debugger.IsAttached || args.Contains("--debug") || Environment.UserInteractive)
            {
                host.RunAsApp();
            }
            else
            {
                host.RunAsService();
            }
        }
Example #22
0
        public static void Main(string[] args)
        {
            //
            // Build Config
            var            configHelper = new ConfigurationHelper(args);
            IConfiguration config       = configHelper.Build();

            //
            // Initialize runAsAService local variable
            string serviceName   = config.GetValue <string>("serviceName")?.Trim();
            bool   runAsAService = !string.IsNullOrEmpty(serviceName);

            //
            // Host
            using (var host = new WebHostBuilder()
                              .UseContentRoot(configHelper.RootPath)
                              .ConfigureLogging((hostingContext, logging) => {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));

                //
                // Console log is not available in running as a Service
                if (!runAsAService)
                {
                    logging.AddConsole();
                }

                logging.AddDebug();
                logging.AddEventLog(new EventLogSettings()
                {
                    SourceName = EventSourceName
                });
            })
                              .UseUrls("https://*:55539")                     // Config can override it. Use "urls":"https://*:55539"
                              .UseConfiguration(config)
                              .ConfigureServices(s => s.AddSingleton(config)) // Configuration Service
                              .UseStartup <Startup>()
                              .UseHttpSys(o => {
                //
                // Kernel mode Windows Authentication
                o.Authentication.Schemes = AuthenticationSchemes.Negotiate | AuthenticationSchemes.NTLM;

                //
                // Need anonymous to allow CORS preflight requests
                // app.UseWindowsAuthentication ensures (if needed) the request is authenticated to proceed
                o.Authentication.AllowAnonymous = true;
            })
                              .Build()
                              .UseHttps()) {
                if (runAsAService)
                {
                    //
                    // Run as a Service
                    Log.Information($"Running as service: {serviceName}");
                    host.RunAsService();
                }
                else
                {
                    //
                    // Run interactive
                    host.Run();
                }
            }
        }
Example #23
0
        public static void Main(string[] args)
        {
            bool isService = !(Debugger.IsAttached || args.Contains("--console"));

            var pathToContentRoot = Directory.GetCurrentDirectory();

            if (isService)
            {
                var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
                pathToContentRoot = Path.GetDirectoryName(pathToExe);
            }

            System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            var configBuilder = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json");

            var config    = configBuilder.Build();
            var port      = int.Parse(config["port"]);
            var url       = config["url"];
            var urlPrefix = config["urlPrefix"];

            var host = new WebHostBuilder()
                       .UseKestrel(options =>
            {
                options.Listen(IPAddress.Any, port);
                // HTTPS
                // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?tabs=aspnetcore2x
                //options.Listen(IPAddress.Any, port, listenOptions =>
                //{
                //  listenOptions.UseHttps("testCert.pfx", "testPassword");
                //});
            })
                       .UseContentRoot(pathToContentRoot)
                       .UseStartup <Startup>()
                       // .UseHttpSys(options =>
                       // {
                       //   // options.Authentication.Schemes = AuthenticationSchemes.None;
                       //   // options.Authentication.AllowAnonymous = true;
                       //   // options.MaxConnections = 100;
                       //   // options.MaxRequestBodySize = 30000000;
                       //   //options.UrlPrefixes.Add(urlPrefix + "+:" + port);
                       //   //options.UrlPrefixes.Add("http://+:80/");
                       //   options.UrlPrefixes.Add("http://+:" + port);
                       // })
                       // .UseApplicationInsights()
                       .Build();

            if (isService)
            {
                host.RunAsService();
            }
            else
            {
                host.Run();
            }

            Process.Start("chrome.exe", string.Format("--incognito  http://localhost:{0}/MovieStore/Movies ", port));


            //BuildWebHost(args).Run();
        }
Example #24
0
        /// <summary>
        /// Default program entry point.
        /// </summary>
        public static void Main(string[] args)
        {
            var isService = args.Contains("--service");

            var config = new ConfigurationBuilder()
                         .AddCommandLine(args)
                         .AddJsonFile("kestrelsettings.json", optional: true, reloadOnChange: false)
                         .AddJsonFile("serilog.json", optional: true, reloadOnChange: true)
                         .Build();

            var pathToExe         = Process.GetCurrentProcess().MainModule.FileName;
            var pathToContentRoot = Path.GetDirectoryName(pathToExe);
            var libuvConfigured   = int.TryParse(Environment.GetEnvironmentVariable(LIBUV_THREAD_COUNT), out var libuvThreads);

            var host = new WebHostBuilder().BuildHostWithReflectionException(builder =>
            {
                return(builder.UseConfiguration(config)
                       .UseKestrel(opts =>
                {
                    opts.Limits.MaxResponseBufferSize = 131072; //128K for large exports (default is 64K)
                })
                       //.UseUrls("http://127.0.0.1:5002") //DO NOT REMOVE (used for local debugging of long running veta exports)
                       .UseLibuv(opts =>
                {
                    if (libuvConfigured)
                    {
                        opts.ThreadCount = libuvThreads;
                    }
                })
                       .UseContentRoot(pathToContentRoot)
                       .UseStartup <Startup>()
                       .ConfigureLogging((hostContext, loggingBuilder) =>
                {
                    loggingBuilder.AddProvider(
                        p => new SerilogLoggerProvider(
                            SerilogExtensions.Configure("VSS.Productivity3D.WebAPI.log", config, p.GetRequiredService <IHttpContextAccessor>())));
                })
                       .Build());
            });

            var log = host.Services.GetRequiredService <ILoggerFactory>().CreateLogger <Program>();

            log.LogInformation("Productivity3D service starting");
            log.LogInformation($"Num Libuv Threads = {(libuvConfigured ? libuvThreads.ToString() : "Default")}");

            if (int.TryParse(Environment.GetEnvironmentVariable(MAX_WORKER_THREADS), out var maxWorkers) &&
                int.TryParse(Environment.GetEnvironmentVariable(MAX_IO_THREADS), out var maxIo))
            {
                ThreadPool.SetMaxThreads(maxWorkers, maxIo);
                log.LogInformation($"Max Worker Threads = {maxWorkers}");
                log.LogInformation($"Max IO Threads = {maxIo}");
            }
            else
            {
                log.LogInformation($"Max Worker Threads = Default");
                log.LogInformation($"Max IO Threads = Default");
            }

            if (int.TryParse(Environment.GetEnvironmentVariable(MIN_WORKER_THREADS), out var minWorkers) &&
                int.TryParse(Environment.GetEnvironmentVariable(MIN_IO_THREADS), out var minIo))
            {
                ThreadPool.SetMinThreads(minWorkers, minIo);
                log.LogInformation($"Min Worker Threads = {minWorkers}");
                log.LogInformation($"Min IO Threads = {minIo}");
            }
            else
            {
                log.LogInformation($"Min Worker Threads = Default");
                log.LogInformation($"Min IO Threads = Default");
            }

            if (int.TryParse(Environment.GetEnvironmentVariable(DEFAULT_CONNECTION_LIMIT), out var connectionLimit))
            {
                //Check how many requests we can execute
                ServicePointManager.DefaultConnectionLimit = connectionLimit;
                log.LogInformation($"Default connection limit = {connectionLimit}");
            }
            else
            {
                log.LogInformation($"Default connection limit = Default");
            }

            if (!isService)
            {
                host.Run();
            }
            else
            {
                host.RunAsService();
            }
        }