-
Notifications
You must be signed in to change notification settings - Fork 6
/
Program.cs
53 lines (41 loc) · 1.54 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace SqlToElasticSearchConverter {
public class Program {
public static void Main(string[] args) {
CreateWebHostBuilder(args).Build().Run();
}
//public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
// WebHost.CreateDefaultBuilder(args)
// .UseStartup<Startup>();
public static IWebHostBuilder CreateWebHostBuilder(string[] args) {
// support for custom ports
var appArgs = new Arguments();
Parser.ParseArgumentsWithUsage(args, appArgs);
return WebHost.CreateDefaultBuilder(args)
.ApplyPorts(appArgs)
.UseStartup<Startup>();
}
}
public static class WebHostBuilderExtension {
public static IWebHostBuilder ApplyPorts(this IWebHostBuilder host, Arguments appArgs) {
if (appArgs.Port > 0) {
//host.UseUrls($"http://0.0.0.0:{appArgs.Port}");
host.UseUrls($"http://*:{appArgs.Port}");
}
return host;
}
}
[CommandLineArguments(CaseSensitive = false)]
public class Arguments {
[Argument(ArgumentType.AtMostOnce, HelpText = "Port", DefaultValue = -1, LongName = "Port", ShortName = "p")]
public int Port;
}
}