-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathProgram.cs
44 lines (42 loc) · 1.69 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Reflection;
namespace DBExportor
{
public class Program
{
public static ushort Port { get; private set; }
public static string Address { get; private set; }
public static DirectoryInfo DBFolder { get; private set; }
public static void Main(string[] args)
{
Port = (args.Where(p => p.StartsWith("-p")).LastOrDefault()?.Substring(2))
.ToUshort(8913);
var folderpath = args.Where(p => p.StartsWith("-d")).LastOrDefault()?.Substring(2);
DBFolder = new DirectoryInfo(String.IsNullOrEmpty(folderpath) ? Directory.GetCurrentDirectory() : folderpath);
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder()
.UseStartup<Startup>()
.UseKestrel(options =>
{
options.Listen(IPAddress.Loopback, Port);
var addrByte = new List<byte>();
addrByte.AddRange(IPAddress.Loopback.GetAddressBytes());
addrByte.AddRange(new byte[] { (byte)(Port / 256), (byte)(Port % 256) });
Address = Convert.ToBase64String(addrByte.ToArray());
Console.WriteLine($"listen on 127.0.0.1:{Port}");
Console.WriteLine($"Address:{Address}");
})
.Build();
}
}