public void Launch() { Log.Debug("{class} {method} {message}", "DaxStudioRibbon", "Launch", "Entering Launch()"); // Find free port and start the web host _port = WebHost.Start(); //todo - can I search for DaxStudio.exe and set _client if found (would need to send it a message with the port number) ?? // activate DAX Studio if it's already running if (_client != null) { if (!_client.HasExited) { SetForegroundWindow(_client.MainWindowHandle); return; } } var path = ""; // look for daxstudio.exe in the same folder as daxstudio.dll path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "daxstudio.exe"); Log.Debug("{class} {method} About to launch DaxStudio on path: {path} port: {port}", "DaxStudioRibbon", "BtnDaxClick", path, _port); // start Dax Studio process _client = Process.Start(new ProcessStartInfo(path, _port.ToString())); Log.Debug("{class} {method} {message}", "DaxStudioRibbon", "Launch", "Exiting Launch()"); }
public async Task ReturnsTrueForExpectedMatch() { var log = this.CreateLogger(); var args = new NameValueCollection(); var url = $"http://localhost:{TcpPort.NextFreePort()}"; args.Add("selenium.baseUrl", url); var browserConfig = WebDriver .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log) .Build(); using (WebHost.Start( url, router => router .MapGet( "", (req, res, data) => { res.ContentType = "text/html"; return(res.WriteAsync("<body></body>")); }))) using (var driver = WebDriverFactory.Create(browserConfig)) { driver.Navigate().GoToUrl(url); driver.WaitForJavascriptResult("6 / 3", 2, log, TimeSpan.FromMilliseconds(100)); } }
public async Task SetUp() { this.log = this.CreateLogger(); var args = new NameValueCollection(); url = new Uri($"http://localhost:{TcpPort.NextFreePort()}"); args.Add("selenium.baseUrl", url.ToString()); browserConfig = WebDriver .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log) .Build(); webHost = WebHost.Start( url.ToString(), router => router .MapGet( "/page1", (req, res, data) => { res.ContentType = "text/html"; return(res.WriteAsync("<body><a href='page2'>Page 2</a></body>")); }) .MapGet( "/page2", (req, res, data) => { res.ContentType = "text/html"; return(res.WriteAsync("<body><label><input type='radio' />Foo</label></body>")); })); webDriver = WebDriverFactory.Create(browserConfig); }
#pragma warning restore 649 public void Execute(IEnumerable<string> arguments) { Tracing.Info("taste - testing a site locally"); parameters.Parse(arguments); if (string.IsNullOrWhiteSpace(parameters.Template)) { parameters.DetectFromDirectory(templateEngines.Engines); } engine = templateEngines[parameters.Template]; if (engine == null) return; var context = Generator.BuildContext(parameters.Path); engine.Initialize(); engine.Process(context); var watcher = new SimpleFileSystemWatcher(); watcher.OnChange(parameters.Path, WatcherOnChanged); var w = new WebHost(engine.GetOutputDirectory(parameters.Path), new FileContentProvider(),Convert.ToInt32(parameters.Port)); w.Start(); Tracing.Info(string.Format("Browse to http://localhost:{0}/ to test the site.", parameters.Port)); Tracing.Info("Press 'Q' to stop the web host..."); ConsoleKeyInfo key; do { key = Console.ReadKey(); } while (key.Key != ConsoleKey.Q); }
public static void Main(string[] args) { var services = GetAllServices(); using (var host = new WebHost()) { host.Start(services); Console.WriteLine("Web host started"); var serviceProvider = host.HostServiceProvider; var valueHolder = serviceProvider.GetService<IValueHolder>(); valueHolder.AddOne(); valueHolder.AddOne(); valueHolder.AddOne(); valueHolder.AddOne(); Console.WriteLine($"Current value: {valueHolder.Get()}"); while (true) { Thread.Sleep(100); } } }
public static void Main(string[] args) { using (var host = WebHost.Start( app => app.Response.WriteAsync("<h1>Programming ASP.NET Core</h1>"))) { // Wait for the host to end Console.WriteLine("Courtesy of 'Programming ASP.NET Core'\n===="); Console.WriteLine("Use Ctrl-C to shutdown the host..."); host.WaitForShutdown(); } //WebHost.CreateDefaultBuilder(args) // .UseKestrel(options => // { // options.Limits.MaxConcurrentConnections = 100; // options.Limits.MaxConcurrentUpgradedConnections = 100; // options.Limits.MaxRequestBodySize = 10 * 1024; // options.Limits.MinRequestBodyDataRate = // new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10)); // options.Limits.MinResponseDataRate = // new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10)); // options.Listen(IPAddress.Loopback, 5000); // options.Listen(IPAddress.Loopback, 5001, listenOptions => // { // listenOptions.UseHttps("testCert.pfx", "testPassword"); // }); // }); }
static void Main(string[] args) { var messageSent = new ManualResetEventSlim(false); using (var host = WebHost.Start("http://127.0.0.1:0", async context => { // Respond with the ApplicationName. var env = context.RequestServices.GetRequiredService <IHostEnvironment>(); await context.Response.WriteAsync(env.ApplicationName); messageSent.Set(); })) { // Need these for test deployer to consider host deployment successful // The address written here is used by the client to send requests var addresses = host.ServerFeatures.Get <IServerAddressesFeature>().Addresses; foreach (var address in addresses) { Console.WriteLine($"Now listening on: {address}"); } Console.WriteLine("Application started. Press Ctrl+C to shut down."); // Shut down after message sent or timeout messageSent.Wait(TimeSpan.FromSeconds(30)); } }
public static void Main(string[] args) { WebHost.Start(async context => { await context.Response.WriteAsync("<h1>A Simple Host</h1>"); }).WaitForShutdown(); }
public static OpenHttpServer CreateAndRun() { var currentPort = DefaultPort; while (true) { OpenHttpServer server = null; try { server = new OpenHttpServer(); var baseAddress = new Uri($"http://localhost:{currentPort}"); // ReSharper disable once AccessToDisposedClosure var webHost = WebHost.Start(baseAddress.ToString(), ctx => server.Handler(ctx)); server.Host = webHost; server.BaseAddress = baseAddress; return(server); } catch (IOException ex) { server?.Dispose(); if (!(ex.InnerException is AddressInUseException)) { throw; } } currentPort++; } }
public async Task SetUp() { this.log = this.CreateLogger(); var args = new NameValueCollection(); url = $"http://localhost:{TcpPort.NextFreePort()}"; args.Add("selenium.baseUrl", url); var browserConfig = WebDriver .Configure(cfg => cfg.WithDefaultOptions().Providers(x => args[x]), log) .Build(); webHost = WebHost.Start( url, router => router .MapGet( "", (req, res, data) => { res.ContentType = "text/html; charset=utf-8"; return(res.WriteAsync( "<html><body><script type=\"text/javascript\">alert('Hello! I am an alert box!');</script></body></html>")); })); webDriver = WebDriverFactory.Create(browserConfig); }
private void Ribbon1Load(object sender, RibbonUIEventArgs e) { Log.Debug("{class} {method} {message}", "DaxStudioRibbon", "RibbonLoad", "Start"); try { // look for a running DaxStudio.exe instance and // if we find one try to start a WebHost for it var client = DaxStudioStandalone.GetClient(); var port = 0; if (_client == null && client != null) { Log.Debug("{class} {method} {message} port: {port}", "DaxStudioRibbon", "Ribbon1Load", "Existing DaxStudio.exe process found", client.Port); _client = client.Process; port = client.Port; } if (port != 0) { WebHost.Start(port); } } catch (Exception ex) { Log.Error("{Class} {method} {exception} {stacktrace}", "DaxStudioRibbon", "RibbonLoad", ex.Message, ex.StackTrace); } Log.Debug("{class} {method} {message}", "DaxStudioRibbon", "RibbonLoad", "Finish"); }
public static void Main(string[] args) { var services = GetAllServices(); using (var host = new WebHost()) { host.Start(services); Console.WriteLine("Web host started"); var serviceProvider = host.HostServiceProvider; var valueHolder = serviceProvider.GetService <IValueHolder>(); valueHolder.AddOne(); valueHolder.AddOne(); valueHolder.AddOne(); valueHolder.AddOne(); Console.WriteLine($"Current value: {valueHolder.Get()}"); while (true) { Thread.Sleep(100); } } }
#pragma warning restore 649 public void Execute(IEnumerable<string> arguments) { Tracing.Info("taste - testing a site locally"); parameters.Parse(arguments); var context = Generator.BuildContext(parameters.Path); if (string.IsNullOrWhiteSpace(parameters.Template)) { parameters.DetectFromDirectory(templateEngines.Engines, context); } engine = templateEngines[parameters.Template]; if (engine == null) { Tracing.Info(string.Format("template engine {0} not found - (engines: {1})", parameters.Template, string.Join(", ", templateEngines.Engines.Keys))); return; } engine.Initialize(); engine.Process(context, skipFileOnError: true); foreach (var t in transforms) t.Transform(context); var watcher = new SimpleFileSystemWatcher(); watcher.OnChange(parameters.Path, WatcherOnChanged); var w = new WebHost(engine.GetOutputDirectory(parameters.Path), new FileContentProvider(), Convert.ToInt32(parameters.Port)); w.Start(); var url = string.Format("http://localhost:{0}/", parameters.Port); if (parameters.LaunchBrowser) { Tracing.Info(string.Format("Opening {0} in default browser...", url)); try { Process.Start(url); } catch (Exception) { Tracing.Info(string.Format("Failed to launch {0}.", url)); } } else { Tracing.Info(string.Format("Browse to {0} to view the site.", url)); } Tracing.Info("Press 'Q' to stop the web host..."); ConsoleKeyInfo key; do { key = Console.ReadKey(); } while (key.Key != ConsoleKey.Q); Console.WriteLine(); }
private static void Main(string[] args) { var context = new TorshiaCotnext(); context.Database.Migrate(); WebHost.Start(new StartUp()); }
private static void StartWebHost() { using (var host = WebHost.Start(app => app.Response.WriteAsync("hello"))) { Console.WriteLine("started"); host.WaitForShutdown(); } }
public static void Main() { Console.OutputEncoding = Encoding.UTF8; InitializeDatabase(); WebHost.Start(new Startup()); }
private static void HelloWorld() { using (WebHost.Start(context => context.Response.WriteAsync("Hello, World!"))) { //host.WaitForShutdown(); // TODO: https://github.com/aspnet/Hosting/issues/1022 Console.WriteLine("Running HelloWorld: Press any key to shutdown and start the next sample..."); Console.ReadKey(); } }
static void Main(string[] args) { //PandaContext context = new PandaContext(); //context.Database.EnsureDeleted(); //context.Database.EnsureCreated(); //Console.WriteLine("Database is restarted..."); WebHost.Start(new StartUp()); }
public static void Main() { using (var context = new PandaDbContext()) { context.Database.EnsureCreated(); } WebHost.Start(new Startup()); }
static void Init1() { WebHost webHost = new WebHost(port: 18080, root: "Html"); webHost.Start(); ConsoleHelper.WriteLine("WSServer 正在初始化....", ConsoleColor.Green); _server = new WSServer(); _server.OnMessage += Server_OnMessage; _server.OnDisconnected += _server_OnDisconnected; _server.Start(); ConsoleHelper.WriteLine("WSServer 就绪,回车启动客户端", ConsoleColor.Green); ConsoleHelper.ReadLine(); WSClient client = new WSClient(); client.OnPong += Client_OnPong; client.OnMessage += Client_OnMessage; client.OnError += Client_OnError; client.OnDisconnected += Client_OnDisconnected; ConsoleHelper.WriteLine("WSClient 正在连接到服务器...", ConsoleColor.DarkGray); var connected = client.Connect(); if (connected) { ConsoleHelper.WriteLine("WSClient 连接成功,回车测试消息", ConsoleColor.DarkGray); ConsoleHelper.ReadLine(); //client.Close(); //ConsoleHelper.ReadLine(); ConsoleHelper.WriteLine("WSClient 正在发送消息...", ConsoleColor.DarkGray); client.Send($"hello world!{DateTime.Now.ToString("HH:mm:ss.fff")}"); ConsoleHelper.ReadLine(); ConsoleHelper.WriteLine("WSClient 正在ping服务器...", ConsoleColor.DarkGray); client.Ping(); ConsoleHelper.ReadLine(); ConsoleHelper.WriteLine("WSClient 正在断开连接..."); client.Close(); ConsoleHelper.ReadLine(); } else { ConsoleHelper.WriteLine("WSClient 连接失败", ConsoleColor.DarkGray); } }
public static void Main(string[] args) { Console.WriteLine("http://localhost:5000/"); using (var host = WebHost.Start(app => app.Response.WriteAsync("Hello, World!"))) { Console.WriteLine("Use Ctrl-C to shutdown the host..."); host.WaitForShutdown(); } }
private static void Main(string[] args) { var context = new MishMashContext(); context.Database.Migrate(); WebHost.Start(new StartUp()); Console.WriteLine("Hello World!"); }
public static void Main(string[] args) { //CreateWebHostBuilder(args).Build().Run(); using (var host = WebHost.Start("http://localhost:8080", context => context.Response.WriteAsync("Hello WebHost"))) { Console.WriteLine("Applicatiion has been started"); host.WaitForShutdown(); } }
public static void Main(string[] args) { var host = WebHost.Start(ctx => { ctx.Response.ContentType = "text/html"; return(ctx.Response.WriteAsync(@"<!DOCTYPE html><html lang=""en"" xmlns=""http://www.w3.org/1999/xhtml""><head> <meta charset=""utf-8""/> <title>LetMeOn.Site</title> <style>html, body{width: 100%; height: 100%;}html{display: table;}body{display: table-cell; vertical-align: middle; text-align: center; background: linear-gradient(135deg, rgba(30,87,153,1) 0%,rgba(41,137,216,1) 50%,rgba(125,185,232,1) 100%);}h1{font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; color: #fff;}</style></head><body> <h1>Hooray, you're online!</h1></body></html>")); }); host.WaitForShutdown(); }
public static void Main(string[] args) { //TorshiqDbContext context = new TorshiqDbContext(); //context.Database.EnsureDeleted(); //Console.WriteLine("The Database is deleted"); //context.Database.EnsureCreated(); //Console.WriteLine("The Database is created"); WebHost.Start(new StartUp()); }
/// <summary> /// 启动MVC服务 /// </summary> public void Start() { try { AreaCollection.RegistAll(); } catch (Exception ex) { throw new Exception("当前代码无任何Controller或者不符合MVC 命名规范! err:" + ex.Message); } try { webHost.Start(); } catch (Exception ex) { throw new Exception("当前端口已被其他程序占用,请更换端口再做尝试! err:" + ex.Message); } }
private static void CustomUrl() { // Changing the listening URL using (WebHost.Start("http://localhost:8080", context => context.Response.WriteAsync("Hello, World!"))) { //host.WaitForShutdown(); // TODO: https://github.com/aspnet/Hosting/issues/1022 Console.WriteLine("Running CustomUrl: Press any key to shutdown and start the next sample..."); Console.ReadKey(); } }
static void Main(string[] args) { var dateAndTime = DateTime.Now; var date = dateAndTime.Date; Console.WriteLine(date.ToString("MMMM dd")); Console.WriteLine(dateAndTime.ToString("HH:mm")); WebHost.Start(new Startup()); }
public void Launch(bool enableLogging) { Log.Debug("{class} {method} {message}", "DaxStudioRibbon", "Launch", "Entering Launch()"); // Find free port and start the web host _port = WebHost.Start(); //todo - can I search for DaxStudio.exe and set _client if found (would need to send it a message with the port number) ?? Log.Debug("{class} {method} {message}", "DaxStudioRibbon", "Launch", "Checking for an existing instance of DaxStudio.exe"); // activate DAX Studio if it's already running if (_client != null) { if (!_client.HasExited) { NativeMethods.SetForegroundWindow(_client.MainWindowHandle); return; } } var path = ""; // look for daxstudio.exe in the same folder as daxstudio.dll path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "daxstudio.exe"); if (!File.Exists(path)) { // try getting daxstudio.exe from the parent directory path = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "daxstudio.exe")); if (!File.Exists(path)) { throw new FileNotFoundException("Excel Addin is unable to launch the DAX Studio User Interface"); } } Log.Debug("{class} {method} About to launch DaxStudio on path: {path} port: {port}", "DaxStudioRibbon", "BtnDaxClick", path, _port); // start Dax Studio process ProcessStartInfo psi = new ProcessStartInfo(path) { Arguments = $"-port {_port}", UseShellExecute = false // this is false as we are executing a .exe file directly }; if (enableLogging) { psi.Arguments += " -log"; } _client = Process.Start(psi); if (!_client.WaitForInputIdle(Constants.ExcelUIStartupTimeout)) { Log.Error("Launching User Interface from Excel exceeded the {timeout} ms timeout", Constants.ExcelUIStartupTimeout); MessageBox.Show("The DAX Studio User Interface is taking a long time to load"); } Log.Debug("{class} {method} {message}", "DaxStudioRibbon", "Launch", "Exiting Launch()"); }
public static void Main(string[] args) { using (var host = WebHost.Start( app => app.Response.WriteAsync("<h1>Programming ASP.NET Core</h1>"))) { // Wait for the host to end Console.WriteLine("Courtesy of 'Programming ASP.NET Core'\n===="); Console.WriteLine("Use Ctrl-C to shutdown the host..."); host.WaitForShutdown(); } }
/// <summary> /// 启动MVC服务 /// </summary> public void Start() { try { webHost.Start(); } catch (Exception ex) { throw new Exception("当前端口已被其他程序占用,请更换端口再做尝试! err:" + ex.Message); } }
public void Execute(string[] arguments) { Settings.Parse(arguments); Console.WriteLine("Port: " + Port); Console.WriteLine("Debug: " + Debug); var f = new FileContentProvider(); var w = new WebHost(Directory.GetCurrentDirectory(), f); w.Start(); Console.ReadLine(); }
public static void PrintedPetsInWebAPI(int httpPort) { WebHost.Start( "http://localhost:" + httpPort, async ctx => { ctx.Response.ContentType = "text/plain; charset=utf-8"; await ctx.Response.WriteAsync(PrintedPetsInConsole(), Encoding.UTF8); }) .WaitForShutdown(); }
public static void Main() { using (var context = new PandaDbContext()) { Console.WriteLine("Migrating database..."); context.Database.Migrate(); Console.WriteLine("Migration successful."); } WebHost.Start(new StartUp()); }
public void Execute(string[] arguments) { Tracing.Info("taste - testing a site locally"); Settings.Parse(arguments); if (Port == 0) { Port = 8080; } Tracing.Info("Port: " + Port); Tracing.Info("Debug: " + Debug); var f = new FileContentProvider(); var w = new WebHost(Directory.GetCurrentDirectory(), f); w.Start(); Tracing.Info("Press 'Q' to stop the process"); ConsoleKeyInfo key; do { key = Console.ReadKey(); } while (key.Key != ConsoleKey.Q); }
public void Execute(string[] arguments) { Tracing.Info("taste - testing a site locally"); Settings.Parse(arguments); if (Port == 0) { Port = 8080; } var f = new FileContentProvider(); if (string.IsNullOrWhiteSpace(Path)) { Path = Directory.GetCurrentDirectory(); } if (string.IsNullOrWhiteSpace(Engine)) { Engine = InferEngineFromDirectory(Path); } engine = templateEngines[Engine]; if (engine == null) return; var context = new SiteContext { Folder = Path }; engine.Initialize(); engine.Process(context); var watcher = new SimpleFileSystemWatcher(); watcher.OnChange(Path, WatcherOnChanged); var w = new WebHost(engine.GetOutputDirectory(Path), f); w.Start(); Tracing.Info("Press 'Q' to stop the web host..."); ConsoleKeyInfo key; do { key = Console.ReadKey(); } while (key.Key != ConsoleKey.Q); }