DreamineVMS 1.0.0.0
Windows PC의 RTSP·USB 카메라 영상을 HLS로 변환해 원격 CCTV Viewer에 전달하는 데스크톱 에이전트입니다.
로딩중...
검색중...
일치하는것 없음
DreamineVMS.Services.Agent.AgentApiClient 클래스 참조sealed

더 자세히 ...

Public 멤버 함수

 AgentApiClient (IConfiguration config, ILogger< AgentApiClient > logger)
void SetCredentials (string serverUrl, string email, string password)
Task<(bool Ok, string Error)> LoginWithStoredCredentialsAsync ()
async Task<(bool Ok, string Error)> LoginAsync (string email, string password)
async Task< bool > SyncCamerasAsync (IEnumerable< AgentCameraInfo > cameras)
async Task< bool > PushSegmentAsync (string cameraId, string filename, byte[] data)
void ClearToken ()

속성

string? Token [get, private set]
string? TenantId [get, private set]
List< AgentCameraInfoCameras = [] [get, private set]
string? Email [get]
string? ServerUrl [get]

Private 멤버 함수

Uri GetActiveServerUrl ()
IEnumerable< Uri > EnumerateServerUrls ()

정적 Private 멤버 함수

static List< Uri > BuildServerCandidates (string? configuredUrl)

Private 속성

readonly HttpClient _http
readonly ILogger< AgentApiClient_logger
readonly List< Uri > _serverUrls
Uri? _activeServerUrl
string? _email
string? _password

상세한 설명

중앙 DreamineVMS.Web 서버와 통신하는 HTTP 클라이언트입니다.

AgentApiClient.cs 파일의 17 번째 라인에서 정의되었습니다.

생성자 & 소멸자 문서화

◆ AgentApiClient()

DreamineVMS.Services.Agent.AgentApiClient.AgentApiClient ( IConfiguration config,
ILogger< AgentApiClient > logger )
inline

지정한 설정으로 AgentApiClient 클래스의 새 인스턴스를 초기화합니다.

매개변수
configconfig에 사용할 IConfiguration 값입니다.
loggerlogger에 사용할 ILogger<AgentApiClient> 값입니다.

AgentApiClient.cs 파일의 127 번째 라인에서 정의되었습니다.

128 {
129 _logger = logger;
130 _serverUrls = BuildServerCandidates(config["Agent:ServerUrl"]);
131 _activeServerUrl = _serverUrls.FirstOrDefault();
132 _http = new HttpClient();
133 _email = config["Agent:Email"];
134 _password = config["Agent:Password"];
135 }

다음을 참조함 : _activeServerUrl, _email, _http, _logger, _password, _serverUrls, BuildServerCandidates().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 함수 문서화

◆ BuildServerCandidates()

List< Uri > DreamineVMS.Services.Agent.AgentApiClient.BuildServerCandidates ( string? configuredUrl)
inlinestaticprivate

Server Candidates 값을 구성합니다.

매개변수
configuredUrlconfigured Url에 사용할 string? 값입니다.
반환값
Build Server Candidates 작업에서 생성한 List<Uri> 결과입니다.

AgentApiClient.cs 파일의 512 번째 라인에서 정의되었습니다.

513 {
514 var candidates = new List<string>();
515 Add(configuredUrl);
516 Add("http://localhost:6080");
517 Add("https://localhost:6443");
518
519 return candidates
520 .Select(item => new Uri(item.EndsWith('/') ? item : item + "/"))
521 .Distinct()
522 .ToList();
523
524 #pragma warning disable CS1587
543 void Add(string? url)
544 {
545 if (string.IsNullOrWhiteSpace(url))
546 {
547 return;
548 }
549
550 candidates.Add(url.Trim());
551 }
552 #pragma warning restore CS1587
553 }

다음에 의해서 참조됨 : AgentApiClient(), SetCredentials().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ClearToken()

void DreamineVMS.Services.Agent.AgentApiClient.ClearToken ( )
inline

Clear Token 작업을 수행합니다.

AgentApiClient.cs 파일의 431 번째 라인에서 정의되었습니다.

