|
@@ -9,14 +9,15 @@ using UniversalNetFrame451.IO;
|
|
|
|
|
|
namespace AlarmInfoServerSim.Services
|
|
namespace AlarmInfoServerSim.Services
|
|
{
|
|
{
|
|
- public class SendInfoSevice : ISendInfoSevice, ITlvProvider
|
|
|
|
|
|
+ public class SendInfoService : ISendInfoService, ITlvProvider, IDisposable
|
|
{
|
|
{
|
|
private readonly ISharedConfig _sharedConfig;
|
|
private readonly ISharedConfig _sharedConfig;
|
|
private readonly ITlvCommunicatorServer _server;
|
|
private readonly ITlvCommunicatorServer _server;
|
|
|
|
|
|
private bool _isConnected = false;
|
|
private bool _isConnected = false;
|
|
|
|
+ private bool disposedValue;
|
|
|
|
|
|
- public SendInfoSevice(ISharedConfig sharedConfig)
|
|
|
|
|
|
+ public SendInfoService(ISharedConfig sharedConfig)
|
|
{
|
|
{
|
|
_sharedConfig= sharedConfig;
|
|
_sharedConfig= sharedConfig;
|
|
|
|
|
|
@@ -24,7 +25,7 @@ namespace AlarmInfoServerSim.Services
|
|
_server.Initialize(this);
|
|
_server.Initialize(this);
|
|
}
|
|
}
|
|
|
|
|
|
- public bool HasConnection => _isConnected;
|
|
|
|
|
|
+ public event EventHandler<bool>? ConnectionChanged;
|
|
|
|
|
|
public bool Open()
|
|
public bool Open()
|
|
{
|
|
{
|
|
@@ -47,11 +48,13 @@ namespace AlarmInfoServerSim.Services
|
|
public void Connected(TcpConnection connection)
|
|
public void Connected(TcpConnection connection)
|
|
{
|
|
{
|
|
_isConnected = true;
|
|
_isConnected = true;
|
|
|
|
+ ConnectionChanged?.Invoke(null, _isConnected);
|
|
}
|
|
}
|
|
|
|
|
|
public void Disconnected(TcpConnection connection)
|
|
public void Disconnected(TcpConnection connection)
|
|
{
|
|
{
|
|
_isConnected = false;
|
|
_isConnected = false;
|
|
|
|
+ ConnectionChanged?.Invoke(null, _isConnected);
|
|
}
|
|
}
|
|
|
|
|
|
public void Received(TlvData data)
|
|
public void Received(TlvData data)
|
|
@@ -63,5 +66,35 @@ namespace AlarmInfoServerSim.Services
|
|
{
|
|
{
|
|
throw new NotImplementedException();
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ protected virtual void Dispose(bool disposing)
|
|
|
|
+ {
|
|
|
|
+ if (!disposedValue)
|
|
|
|
+ {
|
|
|
|
+ if (disposing)
|
|
|
|
+ {
|
|
|
|
+ // TODO: 释放托管状态(托管对象)
|
|
|
|
+ _server.Dispose();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // TODO: 释放未托管的资源(未托管的对象)并重写终结器
|
|
|
|
+ // TODO: 将大型字段设置为 null
|
|
|
|
+ disposedValue = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // // TODO: 仅当“Dispose(bool disposing)”拥有用于释放未托管资源的代码时才替代终结器
|
|
|
|
+ // ~SendInfoService()
|
|
|
|
+ // {
|
|
|
|
+ // // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
|
|
|
|
+ // Dispose(disposing: false);
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ public void Dispose()
|
|
|
|
+ {
|
|
|
|
+ // 不要更改此代码。请将清理代码放入“Dispose(bool disposing)”方法中
|
|
|
|
+ Dispose(disposing: true);
|
|
|
|
+ GC.SuppressFinalize(this);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|