DreamineVMS 1.0.0.0
Windows PC의 RTSP·USB 카메라 영상을 HLS로 변환해 원격 CCTV Viewer에 전달하는 데스크톱 에이전트입니다.
로딩중...
검색중...
일치하는것 없음
VmsDashboardStateService.cs
이 파일의 문서화 페이지로 가기
1using Dreamine.Hybrid.Interfaces;
6
8
25public sealed class VmsDashboardStateService : IVmsDashboardStateService, IDisposable
26{
53 private readonly IHybridStateStore<VmsDashboardState> _stateStore;
62 private readonly object _gate = new();
71 private bool _isStarted;
80 private bool _isDisposed;
81
123 IVmsCameraRepository repository,
124 ICameraRuntimeStateService runtimeState,
125 IHybridStateStore<VmsDashboardState> stateStore)
126 {
127 _repository = repository ?? throw new ArgumentNullException(nameof(repository));
128 _runtimeState = runtimeState ?? throw new ArgumentNullException(nameof(runtimeState));
129 _stateStore = stateStore ?? throw new ArgumentNullException(nameof(stateStore));
130 }
131
140 public void Start()
141 {
142 lock (_gate)
143 {
144 if (_isStarted || _isDisposed)
145 {
146 return;
147 }
148
149 _runtimeState.StateChanged += OnRuntimeStateChanged;
150 _isStarted = true;
151 }
152
153 // 시작 시 1회 초기 동기화.
154 Refresh("VMS application started.");
155 }
156
173 public void Refresh(string? lastEvent = null)
174 {
175 if (_isDisposed)
176 {
177 return;
178 }
179
180 IReadOnlyList<CameraDevice> cameras = _repository.GetAll();
181 IReadOnlyList<CameraRuntimeState> states = _runtimeState.GetAll();
182
183 int connectedCount = states.Count(state => state.State == CameraConnectionState.Connected);
184
185 VmsDashboardState previous = _stateStore.State;
186 string finalLastEvent = lastEvent ?? previous.LastEvent;
187
188 _stateStore.SetState(new VmsDashboardState
189 {
190 TotalCameraCount = cameras.Count,
191 ConnectedCameraCount = connectedCount,
192 RecordingCameraCount = 0,
193 LastEvent = finalLastEvent,
194 LastUpdated = DateTimeOffset.Now
195 });
196 }
197
206 public void Dispose()
207 {
208 lock (_gate)
209 {
210 if (_isDisposed)
211 {
212 return;
213 }
214
215 if (_isStarted)
216 {
217 _runtimeState.StateChanged -= OnRuntimeStateChanged;
218 _isStarted = false;
219 }
220
221 _isDisposed = true;
222 }
223 }
224
249 private void OnRuntimeStateChanged(object? sender, CameraRuntimeState e)
250 {
252 }
253}
readonly IHybridStateStore< VmsDashboardState > _stateStore
VmsDashboardStateService(IVmsCameraRepository repository, ICameraRuntimeStateService runtimeState, IHybridStateStore< VmsDashboardState > stateStore)
void OnRuntimeStateChanged(object? sender, CameraRuntimeState e)