Add SignalR test client

This commit is contained in:
ngfrolov 2023-06-02 09:13:30 +05:00
parent c7021f3292
commit 4a60a8fb12
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7
3 changed files with 105 additions and 0 deletions

View File

@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudDb", "AsbCloudDb\As
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudWebApi.Tests", "AsbCloudWebApi.Tests\AsbCloudWebApi.Tests.csproj", "{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudWebApi.Tests", "AsbCloudWebApi.Tests\AsbCloudWebApi.Tests.csproj", "{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalRTestClient", "SignalRTestClient\SignalRTestClient.csproj", "{E6B97963-4CEA-47B6-A0C8-625FFA9B7D69}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -45,6 +47,10 @@ Global
{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}.Debug|Any CPU.Build.0 = Debug|Any CPU {9CF6FBB1-9AF5-45AB-A521-24F11A79B540}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}.Release|Any CPU.ActiveCfg = Release|Any CPU {9CF6FBB1-9AF5-45AB-A521-24F11A79B540}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}.Release|Any CPU.Build.0 = Release|Any CPU {9CF6FBB1-9AF5-45AB-A521-24F11A79B540}.Release|Any CPU.Build.0 = Release|Any CPU
{E6B97963-4CEA-47B6-A0C8-625FFA9B7D69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6B97963-4CEA-47B6-A0C8-625FFA9B7D69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6B97963-4CEA-47B6-A0C8-625FFA9B7D69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6B97963-4CEA-47B6-A0C8-625FFA9B7D69}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,85 @@
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace SignalRTestClient;
internal class Program
{
static void Main(string[] args)
{
var connectionBuilder = new HubConnectionBuilder();
var connection = connectionBuilder
.WithUrl("http://test.digitaldrilling.ru/hubs/telemetry", connectionOptions => {
connectionOptions.AccessTokenProvider = AccessTokenProvider;
})
.WithAutomaticReconnect()
.AddJsonProtocol()
.ConfigureLogging(ConfigureLogging)
.Build();
connection.Reconnected += (connectionId) => Task.Run(()=> Console.WriteLine($"Reconnected {connectionId}"));
connection.Closed += (exception) => Task.Run(()=> Console.WriteLine($"Closed {exception?.Message}"));
connection.Reconnecting += (exception) => Task.Run(()=> Console.WriteLine($"Reconnecting {exception?.Message}"));
Console.WriteLine("connecting");
connection.StartAsync().Wait();
Console.WriteLine("AddToGroup");
connection.SendCoreAsync("AddToGroup", new object[] { "well_1" }).Wait();
var subsction = connection.On<object>("UpdateProcessMap", (str1) => {
Console.WriteLine(str1);
} );
//connection.On("ReceiveDataSaub");
//connection.On("ReceiveDataSpin");
Console.ReadLine();
connection.SendCoreAsync("RemoveFromGroup", new object[] { "well_1" }).Wait();
Console.WriteLine("Done!");
}
private static void ConfigureLogging(ILoggingBuilder builder)
{
ILoggerProvider provider = new LoggerProvider();
builder.AddProvider(provider);
}
private static Task<string?> AccessTokenProvider()
{
return Task.FromResult("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJpZCI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZGV2IiwiaWRDb21wYW55IjoiMSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6InJvb3QiLCJuYmYiOjE2NjI1NDgxNjIsImV4cCI6MTY5NDEwNTc2MiwiaXNzIjoiYSIsImF1ZCI6ImEifQ.OEAlNzxi7Jat6pzDBTAjTbChskc-tdJthJexyWwwUKE");
}
}
internal class LoggerProvider : ILoggerProvider
{
public ILogger CreateLogger(string categoryName)
{
ILogger logger = new ConsoleLogger();
return logger;
}
public void Dispose()
{
//throw new NotImplementedException();
}
}
internal class ConsoleLogger : ILogger
{
public IDisposable? BeginScope<TState>(TState state) where TState : notnull
{
return null;
}
public bool IsEnabled(LogLevel logLevel)
{
return true;
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
{
Console.WriteLine(formatter(state, exception));
}
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.5" />
</ItemGroup>
</Project>