refactor: 重构数据库相关操作
This commit is contained in:
@@ -15,15 +15,23 @@ public class HdmiVideoStreamEndpoint
|
||||
public class HttpHdmiVideoStreamService : BackgroundService
|
||||
{
|
||||
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
private readonly Database.UserManager _userManager;
|
||||
|
||||
private HttpListener? _httpListener;
|
||||
private readonly int _serverPort = 4322;
|
||||
private readonly ConcurrentDictionary<string, HdmiIn> _hdmiInDict = new();
|
||||
private readonly ConcurrentDictionary<string, CancellationTokenSource> _hdmiInCtsDict = new();
|
||||
|
||||
public HttpHdmiVideoStreamService(Database.UserManager userManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
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($"HDMI Video Stream Service started on port {_serverPort}");
|
||||
|
||||
@@ -133,14 +141,7 @@ public class HttpHdmiVideoStreamService : BackgroundService
|
||||
return hdmiIn;
|
||||
}
|
||||
|
||||
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}");
|
||||
@@ -366,8 +367,7 @@ public class HttpHdmiVideoStreamService : BackgroundService
|
||||
/// <returns>返回所有可用的HDMI视频流终端点列表</returns>
|
||||
public List<HdmiVideoStreamEndpoint>? GetAllVideoEndpoints()
|
||||
{
|
||||
var db = new Database.AppDataConnection();
|
||||
var boards = db?.GetAllBoard();
|
||||
var boards = _userManager.GetAllBoard();
|
||||
if (boards == null)
|
||||
return null;
|
||||
|
||||
@@ -377,9 +377,9 @@ public class HttpHdmiVideoStreamService : BackgroundService
|
||||
endpoints.Add(new HdmiVideoStreamEndpoint
|
||||
{
|
||||
BoardId = board.ID.ToString(),
|
||||
MjpegUrl = $"http://{Global.localhost}:{_serverPort}/mjpeg?boardId={board.ID}",
|
||||
VideoUrl = $"http://{Global.localhost}:{_serverPort}/video?boardId={board.ID}",
|
||||
SnapshotUrl = $"http://{Global.localhost}:{_serverPort}/snapshot?boardId={board.ID}"
|
||||
MjpegUrl = $"http://{Global.LocalHost}:{_serverPort}/mjpeg?boardId={board.ID}",
|
||||
VideoUrl = $"http://{Global.LocalHost}:{_serverPort}/video?boardId={board.ID}",
|
||||
SnapshotUrl = $"http://{Global.LocalHost}:{_serverPort}/snapshot?boardId={board.ID}"
|
||||
});
|
||||
}
|
||||
return endpoints;
|
||||
@@ -395,9 +395,9 @@ public class HttpHdmiVideoStreamService : BackgroundService
|
||||
return new HdmiVideoStreamEndpoint
|
||||
{
|
||||
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}"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user