signalR dziaua #1
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Squirrowse.Client.Service;
|
||||
|
||||
namespace Squirrowse.Client
|
||||
{
|
||||
@ -19,6 +20,7 @@ namespace Squirrowse.Client
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddHostedService<Worker>();
|
||||
services.AddTransient<IConnectionManager, ConnectionManager>();//keep as transient for now
|
||||
});
|
||||
}
|
||||
}
|
||||
|
21
Squirrowse.Client/Service/ConnectionManager.cs
Normal file
21
Squirrowse.Client/Service/ConnectionManager.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Squirrowse.Client.Service
|
||||
{
|
||||
public class ConnectionManager : IConnectionManager
|
||||
{
|
||||
private readonly HubConnection _connection;
|
||||
|
||||
public ConnectionManager(string url, int port)
|
||||
{
|
||||
_connection = new HubConnectionBuilder()
|
||||
.WithUrl($"{url}:{port}/StreamHub")
|
||||
.AddMessagePackProtocol()
|
||||
.WithAutomaticReconnect()
|
||||
.Build();
|
||||
}
|
||||
|
||||
public HubConnection EstablishHubConnection() => _connection;
|
||||
}
|
||||
}
|
10
Squirrowse.Client/Service/IConnectionManager.cs
Normal file
10
Squirrowse.Client/Service/IConnectionManager.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
|
||||
namespace Squirrowse.Client.Service
|
||||
{
|
||||
public interface IConnectionManager
|
||||
{
|
||||
HubConnection EstablishHubConnection();
|
||||
|
||||
}
|
||||
}
|
34
Squirrowse.Core.Tests/ImgExtensionTests.cs
Normal file
34
Squirrowse.Core.Tests/ImgExtensionTests.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using FluentAssertions;
|
||||
using OpenCvSharp;
|
||||
using Squirrowse.Core.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace Squirrowse.Core.Tests
|
||||
{
|
||||
public class ImgExtensionTests
|
||||
{
|
||||
private readonly Mat sampleMat = new Mat(500, 600, MatType.CV_8UC3);
|
||||
|
||||
[SkippableFact]
|
||||
public void ByteShouldBeConvertedToMat()
|
||||
{
|
||||
//
|
||||
Skip.If(true, "Cannot use fluent assertion in this kind of test (compare pointer to obj)");
|
||||
//
|
||||
var bytes = sampleMat.ConvertToJpgByte();
|
||||
|
||||
var reMet = bytes.ConvertByteToMat();
|
||||
|
||||
reMet.Should().BeEquivalentTo(sampleMat);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatShouldBeConvertedToByteArr()
|
||||
{
|
||||
var newByteArr = sampleMat.ConvertToJpgByte();
|
||||
|
||||
newByteArr.Should().BeOfType(typeof(byte[]));
|
||||
newByteArr.Should().NotBeNullOrEmpty();
|
||||
}
|
||||
}
|
||||
}
|
23
Squirrowse.Core.Tests/Squirrowse.Core.Tests.csproj
Normal file
23
Squirrowse.Core.Tests/Squirrowse.Core.Tests.csproj
Normal file
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="5.9.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
|
||||
<PackageReference Include="xunit" Version="2.4.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="1.0.1" />
|
||||
<PackageReference Include="OpenCvSharp4.Windows" Version="4.1.1.20191021" />
|
||||
<PackageReference Include="Xunit.SkippableFact" Version="1.3.12" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Squirrowse.Core\Squirrowse.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
16
Squirrowse.Core/CoreModule.cs
Normal file
16
Squirrowse.Core/CoreModule.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Squirrowse.Core
|
||||
{
|
||||
public static class CoreModule
|
||||
{
|
||||
public static IServiceCollection AddCoreModule(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
12
Squirrowse.Core/Models/VideoFrame.cs
Normal file
12
Squirrowse.Core/Models/VideoFrame.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace Squirrowse.Client.Models
|
||||
{
|
||||
public class VideoFrame
|
||||
{
|
||||
public byte[] FrameBytes { get; set; }
|
||||
public DateTime TimeStamp => DateTime.Now;
|
||||
public Guid id => Guid.NewGuid();
|
||||
public string Issuer { get; set; }
|
||||
}
|
||||
}
|
21
Squirrowse.Core/Services/ImgExtensions.cs
Normal file
21
Squirrowse.Core/Services/ImgExtensions.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace Squirrowse.Core.Services
|
||||
{
|
||||
public static class ImgExtensions
|
||||
{
|
||||
public static byte[] ConvertToJpgByte(this Mat mat)
|
||||
{
|
||||
Cv2.ImEncode(".jpg", mat, out var imgbuffer);//no need to dispose
|
||||
return imgbuffer.Any() ? imgbuffer : new byte[] { };
|
||||
}
|
||||
|
||||
public static Mat ConvertByteToMat(this byte[] bytearr)
|
||||
{
|
||||
using var tempMat = Cv2.ImDecode(bytearr, ImreadModes.Unchanged); //keep as disposable
|
||||
return tempMat ?? new Mat();
|
||||
}
|
||||
}
|
||||
}
|
11
Squirrowse.Core/Squirrowse.Core.csproj
Normal file
11
Squirrowse.Core/Squirrowse.Core.csproj
Normal file
@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.0.0" />
|
||||
<PackageReference Include="OpenCvSharp4.Windows" Version="4.1.1.20191021" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -3,9 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29411.108
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrowse.Service", "Squirrowse.Service\Squirrowse.Service.csproj", "{8C085621-BAAA-4E96-B027-561BC18751EE}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrowse.Service", "Squirrowse.Service\Squirrowse.Service.csproj", "{8C085621-BAAA-4E96-B027-561BC18751EE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrowse.Client", "Squirrowse.Client\Squirrowse.Client.csproj", "{558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Squirrowse.Client", "Squirrowse.Client\Squirrowse.Client.csproj", "{558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrowse.Core", "Squirrowse.Core\Squirrowse.Core.csproj", "{D0989FCC-484E-4ADB-BA5E-1020894F9C09}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{BB569A06-F4D1-4927-87AB-86C4BD2AFBC5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrowse.Core.Tests", "Squirrowse.Core.Tests\Squirrowse.Core.Tests.csproj", "{CFA96677-EAA7-4871-AAD8-E6336973366F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -21,10 +27,21 @@ Global
|
||||
{558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{558A5917-6AD3-4C40-ACA1-EE3B8B8927C8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D0989FCC-484E-4ADB-BA5E-1020894F9C09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D0989FCC-484E-4ADB-BA5E-1020894F9C09}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D0989FCC-484E-4ADB-BA5E-1020894F9C09}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D0989FCC-484E-4ADB-BA5E-1020894F9C09}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{CFA96677-EAA7-4871-AAD8-E6336973366F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{CFA96677-EAA7-4871-AAD8-E6336973366F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CFA96677-EAA7-4871-AAD8-E6336973366F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CFA96677-EAA7-4871-AAD8-E6336973366F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{CFA96677-EAA7-4871-AAD8-E6336973366F} = {BB569A06-F4D1-4927-87AB-86C4BD2AFBC5}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1CC5C3B8-3825-4EB5-ACFF-73B4CAC8945D}
|
||||
EndGlobalSection
|
||||
|
Loading…
Reference in New Issue
Block a user