| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using AlarmInfoServerSim.Services;
- using CommunityToolkit.Mvvm.ComponentModel;
- namespace AlarmInfoServerSim.ViewModels
- {
- public partial class StatusBarViewModel : ObservableObject
- {
- private readonly ISharedConfig _sharedConfig;
- private readonly IInfoSendingService _sendInfoService;
- [ObservableProperty]
- private string _status;
- [ObservableProperty]
- private string _remoteIp;
- [ObservableProperty]
- private string _remotePort;
- public StatusBarViewModel(ISharedConfig sharedConfig, IInfoSendingService sendInfoService)
- {
- _sharedConfig = sharedConfig;
- _status = "Disconnected";
- _remoteIp = "Unknown";
- _remotePort = "Unknown";
- _sendInfoService = sendInfoService;
- _sendInfoService.ConnectionStatusChanged += OnConnectionStatusChanged;
- _sendInfoService.TcpConnectionChanged += OnTcpConnectionChanged;
- }
- private void OnTcpConnectionChanged(object? sender, UniversalNetFrame451.IO.TcpConnection e)
- {
- if (Status == "Connected")
- {
- RemoteIp = e.RemoteEndPoint.Address.ToString();
- RemotePort = e.RemoteEndPoint.Port.ToString();
- }
- }
- private void OnConnectionStatusChanged(object? sender, bool e)
- {
- if(e)
- {
- Status = "Connected";
- }
- else
- {
- Status = "Disconnected";
- RemoteIp = "Unknown";
- RemotePort = "Unknown";
- }
-
- }
- }
- }
|