feat: asp serve frontend static files
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Newtonsoft.Json;
|
||||
using NLog;
|
||||
using NLog.Web;
|
||||
@@ -9,7 +10,6 @@ var logger = NLog.LogManager.Setup()
|
||||
.GetCurrentClassLogger();
|
||||
logger.Debug("Init Main...");
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -84,15 +84,24 @@ try
|
||||
// Application Settings
|
||||
var app = builder.Build();
|
||||
// Configure the HTTP request pipeline.
|
||||
// app.UseExceptionHandler(new ExceptionHandlerOptions()
|
||||
// {
|
||||
// AllowStatusCode404Response = true,
|
||||
// ExceptionHandlingPath = "/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();
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
// app.UseExceptionHandler("/Home/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();
|
||||
|
||||
// Serve static files
|
||||
logger.Info($"Use Static Files : {Path.Combine(Directory.GetCurrentDirectory(), "wwwroot")}");
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles(); // Serves files from wwwroot by default
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "assets")),
|
||||
RequestPath = "/assets"
|
||||
});
|
||||
app.MapFallbackToFile("index.html");
|
||||
}
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseCors();
|
||||
app.UseAuthorization();
|
||||
@@ -103,15 +112,13 @@ try
|
||||
app.UseSwaggerUi();
|
||||
// }
|
||||
|
||||
// Router
|
||||
app.MapControllers();
|
||||
|
||||
// Setup Program
|
||||
MsgBus.Init();
|
||||
|
||||
// Router
|
||||
// API Get
|
||||
app.MapGet("/", () => Results.Redirect("/swagger"));
|
||||
app.MapControllers();
|
||||
|
||||
app.Run("http://localhost:5000");
|
||||
app.Run();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
@@ -5,18 +5,20 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "http://localhost:5188",
|
||||
"applicationUrl": "http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:7070;http://localhost:5188",
|
||||
"applicationUrl": "https://localhost:7278;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Import Project="PublishAllRids.targets" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<RuntimeIdentifiers>win-x64;linux-x64;</RuntimeIdentifiers>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Import Project="PublishAllRids.xml" />
|
||||
<!-- <Import Project="PublishSPA.xml" /> -->
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<RuntimeIdentifiers>win-x64;linux-x64;</RuntimeIdentifiers>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<SpaRoot>../</SpaRoot>
|
||||
<SpaProxyServerUrl>http://localhost:5173</SpaProxyServerUrl>
|
||||
<SpaProxyLaunchCommand>npm run dev</SpaProxyLaunchCommand>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DotNext" Version="5.19.1" />
|
||||
<PackageReference Include="DotNext.Threading" Version="5.19.1" />
|
||||
<PackageReference Include="Honoo.IO.Hashing.Crc" Version="1.3.3" />
|
||||
<PackageReference Include="linq2db.AspNet" Version="5.4.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="9.0.4" />
|
||||
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NLog" Version="5.4.0" />
|
||||
@@ -23,6 +28,6 @@
|
||||
<PackageReference Include="NSwag.AspNetCore" Version="14.3.0" />
|
||||
<PackageReference Include="pythonnet" Version="3.0.5" />
|
||||
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@@ -8,6 +8,44 @@ using WebProtocol;
|
||||
|
||||
namespace server.Controllers;
|
||||
|
||||
// /// <summary>
|
||||
// /// [TODO:description]
|
||||
// /// </summary>
|
||||
// public class HomeController : ControllerBase
|
||||
// {
|
||||
// private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
//
|
||||
// string INDEX_HTML_PATH = Path.Combine(Environment.CurrentDirectory, "index.html");
|
||||
//
|
||||
// /// <summary>
|
||||
// /// [TODO:description]
|
||||
// /// </summary>
|
||||
// /// <returns>[TODO:return]</returns>
|
||||
// [HttpGet("/")]
|
||||
// public IResult Index()
|
||||
// {
|
||||
// return TypedResults.Content("Hello", "text/html");
|
||||
// }
|
||||
//
|
||||
// // [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
// // public IResult Error()
|
||||
// // {
|
||||
// // return TypedResults.Ok();
|
||||
// // }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// [TODO:description]
|
||||
// /// </summary>
|
||||
// /// <returns>[TODO:return]</returns>
|
||||
// [HttpGet("/hello")]
|
||||
// [HttpPost("/hello")]
|
||||
// public IActionResult Hello()
|
||||
// {
|
||||
// string randomString = Guid.NewGuid().ToString();
|
||||
// return this.Ok($"Hello World! GUID: {randomString}");
|
||||
// }
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// UDP API
|
||||
/// </summary>
|
||||
@@ -346,6 +384,32 @@ public class JtagController : ControllerBase
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <param name="address">[TODO:parameter]</param>
|
||||
/// <param name="port">[TODO:parameter]</param>
|
||||
/// <param name="portNum">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
[HttpPost("BoundaryScan")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(string), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
|
||||
public async ValueTask<IResult> BoundaryScan(string address, int port, int portNum)
|
||||
{
|
||||
var jtagCtrl = new JtagClient.Jtag(address, port);
|
||||
var ret = await jtagCtrl.BoundaryScan(portNum);
|
||||
if (!ret.IsSuccessful)
|
||||
{
|
||||
if (ret.Error is ArgumentException)
|
||||
return TypedResults.BadRequest(ret.Error);
|
||||
else return TypedResults.InternalServerError(ret.Error);
|
||||
}
|
||||
|
||||
return TypedResults.Ok(ret.Value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -368,6 +368,21 @@ public class JtagStatusReg
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
public class JtagBoundaryRegister
|
||||
{
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
public int PortNum { get; set; }
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
public UInt32[] PortStatus { get; set; } = new UInt32[] { };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Jtag控制器
|
||||
/// </summary>
|
||||
@@ -730,13 +745,13 @@ public class Jtag
|
||||
return true;
|
||||
}
|
||||
|
||||
async ValueTask<Result<UInt32>> LoadDRCareOutput(UInt32 bytesLen)
|
||||
async ValueTask<Result<UInt32>> LoadDRCareOutput(UInt32 UInt32Num)
|
||||
{
|
||||
if (bytesLen > Math.Pow(2, 28)) return new(new Exception("Length is over 2^(28 - 3)"));
|
||||
if (UInt32Num > Math.Pow(2, 23)) return new(new Exception("Length is over 2^(28 - 5)"));
|
||||
|
||||
var ret = await WriteFIFO(
|
||||
JtagAddr.WRITE_CMD,
|
||||
Common.Number.MultiBitsToNumber(JtagCmd.CMD_JTAG_LOAD_DR_CAREO, JtagCmd.LEN_CMD_JTAG, 8 * bytesLen, 28).Value,
|
||||
Common.Number.MultiBitsToNumber(JtagCmd.CMD_JTAG_LOAD_DR_CAREO, JtagCmd.LEN_CMD_JTAG, 32 * UInt32Num, 28).Value,
|
||||
0x01_00_00_00, JtagState.CMD_EXEC_FINISH);
|
||||
|
||||
if (ret.Value)
|
||||
@@ -745,6 +760,31 @@ public class Jtag
|
||||
return new(new Exception("LoadDRCareo Failed!"));
|
||||
}
|
||||
|
||||
async ValueTask<Result<UInt32[]>> LoadDRCareOutputArray(UInt32 UInt32Num)
|
||||
{
|
||||
if (UInt32Num > Math.Pow(2, 23)) return new(new Exception("Length is over 2^(28 - 5)"));
|
||||
|
||||
var ret = await WriteFIFO(
|
||||
JtagAddr.WRITE_CMD,
|
||||
Common.Number.MultiBitsToNumber(JtagCmd.CMD_JTAG_LOAD_DR_CAREO, JtagCmd.LEN_CMD_JTAG, 32 * UInt32Num, 28).Value,
|
||||
0x01_00_00_00, JtagState.CMD_EXEC_FINISH);
|
||||
|
||||
if (ret.Value)
|
||||
{
|
||||
var array = new UInt32[UInt32Num];
|
||||
for (int i = 0; i < UInt32Num; i++)
|
||||
{
|
||||
var retData = await ReadFIFO(JtagAddr.READ_DATA);
|
||||
if (!retData.IsSuccessful)
|
||||
return new(new Exception("Read FIFO failed when Load DR"));
|
||||
array[i] = retData.Value;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
else
|
||||
return new(new Exception("LoadDRCareo Failed!"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取 JTAG 设备的 ID 代码
|
||||
/// </summary>
|
||||
@@ -774,7 +814,7 @@ public class Jtag
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Clear Write Registers Failed"));
|
||||
|
||||
var retData = await LoadDRCareOutput(4);
|
||||
var retData = await LoadDRCareOutput(1);
|
||||
if (!retData.IsSuccessful)
|
||||
{
|
||||
return new(new Exception("Get ID Code Failed"));
|
||||
@@ -812,11 +852,9 @@ public class Jtag
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Clear Write Registers Failed"));
|
||||
|
||||
var retData = await LoadDRCareOutput(4);
|
||||
var retData = await LoadDRCareOutput(1);
|
||||
if (!retData.IsSuccessful)
|
||||
{
|
||||
return new(new Exception("Read Status Reg Failed"));
|
||||
}
|
||||
|
||||
return retData.Value;
|
||||
}
|
||||
@@ -901,4 +939,46 @@ public class Jtag
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <param name="portNum">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public async ValueTask<Result<JtagBoundaryRegister>> BoundaryScan(int portNum)
|
||||
{
|
||||
if (portNum <= 0)
|
||||
return new(new ArgumentException("The number of port couldn't be negative", nameof(portNum)));
|
||||
|
||||
// Clear Data
|
||||
await MsgBus.UDPServer.ClearUDPData(this.address);
|
||||
|
||||
logger.Trace($"Clear up udp server {this.address} receive data");
|
||||
|
||||
Result<bool> ret;
|
||||
|
||||
ret = await CloseTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
||||
|
||||
ret = await RunTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Run Test Failed"));
|
||||
|
||||
logger.Trace("Jtag initialize");
|
||||
|
||||
ret = await ExecRDCmd(JtagCmd.JTAG_DR_SAMPLE);
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Execute Command JTAG_DR_JRST Failed"));
|
||||
|
||||
var retData = await LoadDRCareOutputArray(((uint)(portNum % 32 == 0 ? portNum / 32 : portNum / 32 + 1)));
|
||||
if (!retData.IsSuccessful)
|
||||
return new(new Exception("Read Status Reg Failed"));
|
||||
|
||||
ret = await CloseTest();
|
||||
if (!ret.IsSuccessful) return new(ret.Error);
|
||||
else if (!ret.Value) return new(new Exception("Jtag Close Test Failed"));
|
||||
|
||||
return new JtagBoundaryRegister() { PortNum = portNum, PortStatus = retData.Value };
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user