Update TcpRpcClient.cs

This commit is contained in:
TheJoKlLa 2022-05-16 22:55:54 +02:00 committed by GitHub
parent 086bbc2497
commit 0176a503c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,4 @@
using Capnp.FrameTracing; using Capnp.FrameTracing;
using Capnp.Util; using Capnp.Util;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System; using System;
@ -10,32 +10,12 @@ using System.Threading.Tasks;
namespace Capnp.Rpc namespace Capnp.Rpc
{ {
/// <summary> public class ConnectionStateChange
/// State of Variable has changed
/// </summary>
public delegate void StateChanged();
/// <summary>
/// ConnectionState has changed EventArgs
/// </summary>
public class ConnectionStateEventArgs : EventArgs
{ {
/// <summary>
/// New State of Connection
/// </summary>
public ConnectionState NewState { get; set; } public ConnectionState NewState { get; set; }
/// <summary>
/// Last State of Connection
/// </summary>
public ConnectionState LastState { get; set; } public ConnectionState LastState { get; set; }
} }
/// <summary>
/// ConnectionState EventHandler
/// </summary>
public delegate void ConnectionStateEventHandler(Object sender, ConnectionStateEventArgs e);
/// <summary> /// <summary>
/// TCP-based RPC implementation which will establish a connection to a TCP server implementing /// TCP-based RPC implementation which will establish a connection to a TCP server implementing
/// the Cap'n Proto RPC protocol. /// the Cap'n Proto RPC protocol.
@ -285,15 +265,7 @@ namespace Capnp.Rpc
/// <summary> /// <summary>
/// State of Connection has changed /// State of Connection has changed
/// </summary> /// </summary>
public event ConnectionStateEventHandler? ConnectionStateChanged; public event EventHandler<ConnectionStateChange> ConnectionStateChanged;
/// <summary>
/// On ConnectionState changed
/// </summary>
protected virtual void OnConnectionStateChanged(ConnectionStateEventArgs e)
{
ConnectionStateChanged?.Invoke(this, e);
}
private ConnectionState _State = ConnectionState.Initializing; private ConnectionState _State = ConnectionState.Initializing;
@ -307,14 +279,18 @@ namespace Capnp.Rpc
} }
private set private set
{ {
ConnectionStateEventArgs args = new ConnectionStateEventArgs() ConnectionStateChange args = new ConnectionStateChange()
{ {
LastState = _State, LastState = _State,
NewState = value NewState = value
}; };
_State = value; _State = value;
OnConnectionStateChanged(args); EventHandler<ConnectionStateChange> eventHandler = ConnectionStateChanged;
if(eventHandler != null)
{
eventHandler(this, args);
}
} }
} }
@ -350,4 +326,4 @@ namespace Capnp.Rpc
/// </summary> /// </summary>
public bool IsWaitingForData => _pump?.IsWaitingForData ?? false; public bool IsWaitingForData => _pump?.IsWaitingForData ?? false;
} }
} }