-
Notifications
You must be signed in to change notification settings - Fork 3
/
Program.cs
66 lines (62 loc) · 2.22 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
54
55
56
57
58
59
60
61
62
63
64
65
66
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using PcrBattleChannel.Algorithm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace PcrBattleChannel
{
public class Program
{
private static readonly Dictionary<string, Action<string>> _argHandlers = new()
{
{ "admin", val => Areas.Identity.Pages.Account.RegisterModel.AdminQQ = ulong.Parse(val) },
{ "yobot_sync", val => YobotSyncScheduler.Interval = TimeSpan.FromMinutes(double.Parse(val)) },
{ "allow_add_guild", val => Pages.Home.AddGuildModel.IsAllowed = true },
{ "skip_im_loading", val => Startup.LoadIMContext = false },
{ "forbid_register", val => Areas.Identity.Pages.Account.RegisterModel.AllowRegister = false },
};
private static void HandleArgs(string[] args)
{
foreach (var arg in args.Select(aa => aa.Split('=')).GroupBy(aa => aa[0]))
{
if (!_argHandlers.TryGetValue(arg.Key, out var handler))
{
throw new Exception($"Unknown argument {arg.Key}");
}
if (arg.Count() != 1)
{
throw new Exception($"Duplicate argument {arg.Key}");
}
var val = arg.First();
handler(val.Length switch
{
1 => null,
2 => val[1],
_ => throw new Exception($"Invalid argument {arg.Key}"),
});
}
}
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
}
public static void Main(string[] args)
{
try
{
HandleArgs(args);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return;
}
CreateHostBuilder(args).Build().Run();
}
}
}