static void Main(string[] args) { using (var host = new NancyHost(new NancyBootstrapper(), new Uri(@"http://localhost:1234"))) { host.Start(); Console.ReadLine(); } }
static void Main(string[] args) { var nancyHost = new NancyHost(new Uri("http://localhost:8888/nancy/")); nancyHost.Start(); Console.WriteLine("Nancy now listening - navigate to http://localhost:8888/nancy/. Press enter to stop"); Console.ReadKey(); nancyHost.Stop(); Console.WriteLine("Stopped. Good bye!"); }
static void Main(string[] args) { var uri = new Uri("http://localhost:3579"); using (var host = new NancyHost(uri)) { host.Start(); Console.WriteLine("Your application is running on " + uri); Console.WriteLine("Press any [Enter] to close the host."); Console.ReadLine(); } }
private static void Main(string[] args) { // Initialize an instance of NancyHost: var configuration = new HostConfiguration { UrlReservations = new UrlReservations { CreateAutomatically = true } }; var uri = new Uri("http://localhost:12340"); Console.WriteLine($"Uri: {uri}."); var host = new NancyHost(configuration, uri); host.Start(); // start hosting Console.WriteLine("Press any key to stop..."); Console.ReadKey(); host.Stop(); // stop hosting }
public static void Main() { ConsoleLogger.Log("starting antdui"); var startTime = DateTime.Now; var app = new AppConfiguration().Get(); Port = app.AntdUiPort; ServerPort = app.AntdPort; var uri = $"http://localhost:{Port}/"; var host = new NancyHost(new Uri(uri)); host.Start(); ConsoleLogger.Log("host ready"); ConsoleLogger.Log($"http port: {Port}"); ConsoleLogger.Log("antdui is running"); ConsoleLogger.Log($"loaded in: {DateTime.Now - startTime}"); KeepAlive(); Console.WriteLine("Stopping..."); host.Stop(); }
public void Should_be_get_an_exception_indicating_a_conflict_when_trying_to_listen_on_a_used_prefix() { Exception ex; // Given using (CreateAndOpenSelfHost()) { // When ex = Record.Exception(() => { using (var host = new NancyHost(BaseUri)) { host.Start(); } }); } // Then ex.Message.ShouldContain("conflict"); }
static void Main(string[] args) { User.UserCreation(); HostConfiguration hostConfiguration = new HostConfiguration() { UrlReservations = new UrlReservations() { CreateAutomatically = true }, }; using (var host = new NancyHost(hostConfiguration, new Uri("http://localhost:1234"))) { host.Start(); Console.WriteLine("Running on http://localhost:1234"); Console.ReadLine(); host.Stop(); } }
static void Main(string[] args) { StaticConfiguration.DisableErrorTraces = false; Console.WriteLine("Nancy is starting"); Host = new NancyHost(CurrentAddress); Host.Start(); Console.WriteLine("Nancy is started and listening on {0}...", CurrentAddress); while (Console.ReadLine() != "quit") { ; } Host.Stop(); Console.WriteLine("Nancy is stopped"); }
static void Main(string[] args) { CacheManager.Instance.MaxSize = 128; CacheManager.Instance.Timeout = 10000; CacheManager.Instance.CleanEnable = true; Setting.Instance.Init(); using (var host = new NancyHost(new Uri("http://localhost:" + Setting.Instance.Port))) { host.Start(); try { Process.Start("http://localhost:" + Setting.Instance.Port + "/m/readme"); } catch (Exception) { } Console.ReadLine(); } }
static void Main(string[] args) { StaticConfiguration.EnableRequestTracing = true; var HostURL = "http://localhost:3579"; var uri = new Uri(HostURL); // Disable caching StaticConfiguration.Caching.EnableRuntimeViewDiscovery = true; StaticConfiguration.Caching.EnableRuntimeViewUpdates = true; using (var host = new NancyHost(uri)) { //System.Diagnostics.Process.Start(HostURL); host.Start(); Console.WriteLine("Your application is running on " + uri); Console.WriteLine("Press any [Enter] to close the host."); Console.ReadLine(); } }
public void Start(string port) { _port = port; var hostConfig = new HostConfiguration { UrlReservations = new UrlReservations { CreateAutomatically = true }, }; if (_hostUrl == null) { _hostUrl = "http://localhost:" + port + "/"; } hostNancy = new NancyHost(hostConfig, new Uri(_hostUrl)); hostNancy.Start(); }
static void Main(string[] args) { var hostConfigs = new HostConfiguration { UrlReservations = new UrlReservations() { CreateAutomatically = true } }; Uri uri = new Uri("http://localhost:1234"); using (var host = new NancyHost(hostConfigs, uri)) { DBPopulator.Populate(); host.Start(); Console.WriteLine("Listening to requests on localhost:1234"); Console.ReadLine(); } }
public static void Start() { // start Nancy interface // initialize an instance of NancyHost (found in the Nancy.Hosting.Self package) // TODO: put this in config string url = "http://localhost:8014"; host = new NancyHost(new Uri(url), new Web.Bootstrapper()); host.Start(); // start hosting // start up monitors that are active var db = new PetaPoco.Database("LocalSQLite"); foreach (var a in db.Query <Model.Monitor>("SELECT * FROM Monitor where Active = 1;")) { log.InfoFormat("Starting monitor name is {0}, running sql ({1}) every {2} seconds", a.Name, a.SQL, a.RunInterval); new App.Monitor(a.MonitorID, a.RunInterval); } }
static void Main(string[] args) { string host = args.Length > 1 ? args[0] : "localhost"; string port = args.Length > 2 ? args[1] : "1234"; Console.WriteLine($"Server host coming from console arguments={host}"); Console.WriteLine($"Port coming from console arguments={port}"); string url = $"http://{host}:{port}"; var nancyHost = new NancyHost(new Uri(url)); try { nancyHost.Start(); Console.WriteLine($"Running on {url}"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { nancyHost.Dispose(); } }
/* * NancyFx-打造小型 WebAPI 與 Microservice 的輕巧利器-黑暗執行緒 * https://blog.darkthread.net/blog/nancyfx * * Nancy.Hosting.Self * * 開放授權 netsh http add urlacl url="http://+:9527/" user="******" * 移除權限 netsh http delete urlacl url="http://+:9527/" */ static void Main(string[] args) { using (var host = new NancyHost( new Uri("http://localhost:9527"))) // http://127.0.0.1:9527/ { try { host.Start(); Console.WriteLine("Press any key to stop..."); Console.Read(); host.Stop(); } catch (AutomaticUrlReservationCreationFailureException ex) { Console.WriteLine("權限不足:" + ex.Message); Console.WriteLine("Press any key to stop..."); Console.Read(); } } }
public static void Main(string[] args) { // https://github.com/squidge/events/ var uris = new[] { new Uri("http://localhost:8888") }; var hostConfig = new HostConfiguration(); var nancyHost = new NancyHost(hostConfig, uris); nancyHost.Start(); Console.WriteLine("Nancy now listening - navigating to http://localhost:8888/. Press enter to stop"); Process.Start("http://localhost:8888/"); Console.ReadKey(); nancyHost.Stop(); Console.WriteLine("Stopped. Good bye!"); }
static void Main(string[] args) { if (!args.Any()) { PrintUsersManual(); Console.ReadLine(); return; } string url = args[0]; var host = new NancyHost(new Uri(url)); host.Start(); Console.WriteLine($"Running H.VectorClocks.Http server on {url} @ {DateTime.Now}"); Console.ReadLine(); host.Dispose(); }
protected virtual void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { // Dispose managed state (managed objects) RestModule.Sim = null; if (_host != null) { _host.Stop(); _host.Dispose(); _host = null; } } _disposedValue = true; } }
static void Main(string[] args) { using (var nancyHost = new NancyHost(new CustomBootstrapper(), new HostConfiguration() { RewriteLocalhost = true, UrlReservations = new UrlReservations() { CreateAutomatically = true } }, new Uri("http://localhost:80/"))) { nancyHost.Start(); Console.WriteLine($"http://{GetLocalIPAddress()}:80/"); while (true) { Thread.Sleep(100); } } }
public static void Main(string[] args) { var endpointAddress = args[0]; using (var host = new NancyHost(new Uri(endpointAddress))) { host.Start(); Console.WriteLine("Running on {0}...", endpointAddress); if (Is_running_on_Mono) { Console.WriteLine("Ctrl-C to stop service host"); UnixSignal.WaitAny(UnixTerminationSignals); } else { Console.WriteLine("ENTER to stop service host"); Console.ReadLine(); } } }
static Globals() { // start server for debug try { HostConfiguration hostConfigs = new HostConfiguration() { UrlReservations = new UrlReservations() { CreateAutomatically = true } }; nancyHost = new NancyHost(hostConfigs, new Uri("http://localhost:1234/")); nancyHost.Start(); TForms = new Dictionary <string, TestedForm>(); Logger.WriteLog($"Nancy REST TEST Server started(>>>) at port=1234"); } catch (Exception ex) { Logger.WriteError(ex); } }
static void Main() { const int PORT = 8899; var uri = new Uri($"http://localhost:{PORT}/"); using (var nancyHost = new NancyHost(uri)) { nancyHost.Start(); var consulRegistryHost = new ConsulRegistryHost(); var serviceRegistry = new ServiceRegistry(consulRegistryHost); serviceRegistry.RegisterServiceAsync("price", "1.3.2", uri) .Wait(); Console.WriteLine($"Now listening on {uri}/price. Press enter to stop"); Console.ReadKey(); } }
public void Start() { try { //系统初始化 var bootstrapper = new Bootstrapper(); HostConfiguration hostConfigs = new HostConfiguration(); hostConfigs.UrlReservations.CreateAutomatically = true; nancyHost = new NancyHost(bootstrapper, hostConfigs, uris.ToArray()); if (nancyHost != null) { nancyHost.Start(); } } catch (Exception ex) { Console.WriteLine("启动服务出错Message:" + ex.Message); Console.WriteLine("启动服务出错StackTrace:" + ex.StackTrace); } }
private void LaunchServer(AutoResetEvent autoEvent) { HostConfiguration config = new HostConfiguration() { UrlReservations = new UrlReservations() { CreateAutomatically = true } }; NancyHost host = new NancyHost(config, new Uri("http://localhost:5412")); host.Start(); Console.WriteLine("Host started... Do ^C to exit."); Console.CancelKeyPress += (sender, e) => { Console.WriteLine("^C received, exitting..."); host.Dispose(); autoEvent.Set(); }; }
static void Main(string[] args) { // start VS as admin to run this var server = new NancyHost(new CustomBootstrapper(), GetUriParams(8282)); server.Start(); Console.WriteLine("started!"); Console.WriteLine("press any key to exit"); DataManager.Topics.Add(new Table { ID = 100, Issued = DateTimeOffset.Parse("2017-08-27 13:00Z"), Name = "Test table", Serial = 1, Headers = new[] { "col1", "col2" }, Data = new string[][] { new string[] { "a1", "b1" }, new string[] { "a2", "b2" } } }); DataManager.Topics.Add(new FreeText { ID = 200, Issued = DateTimeOffset.Parse("2017-08-27 13:15Z"), Name = "Test free text", Serial = 1, Content = "Hello world\r\nthis is a second line" }); //Process.Start("http://localhost:8282"); Console.ReadKey(); }
static void Main(string[] args) { try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var amlStudioStart = args.FirstOrDefault(a => a.StartsWith("/amlstudio:", StringComparison.OrdinalIgnoreCase)); _serverPort = FreeTcpPort(); var config = new HostConfiguration(); config.RewriteLocalhost = false; using (var host = new NancyHost(config, new Uri("http://localhost:" + _serverPort.ToString()))) { host.Start(); if (string.IsNullOrEmpty(amlStudioStart)) { Application.Run(new AppContext(new EditorWindow())); } else { var connName = amlStudioStart.Substring(11); var conn = ConnectionManager.Current.Library.Connections.FirstOrDefault(c => c.ConnectionName.Equals(connName, StringComparison.OrdinalIgnoreCase)); var win = new EditorWindow(); if (conn != null) { win.SetConnection(conn); } Application.Run(new AppContext(win)); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Innovator Admin: Crash"); File.WriteAllText(Path.Combine(Path.GetDirectoryName(AssemblyPath), "LastError.txt"), ex.ToString()); } }
static void Main(string[] args) { HostConfiguration hostConfiguration = new HostConfiguration() { RewriteLocalhost = false }; // run behind nginx proxy _host = new NancyHost(hostConfiguration, new Uri("http://localhost:8888")); try { Conn = R.Connection() .Hostname("localhost") .Port(RethinkDBConstants.DefaultPort) .Timeout(RethinkDBConstants.DefaultTimeout) .Connect(); }catch (Exception e) { Console.WriteLine("Can't connect to RethinkDB database: " + e.Message); return; } _host.Start(); Console.CancelKeyPress += (sender, e) => { Console.WriteLine("^c pressed quiting.."); _host.Dispose(); Conn.Close(); Environment.Exit(0); }; while (true) { Thread.Sleep(1); } }
public Uri Start() { bool nancyStarted = false; // Need to retry in order to ensure that we properly startup after any failures for (var i = 0; i < 3; i++) { _Nancy = new NancyHost(_uri); try { _Nancy.Start(); nancyStarted = true; break; } catch (HttpListenerException) { UriBuilder ub = new UriBuilder(_uri); ub.Port = ++port; _uri = ub.Uri; } catch { try { _Nancy.Stop(); } catch (Exception e) { } } } if (!nancyStarted) { //Don't allow to run the tests if Nancy not started. throw new Exception(); } return(_uri); }
static void Main() { HostConfiguration hostConfiguration = new HostConfiguration(); { hostConfiguration.UrlReservations.CreateAutomatically = true; hostConfiguration.RewriteLocalhost = true; } var uriStrings = new List <string> { String.Format("http://localhost:{0}", Program.Port) }; var uris = uriStrings .Select(uriString => new Uri(uriString)) .ToArray(); //start host using (var host = new NancyHost(hostConfiguration, uris)) { host.Start(); Console.WriteLine("Nancy now listening on:"); foreach (var uriString in uriStrings) { Console.WriteLine(uriString); } //refresh the ports var useServoCache = Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift); PortPool.X.Refresh(useServoCache); //start scheduler (it will start with making requests to the host, so must be after host starts) Scheduler.X.Start(); while (true) { Thread.Sleep(10000); } } }
private void StartServer_Click(object sender, EventArgs e) { if (isServerUp) { hostg.Stop(); StartServer.Text = "Start Server"; isServerUp = false; } else { if (Globals.settings.tintEnabled) { foreach (string file in Directory.GetFiles(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Content/html/img"))) { using (MagickImage image = new MagickImage(file)) { image.Colorize(new MagickColor(Globals.settings.tintColor), new Percentage(100)); image.Write(file); } } } isServerUp = true; try { UrlLinkLabel.Text = "http://localhost:" + Globals.settings.serverPort + "/Content/html/bts-game.html"; HostConfiguration config = new HostConfiguration(); config.UrlReservations.CreateAutomatically = true; NancyHost host = new NancyHost(config, new Uri("http://localhost:" + Globals.settings.serverPort)); host.Start(); hostg = host; StartServer.Text = "Stop Server"; } catch (Exception ee) { Console.WriteLine(ee.Message); throw; } } }
public static void Main(string[] args) { var options = new Options(); try { Parser.Default.ParseArgumentsStrict(args, options); if (options.ShowVersionInformation) { var assembly = typeof(Program).Assembly; var versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); Console.WriteLine(versionInfo.ProductVersion); } else { var bootstrapper = new Bootstrapper(options); var hostConfiguration = new HostConfiguration { UrlReservations = new UrlReservations() { CreateAutomatically = true } }; using (var host = new NancyHost(bootstrapper, hostConfiguration, new Uri(options.ServiceUri))) { host.Start(); Log.Info(m => m( "{0} is running on {1}", options.ServiceId, options.ServiceUri)); Console.ReadLine(); } } } catch (Exception ex) { Log.Fatal(m => m( "{0} service starting failed! Error: {1}", options.ServiceId, ex.ToString())); } }
private static void StartServer(string solutionPath, int port, bool verbose) { try { Configuration.ConfigurationLoader.Load(); var solution = new CSharpSolution(); Console.CancelKeyPress += (sender, e) => { solution.Terminated = true; Console.WriteLine("Ctrl-C pressed"); e.Cancel = true; }; var nancyHost = new NancyHost(new Bootstrapper(solution, new NativeFileSystem(), verbose), new HostConfiguration { RewriteLocalhost = false }, new Uri("http://localhost:" + port)); nancyHost.Start(); Console.WriteLine("OmniSharp server is listening"); solution.LoadSolution(solutionPath); Console.WriteLine("Solution has finished loading"); while (!solution.Terminated) { Thread.Sleep(1000); } Console.WriteLine("Quit gracefully"); nancyHost.Stop(); } catch (Exception e) { if (e is SocketException || e is HttpListenerException) { Console.Error.WriteLine("Detected an OmniSharp instance already running on port " + port + ". Press a key."); Console.ReadKey(); return; } throw; } }
static void Main(string[] args) { Console.CancelKeyPress += (sender, eventArgs) => { eventArgs.Cancel = true; Source.Cancel(); }; _nancyHost = new NancyHost(new Uri("http://localhost:5000"), new DefaultNancyBootstrapper(), new HostConfiguration { UrlReservations = new UrlReservations { CreateAutomatically = true } }); _nancyHost.Start(); Console.WriteLine("Press Ctrl-C to exit."); WaitHandle.WaitAll(new[] { Source.Token.WaitHandle }); }
public NancyHostWrapper(NancyHost host) { this.host = host; }
private static NancyHostWrapper CreateAndOpenSelfHost(INancyBootstrapper nancyBootstrapper = null, HostConfiguration configuration = null) { if (nancyBootstrapper == null) { nancyBootstrapper = new DefaultNancyBootstrapper(); } var host = new NancyHost( nancyBootstrapper, configuration, BaseUri); try { host.Start(); } catch { throw new SkipException("Skipped due to no Administrator access - please see test fixture for more information."); } return new NancyHostWrapper(host); }
public void Should_include_default_port_in_uri_prefixes() { // Given var host = new NancyHost(new Uri("http://localhost/")); // When var prefix = host.GetPrefixes().Single(); // Then prefix.ShouldEqual("http://+:80/"); }
protected override void OnStart(string[] args) { nancyHost = new NancyHost(new Uri(arguments.Url), new PulseBootstrapper()); nancyHost.Start(); }
public void Should_not_throw_when_disposed_without_starting() { // Given var bootstrapperMock = A.Fake<INancyBootstrapper>(); var host = new NancyHost(new Uri("http://localhost/"), bootstrapperMock); // When host.Dispose(); // Then A.CallTo(() => bootstrapperMock.Dispose()).MustHaveHappened(); }
public NancyPack Stop() { if (this.host != null) { this.host.Stop(); this.host.Dispose(); this.host = null; Console.WriteLine("Stopped hosting Nancy"); } return this; }
public NancyPack Go() { Guard.AgainstNullProperty("Boot", this.Boot); this.Stop(); this.host = this.Config != null ? new NancyHost(this.Boot, this.Config, this.uris.ToArray()) : new NancyHost(this.Boot, this.uris.ToArray()); try { this.host.Start(); } catch (Exception) { this.host = null; throw; } if (!this.uris.Any()) { Console.WriteLine("NOT hosting Nancy at any URL"); } else { foreach (var uri in this.uris) { Console.WriteLine("Hosting Nancy at: " + uri.ToString()); } } return this; }