431=> Token = null;

다음을 참조함 : Token.

◆ EnumerateServerUrls()

IEnumerable< Uri > DreamineVMS.Services.Agent.AgentApiClient.EnumerateServerUrls ( )
inlineprivate

Enumerate Server Urls 작업을 수행합니다.

반환값
Enumerate Server Urls 작업에서 생성한 IEnumerable<Uri> 결과입니다.

AgentApiClient.cs 파일의 470 번째 라인에서 정의되었습니다.

471 {
472 if (_activeServerUrl is not null)
473 {
474 yield return _activeServerUrl;
475 }
476
477 foreach (Uri serverUrl in _serverUrls)
478 {
479 if (_activeServerUrl is not null && serverUrl == _activeServerUrl)
480 {
481 continue;
482 }
483
484 yield return serverUrl;
485 }
486 }

다음을 참조함 : _activeServerUrl, _serverUrls.

다음에 의해서 참조됨 : LoginAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GetActiveServerUrl()

Uri DreamineVMS.Services.Agent.AgentApiClient.GetActiveServerUrl ( )
inlineprivate

Active Server Url 값을 가져옵니다.

반환값
Get Active Server Url 작업에서 생성한 Uri 결과입니다.

AgentApiClient.cs 파일의 449 번째 라인에서 정의되었습니다.

450 {
451 return _activeServerUrl ?? _serverUrls.First();
452 }

다음을 참조함 : _activeServerUrl, _serverUrls.

다음에 의해서 참조됨 : PushSegmentAsync(), SyncCamerasAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ LoginAsync()

async Task<(bool Ok, string Error)> DreamineVMS.Services.Agent.AgentApiClient.LoginAsync ( string email,
string password )
inline

Login Async 작업을 수행합니다.

매개변수
emailemail에 사용할 string 값입니다.
passwordpassword에 사용할 string 값입니다.
반환값
Login Async 작업에서 생성한 Task<(bool Ok, string Error)> 결과입니다.

AgentApiClient.cs 파일의 254 번째 라인에서 정의되었습니다.

255 {
256 foreach (Uri serverUrl in EnumerateServerUrls())
257 {
258 try
259 {
260 var resp = await _http.PostAsJsonAsync(
261 new Uri(serverUrl, "/api/agent/login"),
262 new { Email = email, Password = password });
263
264 if (!resp.IsSuccessStatusCode)
265 {
266 _logger.LogWarning("[Agent] 로그인 실패: {Server} responded {StatusCode}.",
267 serverUrl, (int)resp.StatusCode);
268 continue;
269 }
270
271 var data = await resp.Content.ReadFromJsonAsync<AgentLoginResponse>();
272 if (data is null)
273 {
274 _logger.LogWarning("[Agent] 로그인 실패: {Server} returned an empty response.", serverUrl);
275 continue;
276 }
277
278 _activeServerUrl = serverUrl;
279 Token = data.Token;
280 TenantId = data.TenantId;
281 Cameras = data.Cameras ?? [];
282 _logger.LogInformation("[Agent] 중앙 서버 연결: {Server}", serverUrl);
283 return (true, "");
284 }
285 catch (Exception ex)
286 {
287 _logger.LogWarning(ex, "[Agent] 중앙 서버 연결 실패: {Server}", serverUrl);
288 }
289 }
290
291 Token = null;
292 return (false, "중앙 서버 연결 실패");
293 }

다음을 참조함 : _activeServerUrl, _http, _logger, Cameras, Email, EnumerateServerUrls(), TenantId, Token.

다음에 의해서 참조됨 : LoginWithStoredCredentialsAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ LoginWithStoredCredentialsAsync()

Task<(bool Ok, string Error)> DreamineVMS.Services.Agent.AgentApiClient.LoginWithStoredCredentialsAsync ( )
inline

저장된 자격증명으로 로그인합니다.

반환값
Login With Stored Credentials Async 작업에서 생성한 Task<(bool Ok, string Error)> 결과입니다.

AgentApiClient.cs 파일의 215 번째 라인에서 정의되었습니다.

