本文整理汇总了C#中Nancy.Hosting.Self.NancyHost.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# NancyHost.Stop方法的具体用法?C# NancyHost.Stop怎么用?C# NancyHost.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.Hosting.Self.NancyHost
的用法示例。
在下文中一共展示了NancyHost.Stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunAsConsoleApp
private static void RunAsConsoleApp(string[] args)
{
// Running from the command line
WriteWelcomeHeader();
#if DEBUG
Logging.EnableConsoleOutput(true);
#else
Logging.EnableConsoleOutput(false);
#endif
var serviceArgs = new ServiceArgs();
if (CommandLine.Parser.ParseArgumentsWithUsage(args, serviceArgs))
{
try
{
var bootstrapper = ServiceBootstrap.GetBootstrapper(serviceArgs);
var baseUris = serviceArgs.BaseUris.Select(x => x.EndsWith("/") ? new Uri(x) : new Uri(x + "/")).ToArray();
var nancyHost = new NancyHost(bootstrapper, new HostConfiguration {AllowChunkedEncoding = false}, baseUris);
Nancy.StaticConfiguration.DisableErrorTraces = !serviceArgs.ShowErrorTraces;
nancyHost.Start();
Console.ReadLine();
nancyHost.Stop();
}
catch (BootstrapperException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("Unhandled exception in server: {0}", ex.Message);
}
}
}
示例2: Main
static void Main(string[] args)
{
var parsedArgs = Parser.Default.ParseArguments<Options> (args);
if (!parsedArgs.Errors.Any () && parsedArgs.Value != null) {
var options = parsedArgs.Value;
var domain = options.Domain ?? ConfigurationManager.AppSettings.Get ("Nancy.Host") ?? "127.0.0.1";
var port = options.Port ?? ConfigurationManager.AppSettings.Get ("Nancy.Port") ?? "9999";
var uri = new Uri ("http://" + domain + ":" + port);
var configuration = new HostConfiguration();
configuration.UnhandledExceptionCallback = HandleException;
// initialize an instance of NancyHost (found in the Nancy.Hosting.Self package)
var nancyHost = new NancyHost (new Bootstrapper (), uri);
nancyHost.Start (); // start hosting
while (true) {
Thread.Sleep (10000000);
}
nancyHost.Stop (); // stop hosting
}
}
示例3: Main
public static void Main(string[] args)
{
Config.LoadFromAppSettings();
GenericFileResponse.SafePaths.Add(Config.PackageRepositoryPath);
HostConfiguration hostConfigs = new HostConfiguration()
{
UrlReservations = new UrlReservations() { CreateAutomatically = true }
};
using (var host = new NancyHost(new Uri(string.Format("http://localhost:{0}", Config.Port)), new NusharpBootstrapper(), hostConfigs))
{
host.Start();
//Under mono if you daemonize a process a Console.ReadLine will cause an EOF
//so we need to block another way
if (args.Any(s => s.Equals("-d", StringComparison.CurrentCultureIgnoreCase)))
{
Thread.Sleep(Timeout.Infinite);
}
else
{
Console.ReadKey();
}
host.Stop();
}
}
示例4: Main
public static void Main(string[] args)
{
const string uri = "http://localhost:8080";
Console.WriteLine("Iniciando o Nancy em " + uri);
// Inicializando uma instância do NancyHost
var host = new NancyHost(new Uri(uri));
// Inicia a hospedagem
host.Start();
// Verifica se está rodando o Mono
if (Type.GetType("Mono.Runtime") != null)
{
// No Mono, os processos irão geralmente executar como serviços
// - isso permite escutar sinais de término (CTRL + C, shutdown, etc)
// e finaliza corretamente
UnixSignal.WaitAny(new[]
{
new UnixSignal(Signum.SIGINT),
new UnixSignal(Signum.SIGTERM),
new UnixSignal(Signum.SIGQUIT),
new UnixSignal(Signum.SIGHUP)
});
}
else
{
Console.ReadLine();
}
Console.WriteLine("Parando o Nancy");
// Termina a hospedagem
host.Stop();
}
示例5: Main
/// <summary>
/// Start hosting the application.
/// </summary>
/// <param name="arguments">
/// The arguments.
/// </param>
public static void Main(string[] arguments)
{
var url = new Uri(ConfigurationManager.AppSettings["HostUrl"]);
var configuration = new HostConfiguration
{
UnhandledExceptionCallback = exception => Console.WriteLine(exception)
};
var host = new NancyHost(configuration, url);
host.Start();
if (arguments.Any(s => s.Equals("-d", StringComparison.CurrentCultureIgnoreCase)))
{
Thread.Sleep(Timeout.Infinite);
}
else
{
Console.WriteLine("Server running on {0}, press Enter to exit...", url);
Console.ReadLine();
}
host.Stop();
}
示例6: Run
public void Run(CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
return;
var nancyConfig = new HostConfiguration
{
UrlReservations = new UrlReservations
{
CreateAutomatically = true
}
};
var bootstrapper = new ApiBootstrapper(_repository);
var host = new NancyHost(bootstrapper, nancyConfig, _baseUri);
cancellationToken.Register(() =>
{
Log.InfoFormat("Stopping Nancy host at \"{0}\".", _baseUri);
host.Stop();
Log.InfoFormat("Nancy host at \"{0}\" successfully stopped.", _baseUri);
});
Log.InfoFormat(CultureInfo.InvariantCulture, "Starting Nancy host at \"{0}\".", _baseUri);
host.Start();
}
示例7: Main
static void Main(string[] args)
{
var host = new NancyHost(new Uri(startUrl));
Console.WriteLine("Launching Email Visualiser.");
try
{
host.Start();
Console.WriteLine("Server has launched.");
Console.WriteLine("Launching browser...");
Process.Start(startUrl);
Console.WriteLine("Press any key to stop the server.");
Console.ReadLine();
}
catch (Exception e)
{
TextWriter errorWriter = Console.Error; //TODO change to a logger
errorWriter.WriteLine("------An error has been encountered.------");
errorWriter.WriteLine(e.Message);
#if DEBUG
errorWriter.WriteLine(e.InnerException);
errorWriter.WriteLine(e.StackTrace);
#endif
errorWriter.WriteLine("------The application will now close.------");
}
finally
{
host.Stop();
}
}
示例8: Main
static void Main(string[] args)
{
// Note: The URI must *exactly* match the one specified in the URL ACL.
// This leads to a problem when you use +, because the Uri constructor doesn't like it.
var uri = "http://localhost:1234/";
if (args.Length != 0)
uri = args[0];
var stop = new ManualResetEvent(false);
Console.CancelKeyPress += (sender, e) =>
{
Console.WriteLine("^C");
stop.Set();
};
var host = new NancyHost(new Uri(uri));
host.Start();
Console.WriteLine("Nancy Self Host listening on {0}", uri);
Console.WriteLine("Press Ctrl+C to quit.");
stop.WaitOne();
host.Stop();
}
示例9: Main
static void Main(params string[] args)
{
#if DEBUG
Assembly.LoadFile(Path.Combine(Directory.GetCurrentDirectory(), "Aqueduct.Appia.Razor.dll"));
#endif
var options = new Options();
ICommandLineParser parser = new CommandLineParser();
parser.ParseArguments(args, options);
if (string.IsNullOrEmpty(options.ExportPath) == false)
{
var exporter = new HtmlExporter(options.ExportPath,
new Configuration(),
new Aqueduct.Appia.Core.Bootstrapper())
{ Verbose = options.Verbose };
exporter.Initialise();
exporter.Export();
}
else
{
var ip = options.Address == "*" ? IPAddress.Any : IPAddress.Parse(options.Address);
var nancyHost = new NancyHost(ip, options.Port, new Aqueduct.Appia.Core.Bootstrapper());
nancyHost.Start();
Console.WriteLine(String.Format("Nancy now listening - navigate to http://{0}:{1}/. Press enter to stop", options.Address, options.Port));
Console.ReadKey();
nancyHost.Stop();
Console.WriteLine("Stopped. Good bye!");
}
}
示例10: Run
public void Run()
{
EnsureInstallation();
foreach (var service in _services)
{
Console.WriteLine("Starting service {0}", service.ServiceName);
service.Start();
}
_nancy = new NancyHost(_uris);
_nancy.Start();
Console.WriteLine("Running server at {0}", string.Join(", ", _uris
.Select(u => u.ToString())
));
Console.ReadLine();
Console.WriteLine("Stopping server");
_nancy.Stop();
foreach (var service in _services)
{
Console.WriteLine("Stopping service {0}", service.ServiceName);
service.Stop();
}
}
示例11: Main
static void Main(string[] args)
{
BeagleBoneBlack.SetupOverlays();
TankManager.DmxControl = new DMXControl(10);
TankManager.DmxLED = new LEDStrip(TankManager.DmxControl);
TankManager.TreadsLED = new LEDStrip(new LPD8806((5 * 32) * 3, "/dev/spidev1.0"));
TankManager.BarrelLED = new LEDStrip(new LPD8806(77, "/dev/spidev2.0"));
TankManager.Sensor = new SpeedSensor("/dev/ttyO1");
TankManager.StartTheTank();
Console.WriteLine("Starting Nancy self host");
NancyHost host = new NancyHost( new Uri("http://localhost:8080"));
host.Start();
Console.WriteLine("Awaiting commands");
ConsoleKeyInfo key = new ConsoleKeyInfo();
while(key.Key != ConsoleKey.Escape)
{
key = Console.ReadKey(true);
}
Console.WriteLine("Stopping Nancy");
host.Stop(); // stop hosting
TankManager.StopTheTank();
}
示例12: Main
static void Main(string[] args)
{
if (args != null && args.Length >= 2)
{
if (args[0] == "-conf" && File.Exists(args[1]))
AppConfig.ChangeAppConfig(args[1]);
}
// initialize an instance of NancyHost (found in the Nancy.Hosting.Self package)
string uri = (string)ConfigurationManager.AppSettings["Nancy.Uri"];
if (string.IsNullOrEmpty(uri))
throw new Exception("The parameter 'Nancy.Uri' is not specified in .config file.");
var host = new NancyHost(new Uri(uri), new CustomBootstrapper());
host.Start(); // start hosting
Console.WriteLine();
Console.Write("Service is ready to receive requests on ");
ConsoleColor prevColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(uri.ToString());
Console.ForegroundColor = prevColor;
Console.ReadKey();
host.Stop(); // stop hosting
}
示例13: Main
public static void Main (string[] args)
{
var hostConfiguration = new HostConfiguration
{
UrlReservations = new UrlReservations() { CreateAutomatically = true }
};
var nancyHost = new NancyHost(hostConfiguration,
new Uri("http://localhost:8080/"));
nancyHost.Start();
Console.WriteLine("Nancy now listening at http://localhost:8080/. Press enter to stop");
ConsoleKeyInfo key = Console.ReadKey();
if ((int)key.Key == 0)
{
// Mono returns a ConsoleKeyInfo with a Key value of 0 when stdin is redirected
// See https://bugzilla.xamarin.com/show_bug.cgi?id=12551
// For now, just sleep, so that we can run in background with nohup
Thread.Sleep(Timeout.Infinite);
}
nancyHost.Stop();
Console.WriteLine("Stopped. Good bye!");
}
示例14: Main
public static void Main()
{
var host = new NancyHost(new Uri("http://localhost:5150"));
host.Start();
Console.ReadLine();
host.Stop();
}
示例15: Main
private static void Main(string[] args)
{
if (args.Length != 2 && args.Length != 3)
{
Console.WriteLine("WelcomePage.WebServer url root-directory [-open]");
return;
}
var url = new Uri(args[0]);
var rootDirectory = args[1];
bool openBrowser = args.Length == 3 && args[2].Equals("-open", StringComparison.InvariantCultureIgnoreCase);
var stop = new ManualResetEvent(false);
Console.CancelKeyPress += (sender, e) =>
{
Console.WriteLine("^C");
stop.Set();
};
var bootstrapper = new Bootstrapper(rootDirectory);
var configuration = new HostConfiguration { RewriteLocalhost = false };
var host = new NancyHost(bootstrapper, configuration, url);
host.Start();
Console.WriteLine("Nancy host listening on '{0}'. Press Ctrl+C to quit.", url);
if (openBrowser)
Process.Start(url.ToString());
stop.WaitOne();
host.Stop();
}