forked from Xian55/WowClassicGrindBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartup.cs
More file actions
175 lines (143 loc) · 6.05 KB
/
Startup.cs
File metadata and controls
175 lines (143 loc) · 6.05 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using Core.Database;
using Frontend;
using MatBlazor;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http.Json;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi;
using PPather;
using Serilog;
using Serilog.Events;
using Serilog.Templates;
using Serilog.Templates.Themes;
using SharedLib;
using SharedLib.Logging;
using SharedLib.Converters;
using System;
using System.IO;
using System.Reflection;
using System.Threading;
namespace PathingAPI;
public sealed class Startup
{
private readonly IConfiguration configuration;
public Startup(IConfiguration configuration)
{
this.configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddLogging(builder =>
{
PathingAPILoggerSink sink = new();
builder.Services.AddSingleton(sink);
Log.Logger = new LoggerConfiguration()
//.MinimumLevel.Debug()
//.MinimumLevel.Verbose()
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information)
.Enrich.FromLogContext()
.Enrich.With<ShortSourceContextEnricher>()
.WriteTo.Sink(sink)
.WriteTo.File(new ExpressionTemplate(LogOutputTemplates.Default),
"out.log",
rollingInterval: RollingInterval.Day)
.WriteTo.Debug(new ExpressionTemplate(LogOutputTemplates.Default))
.WriteTo.Console(new ExpressionTemplate(LogOutputTemplates.Default, theme: TemplateTheme.Literate))
.CreateLogger();
ILoggerFactory logFactory = LoggerFactory.Create(builder =>
{
builder.ClearProviders().AddSerilog();
});
builder.Services.AddSingleton<Microsoft.Extensions.Logging.ILogger>(logFactory.CreateLogger(nameof(Program)));
});
Log.Information(DateTimeOffset.Now.ToString());
string exp = configuration["exp"]
?? Environment.GetEnvironmentVariable("exp")
?? ClientVersion.SoM.ToString().ToLower(System.Globalization.CultureInfo.InvariantCulture);
Log.Information($"Expansion: {exp}");
services.AddMatBlazor();
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<CancellationTokenSource>();
services.AddSingleton<DataConfig>(x => DataConfig.Load(exp));
services.AddSingleton<WorldMapAreaDB>();
services.AddSingleton<PPatherService>();
services.AddSingleton<FactionTemplateDB>();
services.AddSingleton<CreatureDB>();
services.AddSingleton<AreaDB>();
services.AddSingleton(provider =>
provider.GetRequiredService<IOptions<JsonOptions>>().Value.SerializerOptions);
services.Configure<JsonOptions>(options =>
{
options.SerializerOptions.PropertyNameCaseInsensitive = true;
options.SerializerOptions.Converters.Add(new Vector3Converter());
options.SerializerOptions.Converters.Add(new Vector4Converter());
});
services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
options.JsonSerializerOptions.Converters.Add(new Vector3Converter());
options.JsonSerializerOptions.Converters.Add(new Vector4Converter());
});
services.AddSignalR()
.AddMessagePackProtocol(options =>
{
options.SerializerOptions.WithCompression(MessagePack.MessagePackCompression.Lz4BlockArray);
});
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Pathing API", Version = "v1" });
//// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlDocumentPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
if (File.Exists(xmlDocumentPath))
{
c.IncludeXmlComments(xmlDocumentPath);
}
});
services.BuildServiceProvider(new ServiceProviderOptions() { ValidateOnBuild = true });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "PPather API V1");
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCustomStaticFiles(env);
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<WatchHub>(WatchHub.Url);
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
endpoints.MapControllers();
endpoints.MapRazorPages();
});
}
}