本文整理汇总了C#中Microsoft.AspNetCore.Hosting.WebHostBuilder.UseServer方法的典型用法代码示例。如果您正苦于以下问题:C# WebHostBuilder.UseServer方法的具体用法?C# WebHostBuilder.UseServer怎么用?C# WebHostBuilder.UseServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNetCore.Hosting.WebHostBuilder
的用法示例。
在下文中一共展示了WebHostBuilder.UseServer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
Console.WriteLine($"OmniSharp: {string.Join(" ", args)}");
var applicationRoot = Directory.GetCurrentDirectory();
var serverPort = 2000;
var logLevel = LogLevel.Information;
var hostPID = -1;
var transportType = TransportType.Http;
var otherArgs = new List<string>();
var plugins = new List<string>();
var enumerator = args.GetEnumerator();
while (enumerator.MoveNext())
{
var arg = (string)enumerator.Current;
if (arg == "-s")
{
enumerator.MoveNext();
applicationRoot = Path.GetFullPath((string)enumerator.Current);
}
else if (arg == "-p")
{
enumerator.MoveNext();
serverPort = int.Parse((string)enumerator.Current);
}
else if (arg == "-v")
{
logLevel = LogLevel.Debug;
}
else if (arg == "--hostPID")
{
enumerator.MoveNext();
hostPID = int.Parse((string)enumerator.Current);
}
else if (arg == "--stdio")
{
transportType = TransportType.Stdio;
}
else if (arg == "--plugin")
{
enumerator.MoveNext();
plugins.Add((string)enumerator.Current);
}
else
{
otherArgs.Add((string)enumerator.Current);
}
}
Environment = new OmnisharpEnvironment(applicationRoot, serverPort, hostPID, logLevel, transportType, otherArgs.ToArray());
var config = new ConfigurationBuilder()
.AddCommandLine(new[] { "--server.urls", "http://localhost:" + serverPort });
var writer = new SharedConsoleWriter();
var builder = new WebHostBuilder()
.UseConfiguration(config.Build())
.UseEnvironment("OmniSharp")
.UseStartup(typeof(Startup))
.ConfigureServices(serviceCollection =>
{
serviceCollection.AddSingleton<IOmnisharpEnvironment>(Environment);
serviceCollection.AddSingleton<ISharedTextWriter>(writer);
serviceCollection.AddSingleton<PluginAssemblies>(new PluginAssemblies(plugins));
serviceCollection.AddSingleton<IOmnisharpAssemblyLoader>(new OmnisharpAssemblyLoader());
});
if (transportType == TransportType.Stdio)
{
builder.UseServer(new StdioServer(Console.In, writer));
}
else
{
builder.UseServer("Microsoft.AspNetCore.Server.Kestrel");
}
using (var app = builder.Build())
{
app.Start();
var appLifeTime = app.Services.GetRequiredService<IApplicationLifetime>();
Console.CancelKeyPress += (sender, e) =>
{
appLifeTime.StopApplication();
e.Cancel = true;
};
if (hostPID != -1)
{
try
{
var hostProcess = Process.GetProcessById(hostPID);
hostProcess.EnableRaisingEvents = true;
hostProcess.OnExit(() => appLifeTime.StopApplication());
}
catch
//.........这里部分代码省略.........