Skip to content

Commit

Permalink
the solution builds after upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
aaart committed Oct 6, 2024
1 parent 1807f12 commit 7e62a1d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 73 deletions.
10 changes: 5 additions & 5 deletions Sod.Infrastructure/Sod.Infrastructure.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="MQTTnet" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="StackExchange.Redis" Version="2.2.88" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="MQTTnet" Version="4.3.7.1207" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="StackExchange.Redis" Version="2.8.16" />
</ItemGroup>

</Project>
17 changes: 6 additions & 11 deletions Sod.Model/Events/Outgoing/Mqtt/MqttOutgoingEventPublisher.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using MQTTnet;
using MQTTnet.Client.Publishing;
using MQTTnet.Client;
using Sod.Infrastructure.Capabilities;
using Sod.Model.CommonTypes;

namespace Sod.Model.Events.Outgoing.Mqtt;

public class MqttOutgoingEventPublisher : LoggingCapability, IOutgoingEventPublisher
{
private readonly IApplicationMessagePublisher _publisher;
private readonly IMqttClient _client;
private readonly OutgoingEventMappings _mappings;

public MqttOutgoingEventPublisher(IApplicationMessagePublisher publisher, OutgoingEventMappings mappings)
public MqttOutgoingEventPublisher(IMqttClient client, OutgoingEventMappings mappings)
{
_publisher = publisher;
_client = client;
_mappings = mappings;
}

Expand All @@ -31,7 +26,7 @@ public async Task<IEnumerable<FailedOutgoingEvent>> PublishAsync(OutgoingEvent e
.WithTopic(topic)
.WithPayload(evnt.Value)
.Build();
var publishResult = await _publisher.PublishAsync(msg, CancellationToken.None);
var publishResult = await _client.PublishAsync(msg);
if (publishResult.ReasonCode != MqttClientPublishReasonCode.Success) failed.Add(new FailedOutgoingEvent(evnt, FailedOutgoingEventReason.CommunicationError));
}

Expand Down
2 changes: 1 addition & 1 deletion Sod.Model/Sod.Model.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
14 changes: 7 additions & 7 deletions Sod.Tests/Sod.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>

<IsPackable>false</IsPackable>

<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.1.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4"/>
<PackageReference Include="Moq" Version="4.16.1"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
59 changes: 28 additions & 31 deletions Sod.Worker/Modules/InfrastructureModule.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.IO;
using System.Linq;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Autofac;
using MQTTnet;
using MQTTnet.Client.Options;
using MQTTnet.Client;
using MQTTnet.Extensions.ManagedClient;
using Sod.Infrastructure.Satel.Communication;
using Sod.Infrastructure.Satel.Socket;
Expand Down Expand Up @@ -56,60 +57,56 @@ protected override void Load(ContainerBuilder builder)
.WithCredentials(cfg.User, cfg.Password)
.WithTcpServer(cfg.Host, cfg.Port);
if (cfg.CrtPath != null)
optionsBuilder.WithTls(x =>
optionsBuilder.WithTlsOptions(opt =>
{
var caCrt = new X509Certificate2(File.ReadAllBytes(cfg.CrtPath));
x.UseTls = true;
x.SslProtocol = System.Security.Authentication.SslProtocols.Tls12;
x.CertificateValidationHandler = certContext =>
{
var chain = new X509Chain();
chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag;
chain.ChainPolicy.VerificationTime = DateTime.Now;
chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 0);

chain.ChainPolicy.CustomTrustStore.Add(caCrt);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;

// convert provided X509Certificate to X509Certificate2
var x5092 = new X509Certificate2(certContext.Certificate);

return chain.Build(x5092);
};
var caCrt = X509CertificateLoader.LoadCertificate(File.ReadAllBytes(cfg.CrtPath));
opt
.UseTls()
.WithSslProtocols(SslProtocols.Tls12 | SslProtocols.Tls13)
.WithCertificateValidationHandler(certContext =>
{
var chain = new X509Chain();
chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag;
chain.ChainPolicy.VerificationTime = DateTime.Now;
chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 0);

chain.ChainPolicy.CustomTrustStore.Add(caCrt);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
// convert provided X509Certificate to X509Certificate2
var x5092 = new X509Certificate2(certContext.Certificate);

return chain.Build(x5092);
});
});

return optionsBuilder.Build();
})
.As<IMqttClientOptions>()
.As<MqttClientOptions>()
.SingleInstance();

builder
.Register(ctx =>
new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(2))
.WithClientOptions(ctx.Resolve<IMqttClientOptions>())
.WithClientOptions(ctx.Resolve<MqttClientOptions>())
.Build())
.As<IManagedMqttClientOptions>()
.As<ManagedMqttClientOptions>()
.SingleInstance();

builder.RegisterType<Broker>().As<IBroker>().SingleInstance();

builder
.Register(_ => new MqttFactory().CreateManagedMqttClient())
.As<IApplicationMessagePublisher>()
.As<IApplicationMessageReceiver>()
.As<IMqttClient>()
.SingleInstance()
.OnActivated(async activatedEventArgs =>
{
var client = activatedEventArgs.Instance;
await client.StartAsync(activatedEventArgs.Context.Resolve<IManagedMqttClientOptions>());
var mappings = activatedEventArgs.Context.Resolve<EventHandlerMappings>();
foreach (var topic in mappings.Topics) await client.SubscribeAsync(topic);

var broker = activatedEventArgs.Context.Resolve<IBroker>();
client.UseApplicationMessageReceivedHandler(x => { broker.Process(x.ApplicationMessage.Topic, Encoding.UTF8.GetString(x.ApplicationMessage.Payload)); });
await client.StartAsync(activatedEventArgs.Context.Resolve<ManagedMqttClientOptions>());
});

builder.RegisterType<MqttOutgoingEventPublisher>().As<IOutgoingEventPublisher>().SingleInstance();
Expand Down
22 changes: 11 additions & 11 deletions Sod.Worker/Sod.Worker.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<UserSecretsId>dotnet-Sod.Service-7247485F-D30A-418F-98AE-4EC2930457F3</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.3.0"/>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.2.0"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0"/>
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="3.1.1"/>
<PackageReference Include="Serilog" Version="2.10.0"/>
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0"/>
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0"/>
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0"/>
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1"/>
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0"/>
<PackageReference Include="Autofac" Version="8.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="4.3.7.1207" />
<PackageReference Include="Serilog" Version="4.0.2" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 0 additions & 7 deletions global.json

This file was deleted.

0 comments on commit 7e62a1d

Please sign in to comment.