mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 14:51:41 +01:00
Added: StateChangeEvent
This commit is contained in:
parent
1ba1b6fbe0
commit
086bbc2497
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netcoreapp3.1;net471</TargetFrameworks>
|
<TargetFrameworks>netcoreapp3.1;net48</TargetFrameworks>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
|
|
||||||
@ -27,7 +27,7 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</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.Extensions.Logging.Console" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
|
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
|
||||||
|
@ -10,6 +10,32 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Capnp.Rpc
|
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>
|
/// <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.
|
||||||
@ -131,11 +157,17 @@ namespace Capnp.Rpc
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs an instance but does not yet attempt to connect.
|
/// Constructs an instance but does not yet attempt to connect.
|
||||||
/// </summary>
|
/// </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();
|
_rpcEngine = new RpcEngine();
|
||||||
_client = new TcpClient();
|
_client = new TcpClient
|
||||||
_client.ExclusiveAddressUse = false;
|
{
|
||||||
|
ExclusiveAddressUse = false,
|
||||||
|
ReceiveTimeout = receiveTimeout,
|
||||||
|
SendTimeout = sendTimeout
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -250,10 +282,41 @@ namespace Capnp.Rpc
|
|||||||
_client.Dispose();
|
_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>
|
/// <summary>
|
||||||
/// Returns the state of this connection.
|
/// Returns the state of this connection.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Gets the number of RPC protocol messages sent by this client so far.
|
/// Gets the number of RPC protocol messages sent by this client so far.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
|
<TargetFrameworks>netstandard2.0;netcoreapp3.1;</TargetFrameworks>
|
||||||
<Configurations>Debug;Release</Configurations>
|
<Configurations>Debug;Release</Configurations>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
|
@ -184,6 +184,6 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generator tool version for GeneratedCodeAttribute
|
/// Generator tool version for GeneratedCodeAttribute
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string GeneratorToolVersion = ThisAssembly.AssemblyVersion;
|
public string GeneratorToolVersion = "0.0";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFrameworks>net471;netcoreapp2.1</TargetFrameworks>
|
<TargetFrameworks>net48;netcoreapp3.1</TargetFrameworks>
|
||||||
<SignAssembly>false</SignAssembly>
|
<SignAssembly>false</SignAssembly>
|
||||||
|
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user