本文整理汇总了C#中Nancy.Hosting.Self.HostConfiguration类的典型用法代码示例。如果您正苦于以下问题:C# HostConfiguration类的具体用法?C# HostConfiguration怎么用?C# HostConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HostConfiguration类属于Nancy.Hosting.Self命名空间,在下文中一共展示了HostConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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
}
}
示例2: 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();
}
}
示例3: Main
static void Main(string[] args)
{
var url = "https://localhost:44388";
var uri =
new Uri(url);
var config = new HostConfiguration
{
UrlReservations = new UrlReservations
{
CreateAutomatically = true
}
};
using (WebApp.Start<Startup>(url))
{
Console.WriteLine("Running on {0}", url);
Console.WriteLine("Press enter to exit");
Console.ReadLine();
}
//using (var host = new NancyHost(config, uri))
//{
// host.Start();
// Console.WriteLine("Your application is running on " + uri);
// Console.WriteLine("Press any [Enter] to close the host.");
// Console.ReadLine();
//}
}
示例4: 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!");
}
示例5: Configure
public void Configure(NancyServiceConfiguration nancyServiceConfiguration)
{
var nancyHostConfiguration = new HostConfiguration();
if (nancyServiceConfiguration.NancyHostConfigurator != null)
{
nancyServiceConfiguration.NancyHostConfigurator(nancyHostConfiguration);
}
NancyServiceConfiguration = nancyServiceConfiguration;
NancyHostConfiguration = nancyHostConfiguration;
_urlReservationsHelper = new UrlReservationsHelper(NancyServiceConfiguration.Uris, NancyHostConfiguration);
NancyHost = new Lazy<NancyHost>(() => {
if (NancyServiceConfiguration.Bootstrapper != null)
{
return new NancyHost(NancyServiceConfiguration.Bootstrapper, NancyHostConfiguration, NancyServiceConfiguration.Uris.ToArray());
}
else
{
return new NancyHost(NancyHostConfiguration, NancyServiceConfiguration.Uris.ToArray());
}
});
}
示例6: Main
public static void Main(string[] args)
{
var logger = LogManager.GetLogger("ServerStartup");
try
{
LoadApplicationConfiguration(args);
}
catch(Exception ex) when (ex is FileNotFoundException || ex is InvalidOperationException || ex is JsonReaderException)
{
logger.Error("Cannot load configuration file!");
logger.Error(ex);
return;
}
logger.Info($"Using {Configuration.ConfigFileName} configuration file.");
Uri nancyUri = new Uri(Configuration.MockUri);
//Starting Nancy self-hosted process
HostConfiguration nancyConfig = new HostConfiguration() { RewriteLocalhost = false };
using(var host = new NancyHost(nancyConfig, nancyUri))
{
host.Start();
logger.Info($"Nancy server is listening on \"{nancyUri}\". Press [anything] Enter to stop the server!");
Console.ReadLine();
}
}
示例7: Main
static void Main(string[] args)
{
int port = args.Length > 0
? int.Parse(args[0])
: TestingPort;
StartupKey = args.Length > 1
? args[1]
: null;
var address = string.Format("http://localhost:{0}", port);
var hostConfig = new HostConfiguration
{
UrlReservations = new UrlReservations
{
CreateAutomatically = true
}
};
using (var host = new NancyHost(hostConfig, new Uri(address)))
{
host.Start();
Console.WriteLine("started {0} {1}", port, StartupKey);
while (true)
{
Thread.Sleep(1000);
}
}
}
示例8: ThreadBegin
private void ThreadBegin()
{
HostConfiguration config = new HostConfiguration();
config.UrlReservations.CreateAutomatically = true;
// TODO: Allow user to change the port
using (var host = new NancyHost(config, new Uri("http://localhost:8957")))
{
try
{
host.Start();
// Keep the server thread alive
while (true);
}
catch (AutomaticUrlReservationCreationFailureException ex)
{
Logger.Log("Couldn't start HTTP server on this port");
MessageBox.Show(
"Couldn't start HTTP server on this port",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error
);
}
}
}
示例9: 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();
}
示例10: Main
static void Main(string[] args)
{
Logging.Log.Info("Starting AnimeRecs web app");
HostConfiguration config = new HostConfiguration()
{
RewriteLocalhost = false
};
string portString = ConfigurationManager.AppSettings["Hosting.Port"];
uint port;
if (!uint.TryParse(portString, out port))
{
throw new Exception("Hosting.Port is not a valid port number.");
}
using (var host = new NancyHost(config, new Uri(string.Format("http://localhost:{0}", port))))
{
host.Start();
Logging.Log.InfoFormat("Started listening on port {0}", port);
#if MONO
WaitForUnixStopSignal();
#else
Console.ReadLine();
#endif
Logging.Log.Info("Got stop signal, stopping web app");
}
}
示例11: Main
static void Main(string[] args)
{
var config = new HostConfiguration()
{
UrlReservations = new UrlReservations
{
CreateAutomatically = true
}
};
var container = MainContainer.Instance.Container;
var serverUrl = container.Resolve<IApplicationParameters>().ServerURL;
try
{
using (var host = new NancyHost(config, new Uri(serverUrl)))
{
host.Start();
Console.WriteLine("Server is running: {0}", serverUrl);
var backgroundTask = new BgTask(MainContainer.Instance);
backgroundTask.Start();
Console.WriteLine("Background process started");
Console.WriteLine("Press ENTER to stop the server...");
Console.ReadLine();
Console.WriteLine("Exiting...");
backgroundTask.Stop();
}
}
catch (Exception ex)
{
Console.WriteLine("Couldn't start the server with this Url: {0}", serverUrl);
}
}
示例12: 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();
}
示例13: Main
static int Main(string[] args)
{
if (args.Length == 0 ||
string.IsNullOrEmpty(UserKey = args[0]))
{
Console.WriteLine("userKey argument is required");
return 1;
}
const int port = 40001;
var address = string.Format("http://localhost:{0}", port);
var hostConfig = new HostConfiguration
{
UrlReservations = new UrlReservations
{
CreateAutomatically = true
}
};
using (var host = new NancyHost(hostConfig, new Uri(address)))
{
host.Start();
var scheduler = ApiBootstrapper.Container.Resolve<Scheduler>();
Console.WriteLine("started {0}", port);
while (scheduler.State != SystemState.Finished)
{
Thread.Sleep(1000);
}
}
return 0;
}
示例14: Main
public static void Main(string[] args)
{
// bool from configuration files.
OsmSharp.Service.Tiles.ApiBootstrapper.BootFromConfiguration();
// start listening.
var uri = new Uri("http://localhost:1234");
HostConfiguration configuration = new HostConfiguration();
configuration.UrlReservations.CreateAutomatically = true;
using (var host = new NancyHost(configuration, uri))
{
try
{
host.Start();
Console.WriteLine("The OsmSharp routing service is running at " + uri);
Console.WriteLine("Press [Enter] to close the host.");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.WriteLine("Press [Enter] to close the host.");
Console.ReadLine();
}
}
}
示例15: Main
static void Main(string[] args)
{
var port = 3400;
HostConfiguration hostConfigs = new HostConfiguration();
hostConfigs.UrlReservations.CreateAutomatically = true;
while (true)
{
try
{
using (var host = new NancyHost(hostConfigs, new Uri("http://localhost:" + port)))
{
host.Start();
Console.WriteLine("Your application is running on port " + port);
Console.WriteLine("Press any key to close the host.");
Console.ReadKey();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
port++;
}
}
}