Added: StateChangeEvent

This commit is contained in:
TheJoKlLa 2022-02-17 00:44:35 +01:00
parent 1ba1b6fbe0
commit 086bbc2497
5 changed files with 72 additions and 9 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net471</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net48</TargetFrameworks>
<IsPackable>false</IsPackable>
@ -27,7 +27,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />

View File

@ -10,6 +10,32 @@ using System.Threading.Tasks;
namespace Capnp.Rpc
{
/// <summary>
/// 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; }
/// <summary>
/// Last State of Connection
/// </summary>
public ConnectionState LastState { get; set; }
}
/// <summary>
/// ConnectionState EventHandler
/// </summary>
public delegate void ConnectionStateEventHandler(Object sender, ConnectionStateEventArgs e);
/// <summary>
/// TCP-based RPC implementation which will establish a connection to a TCP server implementing
/// the Cap'n Proto RPC protocol.
@ -131,11 +157,17 @@ namespace Capnp.Rpc
/// <summary>
/// Constructs an instance but does not yet attempt to connect.
/// </summary>
public TcpRpcClient()
/// <param name="receiveTimeout">The time-out value of the connection in milliseconds.</param>
/// <param name="sendTimeout">The send time-out value, in milliseconds.</param>
public TcpRpcClient(int receiveTimeout = 0, int sendTimeout = 0)
{
_rpcEngine = new RpcEngine();
_client = new TcpClient();
_client.ExclusiveAddressUse = false;
_client = new TcpClient
{
ExclusiveAddressUse = false,
ReceiveTimeout = receiveTimeout,
SendTimeout = sendTimeout
};
}
/// <summary>
@ -250,10 +282,41 @@ namespace Capnp.Rpc
_client.Dispose();
}
/// <summary>
/// State of Connection has changed
/// </summary>
public event ConnectionStateEventHandler? ConnectionStateChanged;
/// <summary>
/// On ConnectionState changed
/// </summary>
protected virtual void OnConnectionStateChanged(ConnectionStateEventArgs e)
{
ConnectionStateChanged?.Invoke(this, e);
}
private ConnectionState _State = ConnectionState.Initializing;
/// <summary>
/// Returns the state of this connection.
/// </summary>
public ConnectionState State { get; private set; } = ConnectionState.Initializing;
public ConnectionState State {
get
{
return _State;
}
private set
{
ConnectionStateEventArgs args = new ConnectionStateEventArgs()
{
LastState = _State,
NewState = value
};
_State = value;
OnConnectionStateChanged(args);
}
}
/// <summary>
/// Gets the number of RPC protocol messages sent by this client so far.

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp3.1;</TargetFrameworks>
<Configurations>Debug;Release</Configurations>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PublishRepositoryUrl>true</PublishRepositoryUrl>

View File

@ -184,6 +184,6 @@
/// <summary>
/// Generator tool version for GeneratedCodeAttribute
/// </summary>
public string GeneratorToolVersion = ThisAssembly.AssemblyVersion;
public string GeneratorToolVersion = "0.0";
}
}

View File

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net471;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net48;netcoreapp3.1</TargetFrameworks>
<SignAssembly>false</SignAssembly>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>