feat: 新增重置控制端的功能;前端可以显示提交记录 fix: 修复资源数据库sha256计算问题;修复资源数据库无法上传的问题
This commit is contained in:
@@ -17,4 +17,13 @@ public class String
|
||||
return new string(charArray);
|
||||
}
|
||||
|
||||
public static string BytesToString(byte[] bytes, string separator = "")
|
||||
{
|
||||
return BitConverter.ToString(bytes).Replace("-", separator.ToString());
|
||||
}
|
||||
|
||||
public static string BytesToBase64(byte[] bytes)
|
||||
{
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,6 @@ public class ResourceController : ControllerBase
|
||||
if (string.IsNullOrWhiteSpace(request.ResourceType) || file == null)
|
||||
return BadRequest("资源类型、资源用途和文件不能为空");
|
||||
|
||||
// 验证资源用途
|
||||
if (request.ResourcePurpose != ResourcePurpose.Template && request.ResourcePurpose != ResourcePurpose.User)
|
||||
return BadRequest($"无效的资源用途: {request.ResourcePurpose}");
|
||||
|
||||
// 模板资源需要管理员权限
|
||||
if (request.ResourcePurpose == ResourcePurpose.Template && !User.IsInRole("Admin"))
|
||||
return Forbid("只有管理员可以添加模板资源");
|
||||
|
||||
@@ -135,7 +135,8 @@ public class ResourceManager
|
||||
|
||||
// 验证资源用途
|
||||
if (resourcePurpose != ResourcePurpose.Template &&
|
||||
resourcePurpose != ResourcePurpose.User)
|
||||
resourcePurpose != ResourcePurpose.User &&
|
||||
resourcePurpose != ResourcePurpose.Homework)
|
||||
{
|
||||
logger.Error($"无效的资源用途: {resourcePurpose}");
|
||||
return new(new Exception($"无效的资源用途: {resourcePurpose}"));
|
||||
@@ -149,7 +150,8 @@ public class ResourceManager
|
||||
}
|
||||
|
||||
// 计算数据的SHA256
|
||||
var sha256 = SHA256.HashData(data).ToString();
|
||||
var sha256Bytes = SHA256.HashData(data);
|
||||
var sha256 = Common.String.BytesToBase64(sha256Bytes);
|
||||
if (string.IsNullOrEmpty(sha256))
|
||||
{
|
||||
logger.Error($"SHA256计算失败");
|
||||
|
||||
@@ -429,7 +429,7 @@ public class Jtag
|
||||
if (!MsgBus.IsRunning)
|
||||
return new(new Exception("Message Bus not Working!"));
|
||||
|
||||
var retPack = await MsgBus.UDPServer.WaitForDataAsync(address, 0, port);
|
||||
var retPack = await MsgBus.UDPServer.WaitForDataAsync(this.ep, 0, this.timeout);
|
||||
if (!retPack.IsSuccessful || !retPack.Value.IsSuccessful)
|
||||
return new(new Exception("Send address package failed"));
|
||||
|
||||
|
||||
@@ -183,6 +183,21 @@ public sealed class UDPClientPool
|
||||
return await Task.Run(() => { return SendDataPack(endPoint, pkg); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送重置信号
|
||||
/// </summary>
|
||||
/// <param name="endPoint">IP端点(IP地址与端口)</param>
|
||||
/// <returns>是否成功</returns>
|
||||
public async static ValueTask<bool> SendResetSignal(IPEndPoint endPoint)
|
||||
{
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
return SendAddrPack(
|
||||
endPoint,
|
||||
new WebProtocol.SendAddrPackage(BurstType.FixedBurst, 0, true, 0, 0xF0F0F0F0));
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取设备地址数据
|
||||
/// </summary>
|
||||
@@ -219,8 +234,7 @@ public sealed class UDPClientPool
|
||||
if (!MsgBus.IsRunning)
|
||||
return new(new Exception("Message Bus not Working!"));
|
||||
|
||||
var retPack = await MsgBus.UDPServer.WaitForDataAsync(
|
||||
endPoint.Address.ToString(), taskID, endPoint.Port, timeout);
|
||||
var retPack = await MsgBus.UDPServer.WaitForDataAsync(endPoint, taskID, timeout);
|
||||
if (!retPack.IsSuccessful) return new(retPack.Error);
|
||||
else if (!retPack.Value.IsSuccessful)
|
||||
return new(new Exception("Send address package failed"));
|
||||
@@ -389,8 +403,7 @@ public sealed class UDPClientPool
|
||||
if (!ret) return new(new Exception($"Send address package failed at segment {i}!"));
|
||||
|
||||
// Wait for data response
|
||||
var retPack = await MsgBus.UDPServer.WaitForDataAsync(
|
||||
endPoint.Address.ToString(), taskID, endPoint.Port, timeout);
|
||||
var retPack = await MsgBus.UDPServer.WaitForDataAsync(endPoint, taskID, timeout);
|
||||
if (!retPack.IsSuccessful) return new(retPack.Error);
|
||||
|
||||
if (!retPack.Value.IsSuccessful)
|
||||
@@ -606,8 +619,7 @@ public sealed class UDPClientPool
|
||||
return new(new Exception("Message bus not working!"));
|
||||
|
||||
// Wait for Write Ack
|
||||
var udpWriteAck = await MsgBus.UDPServer.WaitForAckAsync(
|
||||
endPoint.Address.ToString(), taskID, endPoint.Port, timeout);
|
||||
var udpWriteAck = await MsgBus.UDPServer.WaitForAckAsync(endPoint, taskID, timeout);
|
||||
if (!udpWriteAck.IsSuccessful) return new(udpWriteAck.Error);
|
||||
_progressTracker.AdvanceProgress(progressId, 10);
|
||||
|
||||
@@ -671,7 +683,7 @@ public sealed class UDPClientPool
|
||||
if (!ret) return new(new Exception("Send data package failed!"));
|
||||
|
||||
// Wait for Write Ack
|
||||
var udpWriteAck = await MsgBus.UDPServer.WaitForAckAsync(endPoint.Address.ToString(), taskID, endPoint.Port, timeout);
|
||||
var udpWriteAck = await MsgBus.UDPServer.WaitForAckAsync(endPoint, taskID, timeout);
|
||||
if (!udpWriteAck.IsSuccessful) return new(udpWriteAck.Error);
|
||||
|
||||
if (!udpWriteAck.Value.IsSuccessful)
|
||||
|
||||
@@ -194,14 +194,15 @@ public class UDPServer
|
||||
|
||||
var startTime = DateTime.Now;
|
||||
var isTimeout = false;
|
||||
while (!isTimeout)
|
||||
{
|
||||
var elapsed = DateTime.Now - startTime;
|
||||
isTimeout = elapsed >= TimeSpan.FromMilliseconds(timeout);
|
||||
if (isTimeout) break;
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
while (!isTimeout)
|
||||
{
|
||||
var elapsed = DateTime.Now - startTime;
|
||||
isTimeout = elapsed >= TimeSpan.FromMilliseconds(timeout);
|
||||
if (isTimeout) break;
|
||||
|
||||
using (await udpDataLock.AcquireWriteLockAsync(TimeSpan.FromMilliseconds(timeout)))
|
||||
{
|
||||
if (udpData.TryGetValue(key, out var sortedList) && sortedList.Count > 0)
|
||||
@@ -214,23 +215,16 @@ public class UDPServer
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
logger.Trace("Get nothing even after time out");
|
||||
return new(null);
|
||||
}
|
||||
|
||||
if (data is null)
|
||||
throw new TimeoutException("Get nothing even after time out");
|
||||
else return new(data.DeepClone());
|
||||
}
|
||||
|
||||
|
||||
if (data is null)
|
||||
catch
|
||||
{
|
||||
logger.Trace("Get nothing even after time out");
|
||||
return new(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new(data.DeepClone());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -367,17 +361,22 @@ public class UDPServer
|
||||
/// <summary>
|
||||
/// 异步等待写响应
|
||||
/// </summary>
|
||||
/// <param name="address">IP地址</param>
|
||||
/// <param name="endPoint">IP地址及端口</param>
|
||||
/// <param name="taskID">[TODO:parameter]</param>
|
||||
/// <param name="port">UDP 端口</param>
|
||||
/// <param name="timeout">超时时间范围</param>
|
||||
/// <returns>接收响应包</returns>
|
||||
public async ValueTask<Result<WebProtocol.RecvRespPackage>> WaitForAckAsync
|
||||
(string address, int taskID, int port = -1, int timeout = 1000)
|
||||
(IPEndPoint endPoint, int taskID, int timeout = 1000)
|
||||
{
|
||||
var address = endPoint.Address.ToString();
|
||||
var port = endPoint.Port;
|
||||
|
||||
var data = await FindDataAsync(address, taskID, timeout);
|
||||
if (!data.HasValue)
|
||||
{
|
||||
await UDPClientPool.SendResetSignal(endPoint);
|
||||
return new(new Exception("Get None even after time out!"));
|
||||
}
|
||||
|
||||
var recvData = data.Value;
|
||||
if (recvData.Address != address || (port > 0 && recvData.Port != port))
|
||||
@@ -393,17 +392,22 @@ public class UDPServer
|
||||
/// <summary>
|
||||
/// 异步等待数据
|
||||
/// </summary>
|
||||
/// <param name="address">IP地址</param>
|
||||
/// <param name="taskID">[TODO:parameter]</param>
|
||||
/// <param name="port">UDP 端口</param>
|
||||
/// <param name="endPoint">IP地址</param>
|
||||
/// <param name="taskID">任务ID</param>
|
||||
/// <param name="timeout">超时时间范围</param>
|
||||
/// <returns>接收数据包</returns>
|
||||
public async ValueTask<Result<RecvDataPackage>> WaitForDataAsync
|
||||
(string address, int taskID, int port = -1, int timeout = 1000)
|
||||
(IPEndPoint endPoint, int taskID, int timeout = 1000)
|
||||
{
|
||||
var address = endPoint.Address.ToString();
|
||||
var port = endPoint.Port;
|
||||
|
||||
var data = await FindDataAsync(address, taskID, timeout);
|
||||
if (!data.HasValue)
|
||||
{
|
||||
await UDPClientPool.SendResetSignal(endPoint);
|
||||
return new(new Exception("Get None even after time out!"));
|
||||
}
|
||||
|
||||
var recvData = data.Value;
|
||||
if (recvData.Address != address || (port >= 0 && recvData.Port != port))
|
||||
@@ -523,7 +527,7 @@ public class UDPServer
|
||||
return $@"
|
||||
Receive Data from {data.Address}:{data.Port} at {data.DateTime.ToString()}:
|
||||
Original Data : {BitConverter.ToString(bytes).Replace("-", " ")}
|
||||
Decoded Data : {recvData}
|
||||
Decoded Data : {recvData}
|
||||
";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user