|
@@ -1,8 +1,14 @@
|
|
|
-using Microsoft.AspNetCore.Builder;
|
|
|
+using IES.ExamServer.DI.SignalRHost;
|
|
|
+using Microsoft.AspNetCore.Builder;
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
+using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
+using System.IO;
|
|
|
using System.Windows;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
|
|
|
namespace IES.ExamServer
|
|
|
{
|
|
@@ -23,11 +29,28 @@ namespace IES.ExamServer
|
|
|
{
|
|
|
// 这里是创建 ASP.NET 版通用主机的代码
|
|
|
var builder = WebApplication.CreateBuilder(Environment.GetCommandLineArgs());
|
|
|
- builder.WebHost.UseUrls("http://*:5000;https://*:5001");
|
|
|
+ builder.Configuration.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
|
|
|
+ //builder.WebHost.UseUrls("http://*:5000;https://*:5001");
|
|
|
+
|
|
|
// 注册主窗口和其他服务
|
|
|
builder.Services.AddControllersWithViews();
|
|
|
builder.Services.AddSingleton<MainWindow>();
|
|
|
builder.Services.AddSingleton(this);
|
|
|
+ builder.Services.AddHttpClient();
|
|
|
+ builder.Services.AddSignalR();
|
|
|
+ builder.Services.AddHttpContextAccessor();
|
|
|
+ string path = $"{builder.Environment.ContentRootPath}/Configs";
|
|
|
+ builder.Services.AddCors(options =>
|
|
|
+ {
|
|
|
+ options.AddDefaultPolicy(
|
|
|
+ builder =>
|
|
|
+ {
|
|
|
+
|
|
|
+ builder.AllowAnyOrigin()
|
|
|
+ .AllowAnyHeader()
|
|
|
+ .AllowAnyMethod();
|
|
|
+ });
|
|
|
+ });
|
|
|
var app = builder.Build();
|
|
|
// 这里是文件类型映射,如果你的静态文件在浏览器中加载报 404,那么需要在这里注册,这里我加载一个 3D 场景文件的类型
|
|
|
var contentTypeProvider = new FileExtensionContentTypeProvider();
|
|
@@ -47,6 +70,7 @@ namespace IES.ExamServer
|
|
|
app.UseAuthentication();
|
|
|
app.UseAuthorization();
|
|
|
app.MapControllers();
|
|
|
+ app.MapHub<SignalRExamServerHub>("/signalr/screen").RequireCors("any");
|
|
|
WebApplication = app;
|
|
|
// 处理退出事件,退出 App 时关闭 ASP.NET Core
|
|
|
Exit += async (s, e) => await WebApplication.StopAsync();
|