1using Dreamine.Hybrid.Interfaces;
8using System.Collections.ObjectModel;
9using System.ComponentModel;
10using System.Runtime.CompilerServices;
11using System.Windows.Input;
184 IHybridMessageBus messageBus,
187 _repository = repository ??
throw new ArgumentNullException(nameof(repository));
188 _runtimeState = runtimeState ??
throw new ArgumentNullException(nameof(runtimeState));
189 _streamService = streamService ??
throw new ArgumentNullException(nameof(streamService));
190 _dashboardStateService = dashboardStateService ??
throw new ArgumentNullException(nameof(dashboardStateService));
191 ArgumentNullException.ThrowIfNull(messageBus);
192 _agentSettings = agentSettings ??
throw new ArgumentNullException(nameof(agentSettings));
201 Logs.Add(
new VmsLogItem { Message =
"VMS application started." });
241 public ObservableCollection<CameraRowViewModel>
Cameras {
get; } =
new();
251 public ObservableCollection<VmsLogItem>
Logs {
get; } =
new();
390 if (selected is
null)
396 AddLog($
"Connect requested: {selected.Name}");
418 if (selected is
null)
424 AddLog($
"Disconnect requested: {selected.Name}");
453 if (
string.IsNullOrWhiteSpace(cameraId))
455 AddLog(
"Connect request ignored: camera id is empty.");
462 AddLog($
"Connect request ignored: camera not found. id={cameraId}");
467 AddLog($
"Dashboard connect requested: {camera.Name}");
496 if (
string.IsNullOrWhiteSpace(cameraId))
498 AddLog(
"Disconnect request ignored: camera id is empty.");
505 AddLog($
"Disconnect request ignored: camera not found. id={cameraId}");
510 AddLog($
"Dashboard disconnect requested: {camera.Name}");
532 AddLog(
"Start all cameras requested.");
554 AddLog(
"Stop all cameras requested.");
595 AddLog(
"Embedded dashboard refresh requested.");
601 AddLog(
"Server dashboard requested Open Live. Use /live route in the server WebView.");
625 AddLog($
"Dashboard action requested: {message.Action}");
702 while (
Logs.Count > 300)
753 System.Windows.Application? app = System.Windows.Application.Current;
759 var dispatcher = app.Dispatcher;
762 if (dispatcher.HasShutdownStarted || dispatcher.HasShutdownFinished)
767 if (dispatcher.CheckAccess())
775 dispatcher.Invoke(action);
777 catch (OperationCanceledException) { }
799 PropertyChanged?.Invoke(
this,
new PropertyChangedEventArgs(propertyName));
866 _execute = execute ??
throw new ArgumentNullException(nameof(execute));
934 System.Windows.Threading.Dispatcher? dispatcher =
935 System.Windows.Application.Current?.Dispatcher;
937 if (dispatcher is
null || dispatcher.CheckAccess())
1019 _execute = execute ??
throw new ArgumentNullException(nameof(execute));
1090 catch (Exception ex)
1093 System.Diagnostics.Debug.WriteLine($
"[AsyncRelayCommand] {ex}");
1112 System.Windows.Threading.Dispatcher? dispatcher =
1113 System.Windows.Application.Current?.Dispatcher;
1115 if (dispatcher is
null || dispatcher.CheckAccess())
const string CameraDisconnect
const string CameraStopAll
const string CameraConnect
const string EmbeddedRefresh
const string ServerOpenLive
const string CameraStartAll
void OnPropertyChanged([CallerMemberName] string? propertyName=null)
void AddLog(string message)
async Task StartAllAsync()
readonly IVmsDashboardStateService _dashboardStateService
async Task DisconnectSelectedCameraAsync()
readonly ICameraRuntimeStateService _runtimeState
ObservableCollection< CameraRowViewModel > Cameras
AgentSettingsViewModel AgentSettings
readonly ICameraStreamService _streamService
EventHandler? OpenLiveTabRequested
readonly IDisposable _dashboardSubscription
MainWindowViewModel(IVmsCameraRepository repository, ICameraRuntimeStateService runtimeState, ICameraStreamService streamService, IVmsDashboardStateService dashboardStateService, IHybridMessageBus messageBus, AgentSettingsViewModel agentSettings)
readonly IVmsCameraRepository _repository
readonly AgentSettingsViewModel _agentSettings
ICommand ClearLogsCommand
void OnCameraRuntimeStateChanged(object? sender, CameraRuntimeState state)
void AddLogCore(string message)
CameraRowViewModel? _selectedCamera
CameraRowViewModel? SelectedCamera
async Task OnDashboardActionRequestedAsync(VmsDashboardActionRequestedMessage message, CancellationToken cancellationToken)
async Task ConnectCameraAsync(string? cameraId)
async Task StopAllAsync()
PropertyChangedEventHandler? PropertyChanged
ICommand DisconnectSelectedCameraCommand
async Task DisconnectCameraAsync(string? cameraId)
ICommand ConnectSelectedCameraCommand
void RaiseOpenLiveTabRequested()
static void DispatchToUi(Action action)
ObservableCollection< VmsLogItem > Logs
async Task ConnectSelectedCameraAsync()
readonly? Func< bool > _canExecute
void Execute(object? parameter)
bool CanExecute(object? parameter)
RelayCommand(Action execute, Func< bool >? canExecute=null)
EventHandler? CanExecuteChanged
void RaiseCanExecuteChanged()
EventHandler? CanExecuteChanged
bool CanExecute(object? parameter)
AsyncRelayCommand(Func< Task > execute, Func< bool >? canExecute=null)
async void Execute(object? parameter)
void RaiseCanExecuteChanged()
readonly Func< Task > _execute
readonly? Func< bool > _canExecute