216 {
217 if (string.IsNullOrWhiteSpace(_email) || string.IsNullOrWhiteSpace(_password))
218 return Task.FromResult((false, "이메일 또는 비밀번호가 설정되지 않았습니다."));
219 return LoginAsync(_email, _password);
220 }

다음을 참조함 : _email, _password, LoginAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ PushSegmentAsync()

async Task< bool > DreamineVMS.Services.Agent.AgentApiClient.PushSegmentAsync ( string cameraId,
string filename,
byte[] data )
inline

세그먼트 업로드. 401 반환 시 Token을 null로 설정해 재로그인을 유도합니다.

매개변수
cameraIdcamera Id에 사용할 string 값입니다.
filenamefilename에 사용할 string 값입니다.
datadata에 사용할 byte[] 값입니다.
반환값
Push Segment Async 작업에서 생성한 Task<bool> 결과입니다.

AgentApiClient.cs 파일의 389 번째 라인에서 정의되었습니다.

390 {
391 if (Token is null) return false;
392 try
393 {
394 Uri serverUrl = GetActiveServerUrl();
395 using var content = new ByteArrayContent(data);
396 var resp = await _http.PostAsync(
397 new Uri(serverUrl, $"/api/agent/hls/{Token}/{cameraId}/{filename}"),
398 content);
399
400 if (resp.StatusCode == System.Net.HttpStatusCode.Unauthorized)
401 {
402 Token = null; // 재로그인 트리거
403 _logger.LogWarning("[Agent] 세그먼트 업로드 인증 만료: {CameraId}/{Filename}", cameraId, filename);
404 return false;
405 }
406
407 if (!resp.IsSuccessStatusCode)
408 {
409 _logger.LogWarning("[Agent] 세그먼트 업로드 실패: {CameraId}/{Filename} responded {StatusCode}.",
410 cameraId, filename, (int)resp.StatusCode);
411 }
412
413 return resp.IsSuccessStatusCode;
414 }
415 catch (Exception ex)
416 {
417 Token = null; // 서버 포트가 바뀌었거나 재시작된 경우 다음 루프에서 재로그인합니다.
418 _logger.LogWarning(ex, "[Agent] 세그먼트 업로드 중 오류: {CameraId}/{Filename}", cameraId, filename);
419 return false;
420 }
421 }

다음을 참조함 : _http, _logger, GetActiveServerUrl(), Token.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ SetCredentials()

void DreamineVMS.Services.Agent.AgentApiClient.SetCredentials ( string serverUrl,
string email,
string password )
inline

런타임에 자격증명과 서버 URL을 갱신합니다. 저장 후 재연결 시 호출하세요.

매개변수
serverUrlserver Url에 사용할 string 값입니다.
emailemail에 사용할 string 값입니다.
passwordpassword에 사용할 string 값입니다.

AgentApiClient.cs 파일의 169 번째 라인에서 정의되었습니다.

170 {
171 _email = email;
172 _password = password;
173 var newUrls = BuildServerCandidates(serverUrl);
174 _serverUrls.Clear();
175 _serverUrls.AddRange(newUrls);
176 _activeServerUrl = _serverUrls.FirstOrDefault();
177 Token = null; // 재로그인 유도
178 }

다음을 참조함 : _activeServerUrl, _email, _password, _serverUrls, BuildServerCandidates(), Token.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ SyncCamerasAsync()

async Task< bool > DreamineVMS.Services.Agent.AgentApiClient.SyncCamerasAsync ( IEnumerable< AgentCameraInfo > cameras)
inline

Sync Cameras Async 작업을 수행합니다.

매개변수
camerascameras에 사용할 IEnumerable<AgentCameraInfo> 값입니다.
반환값
Sync Cameras Async 작업에서 생성한 Task<bool> 결과입니다.

AgentApiClient.cs 파일의 319 번째 라인에서 정의되었습니다.

