fix: 修复进度条的问题

This commit is contained in:
2025-08-17 13:33:11 +08:00
parent 97b86acfa8
commit 55edfd771e
13 changed files with 512 additions and 584 deletions

View File

@@ -16,17 +16,12 @@ public class JtagController : ControllerBase
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private readonly ProgressTrackerService _tracker;
private readonly ProgressTracker _tracker = MsgBus.ProgressTracker;
private readonly UserManager _userManager = new();
private readonly ResourceManager _resourceManager = new();
private const string BITSTREAM_PATH = "bitstream/Jtag";
public JtagController(ProgressTrackerService tracker)
{
_tracker = tracker;
}
/// <summary>
/// 控制器首页信息
/// </summary>
@@ -188,8 +183,8 @@ public class JtagController : ControllerBase
logger.Info($"User {username} processing bitstream file of size: {fileBytes.Length} bytes");
// 定义进度跟踪
var (taskId, progress) = _tracker.CreateTask(cancelToken);
progress.Report(10);
var taskId = _tracker.CreateTask(1000);
_tracker.AdvanceProgress(taskId, 10);
_ = Task.Run(async () =>
{
@@ -210,7 +205,8 @@ public class JtagController : ControllerBase
if (!retBuffer.IsSuccessful)
{
logger.Error($"User {username} failed to reverse bytes: {retBuffer.Error}");
progress.Error($"User {username} failed to reverse bytes: {retBuffer.Error}");
_tracker.FailProgress(taskId,
$"User {username} failed to reverse bytes: {retBuffer.Error}");
return;
}
revBuffer = retBuffer.Value;
@@ -228,7 +224,7 @@ public class JtagController : ControllerBase
var processedBytes = outputStream.ToArray();
logger.Info($"User {username} processed {totalBytesProcessed} bytes for device {address}");
progress.Report(20);
_tracker.AdvanceProgress(taskId, 20);
// 下载比特流
var jtagCtrl = new Peripherals.JtagClient.Jtag(address, port);
@@ -237,12 +233,13 @@ public class JtagController : ControllerBase
if (ret.IsSuccessful)
{
logger.Info($"User {username} successfully downloaded bitstream '{resource.ResourceName}' to device {address}");
progress.Finish();
_tracker.CompleteProgress(taskId);
}
else
{
logger.Error($"User {username} failed to download bitstream to device {address}: {ret.Error}");
progress.Error($"User {username} failed to download bitstream to device {address}: {ret.Error}");
_tracker.FailProgress(taskId,
$"User {username} failed to download bitstream to device {address}: {ret.Error}");
}
}
});