|
@@ -5,12 +5,14 @@ using System.Net;
|
|
|
|
|
|
namespace AlarmInfoServerSim.ViewModels;
|
|
|
|
|
|
-public partial class StatusBarViewModel : ObservableObject
|
|
|
+public partial class StatusBarViewModel : ObservableObject ,IDisposable
|
|
|
{
|
|
|
private readonly ILogService _logService;
|
|
|
private readonly ISharedConfig _sharedConfig;
|
|
|
private readonly IInfoSendingService _infoSendingService;
|
|
|
|
|
|
+ private bool disposedValue;
|
|
|
+
|
|
|
[ObservableProperty]
|
|
|
private List<IPAddress> _iPAddresses;
|
|
|
|
|
@@ -27,10 +29,10 @@ public partial class StatusBarViewModel : ObservableObject
|
|
|
private string _buttonContent;
|
|
|
|
|
|
[ObservableProperty]
|
|
|
- private IPAddress _remoteIp;
|
|
|
+ private string _remoteIp;
|
|
|
|
|
|
[ObservableProperty]
|
|
|
- private int _remotePort;
|
|
|
+ private string _remotePort;
|
|
|
|
|
|
[ObservableProperty]
|
|
|
private string _status;
|
|
@@ -43,14 +45,13 @@ public partial class StatusBarViewModel : ObservableObject
|
|
|
_infoSendingService.TcpServerStatusChanged += OnTcpServerStatusChanged;
|
|
|
_infoSendingService.ConnectionChanged += OnConnectionChanged;
|
|
|
|
|
|
-
|
|
|
_iPAddresses = _sharedConfig.IPAddresses;
|
|
|
- _isSelectingEnable=true;
|
|
|
+ _isSelectingEnable = true;
|
|
|
_selectedIP = IPAddress.None;
|
|
|
_selectedPort = 50052;
|
|
|
_buttonContent = "Open";
|
|
|
- _remoteIp =IPAddress.None;
|
|
|
- _remotePort = -1;
|
|
|
+ _remoteIp = "Unknown";
|
|
|
+ _remotePort = "Unknown";
|
|
|
_status = "Disconnected";
|
|
|
}
|
|
|
|
|
@@ -94,17 +95,48 @@ public partial class StatusBarViewModel : ObservableObject
|
|
|
if (e.Item1)
|
|
|
{
|
|
|
Status = "Connected";
|
|
|
- RemoteIp = e.Item2.RemoteEndPoint.Address;
|
|
|
- RemotePort = e.Item2.RemoteEndPoint.Port;
|
|
|
+ RemoteIp = e.Item2.RemoteEndPoint.Address.ToString();
|
|
|
+ RemotePort = e.Item2.RemoteEndPoint.Port.ToString();
|
|
|
_logService.Log($"Get a connection from {RemoteIp}:{RemotePort}");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Status = "Disconnected";
|
|
|
- RemoteIp = IPAddress.None;
|
|
|
- RemotePort = -1;
|
|
|
+ RemoteIp = "Unknown";
|
|
|
+ RemotePort = "Unknown";
|
|
|
_logService.Log($"The connection lost");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ protected virtual void Dispose(bool disposing)
|
|
|
+ {
|
|
|
+ if (!disposedValue)
|
|
|
+ {
|
|
|
+ if (disposing)
|
|
|
+ {
|
|
|
+ // TODO: dispose managed state (managed objects)
|
|
|
+ _infoSendingService.TcpServerStatusChanged-=OnTcpServerStatusChanged;
|
|
|
+ _infoSendingService.ConnectionChanged -= OnConnectionChanged;
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: free unmanaged resources (unmanaged objects) and override finalizer
|
|
|
+ // TODO: set large fields to null
|
|
|
+ disposedValue = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
|
|
+ // ~StatusBarViewModel()
|
|
|
+ // {
|
|
|
+ // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
|
+ // Dispose(disposing: false);
|
|
|
+ // }
|
|
|
+
|
|
|
+ public void Dispose()
|
|
|
+ {
|
|
|
+ // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
|
|
+ Dispose(disposing: true);
|
|
|
+ GC.SuppressFinalize(this);
|
|
|
+ }
|
|
|
}
|