320 {
321 if (Token is null) return false;
322 try
323 {
324 Uri serverUrl = GetActiveServerUrl();
325 var payload = new
326 {
327 Token,
328 Cameras = cameras.Select(c => new
329 {
330 c.Id, c.Name, c.Host, c.RtspUrl, c.AutoReconnect, c.IsPublic
331 })
332 };
333 var resp = await _http.PostAsJsonAsync(new Uri(serverUrl, "/api/agent/sync-cameras"), payload);
334 if (!resp.IsSuccessStatusCode)
335 {
336 _logger.LogWarning("[Agent] 카메라 동기화 실패: {Server} responded {StatusCode}.",
337 serverUrl, (int)resp.StatusCode);
338 }
339
340 return resp.IsSuccessStatusCode;
341 }
342 catch (Exception ex)
343 {
344 _logger.LogWarning(ex, "[Agent] 카메라 동기화 중 오류");
345 return false;
346 }
347 }

다음을 참조함 : _http, _logger, Cameras, GetActiveServerUrl(), Token.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ _activeServerUrl

Uri? DreamineVMS.Services.Agent.AgentApiClient._activeServerUrl
private

active Server Url 값을 보관합니다.

AgentApiClient.cs 파일의 54 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : AgentApiClient(), EnumerateServerUrls(), GetActiveServerUrl(), LoginAsync(), SetCredentials().

◆ _email

string? DreamineVMS.Services.Agent.AgentApiClient._email
private

email 값을 보관합니다.

AgentApiClient.cs 파일의 92 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : AgentApiClient(), LoginWithStoredCredentialsAsync(), SetCredentials().

◆ _http

readonly HttpClient DreamineVMS.Services.Agent.AgentApiClient._http
private

http 값을 보관합니다.

AgentApiClient.cs 파일의 27 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : AgentApiClient(), LoginAsync(), PushSegmentAsync(), SyncCamerasAsync().

◆ _logger

readonly ILogger<AgentApiClient> DreamineVMS.Services.Agent.AgentApiClient._logger
private

logger 값을 보관합니다.

AgentApiClient.cs 파일의 36 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : AgentApiClient(), LoginAsync(), PushSegmentAsync(), SyncCamerasAsync().

◆ _password

string? DreamineVMS.Services.Agent.AgentApiClient._password
private

password 값을 보관합니다.

AgentApiClient.cs 파일의 101 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : AgentApiClient(), LoginWithStoredCredentialsAsync(), SetCredentials().

◆ _serverUrls

readonly List<Uri> DreamineVMS.Services.Agent.AgentApiClient._serverUrls
private

server Urls 값을 보관합니다.

AgentApiClient.cs 파일의 45 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : AgentApiClient(), EnumerateServerUrls(), GetActiveServerUrl(), SetCredentials().

속성 문서화

◆ Cameras

List<AgentCameraInfo> DreamineVMS.Services.Agent.AgentApiClient.Cameras = []
getprivate set

Cameras 값을 가져오거나 설정합니다.

AgentApiClient.cs 파일의 82 번째 라인에서 정의되었습니다.

82{ get; private set; } = [];

다음에 의해서 참조됨 : LoginAsync(), SyncCamerasAsync().

◆ Email

string? DreamineVMS.Services.Agent.AgentApiClient.Email
get

Email 값을 가져옵니다.

AgentApiClient.cs 파일의 188 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : LoginAsync().

◆ ServerUrl

string? DreamineVMS.Services.Agent.AgentApiClient.ServerUrl
get

Server Url 값을 가져옵니다.

AgentApiClient.cs 파일의 197 번째 라인에서 정의되었습니다.

◆ TenantId

string? DreamineVMS.Services.Agent.AgentApiClient.TenantId
getprivate set

Tenant Id 값을 가져오거나 설정합니다.

AgentApiClient.cs 파일의 73 번째 라인에서 정의되었습니다.

73{ get; private set; }

다음에 의해서 참조됨 : LoginAsync().

◆ Token

string? DreamineVMS.Services.Agent.AgentApiClient.Token
getprivate set

Token 값을 가져오거나 설정합니다.

AgentApiClient.cs 파일의 64 번째 라인에서 정의되었습니다.

64{ get; private set; }

다음에 의해서 참조됨 : ClearToken(), LoginAsync(), PushSegmentAsync(), SetCredentials(), SyncCamerasAsync().


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: