StatusBarViewModel.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using AlarmInfoServerSim.Services;
  2. using CommunityToolkit.Mvvm.ComponentModel;
  3. namespace AlarmInfoServerSim.ViewModels
  4. {
  5. public partial class StatusBarViewModel : ObservableObject
  6. {
  7. private readonly ISharedConfig _sharedConfig;
  8. private readonly ISendInfoService _sendInfoService;
  9. [ObservableProperty]
  10. private string _status;
  11. [ObservableProperty]
  12. private string _ipAddress;
  13. [ObservableProperty]
  14. private ushort _port;
  15. public StatusBarViewModel(ISharedConfig sharedConfig, ISendInfoService sendInfoService)
  16. {
  17. _sharedConfig = sharedConfig;
  18. _status = "Unknown";
  19. _ipAddress = _sharedConfig.BasicInfo?.RTServerAddress ?? "Unknown";
  20. _port = _sharedConfig.BasicInfo?.RTServerPort ?? 0;
  21. _sendInfoService = sendInfoService;
  22. _sendInfoService.ConnectionChanged += OnConnectionChanged;
  23. }
  24. private void OnConnectionChanged(object? sender, bool e)
  25. {
  26. Status = e ? "Connected" : "Disconnected";
  27. }
  28. }
  29. }