refactor: 重构数据库相关操作

This commit is contained in:
2025-08-10 20:13:44 +08:00
parent 079004c17d
commit b95a61c532
20 changed files with 2252 additions and 2065 deletions

View File

@@ -87,6 +87,8 @@ public class HttpVideoStreamService : BackgroundService
{
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private readonly Database.UserManager _userManager;
private HttpListener? _httpListener;
private readonly int _serverPort = 4321;
@@ -99,13 +101,18 @@ public class HttpVideoStreamService : BackgroundService
private readonly object _usbCameraLock = new object();
#endif
public HttpVideoStreamService(Database.UserManager userManager)
{
_userManager = userManager;
}
/// <summary>
/// 初始化 HttpVideoStreamService
/// </summary>
public override async Task StartAsync(CancellationToken cancellationToken)
{
_httpListener = new HttpListener();
_httpListener.Prefixes.Add($"http://{Global.localhost}:{_serverPort}/");
_httpListener.Prefixes.Add($"http://{Global.LocalHost}:{_serverPort}/");
_httpListener.Start();
logger.Info($"Video Stream Service started on port {_serverPort}");
@@ -147,14 +154,7 @@ public class HttpVideoStreamService : BackgroundService
return client;
}
var db = new Database.AppDataConnection();
if (db == null)
{
logger.Error("Failed to create HdmiIn instance");
return null;
}
var boardRet = db.GetBoardByID(Guid.Parse(boardId));
var boardRet = _userManager.GetBoardByID(Guid.Parse(boardId));
if (!boardRet.IsSuccessful || !boardRet.Value.HasValue)
{
logger.Error($"Failed to get board with ID {boardId}");
@@ -675,9 +675,9 @@ public class HttpVideoStreamService : BackgroundService
return new VideoEndpoint
{
BoardId = boardId,
MjpegUrl = $"http://{Global.localhost}:{_serverPort}/mjpeg?boardId={boardId}",
VideoUrl = $"http://{Global.localhost}:{_serverPort}/video?boardId={boardId}",
SnapshotUrl = $"http://{Global.localhost}:{_serverPort}/snapshot?boardId={boardId}",
MjpegUrl = $"http://{Global.LocalHost}:{_serverPort}/mjpeg?boardId={boardId}",
VideoUrl = $"http://{Global.LocalHost}:{_serverPort}/video?boardId={boardId}",
SnapshotUrl = $"http://{Global.LocalHost}:{_serverPort}/snapshot?boardId={boardId}",
Resolution = $"{client.FrameWidth}x{client.FrameHeight}",
FrameRate = client.FrameRate
};