Skip to content

Commit

Permalink
Feat/dotnet7 (#93)
Browse files Browse the repository at this point in the history
* upd memmon to don7

* upd samples to dotnet7

* clean warnings

* change trace erros in x509 chain

Co-authored-by: ridomin <[email protected]>
  • Loading branch information
rido-min and ridomin authored Dec 14, 2022
1 parent f0fdd60 commit 41ed16a
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 35 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/samples2docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ jobs:
- name: pi-sense docker push
run: docker push ghcr.io/iotmodels/pi-sense-device:x64


- name: grpc docker
run: docker build -f .\samples\mqtt-grpc-device\Dockerfile . -t ghcr.io/iotmodels/mqtt-grpc-device:latest

- name: grpc push
run: docker push ghcr.io/iotmodels/mqtt-grpc-device:latest


#- name: Build the Docker image ARM
Expand Down
6 changes: 6 additions & 0 deletions samples/mqtt-grpc-device/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using MQTTnet.Extensions.MultiCloud.BrokerIoTClient;
using MQTTnet.Extensions.MultiCloud.Connections;
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -24,13 +25,18 @@ public Device(ILogger<Device> logger, IConfiguration config)
{
_logger = logger;
_configuration = config;
if (_configuration.GetSection("ConsoleTracing").Get<bool>() == true)
{
Trace.Listeners.Add(new ConsoleTraceListener());
}
}


protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
ConnectionSettings cs = new(_configuration.GetConnectionString("cs")) { ModelId = mqtt_grpc_sample_device.ModelId };
connection = await BrokerClientFactory.CreateFromConnectionSettingsAsync(cs, true, stoppingToken);
_logger.LogWarning("Connected to {cs} with {sdk}", BrokerClientFactory.ComputedSettings, BrokerClientFactory.NuGetPackageVersion);

client = new mqtt_grpc_sample_device(connection);

Expand Down
24 changes: 10 additions & 14 deletions samples/mqtt-grpc-device/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/nightly/runtime:7.0-jammy-chiseled AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build
WORKDIR /src
COPY ["samples/mqtt-grpc-device/mqtt-grpc-device.csproj", "samples/mqtt-grpc-device/"]
COPY ["src/MQTTnet.Extensions.MultiCloud.BrokerIoTClient/MQTTnet.Extensions.MultiCloud.BrokerIoTClient.csproj", "src/MQTTnet.Extensions.MultiCloud.BrokerIoTClient/"]
COPY ["src/MQTTnet.Extensions.MultiCloud/MQTTnet.Extensions.MultiCloud.csproj", "src/MQTTnet.Extensions.MultiCloud/"]
RUN dotnet restore "samples/mqtt-grpc-device/mqtt-grpc-device.csproj"
COPY . .
WORKDIR "/src/samples/mqtt-grpc-device"
RUN dotnet build "mqtt-grpc-device.csproj" -c Release -o /app/build
WORKDIR /samples
COPY "samples/mqtt-grpc-device/." .

RUN dotnet remove reference ../../src/MQTTnet.Extensions.MultiCloud.BrokerIoTClient/MQTTnet.Extensions.MultiCloud.BrokerIoTClient.csproj
RUN dotnet add package MQTTnet.Extensions.MultiCloud.BrokerIoTClient --prerelease -n

FROM build AS publish
RUN dotnet publish "mqtt-grpc-device.csproj" -c Release -o /app/publish --os linux --arch x64 --use-current-runtime --self-contained false --no-restore
RUN dotnet restore "mqtt-grpc-device.csproj" --use-current-runtime
RUN dotnet build "mqtt-grpc-device.csproj" -c Release --use-current-runtime --no-restore
RUN dotnet publish "mqtt-grpc-device.csproj" -c Release -o /app --use-current-runtime --self-contained false --no-restore

FROM base AS final
FROM mcr.microsoft.com/dotnet/nightly/runtime:7.0-jammy-chiseled
WORKDIR /app
COPY --from=publish /app/publish .
COPY --from=build /app .
ENTRYPOINT ["dotnet", "mqtt-grpc-device.dll"]
2 changes: 1 addition & 1 deletion samples/mqtt-grpc-device/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.Hosting.Lifetime": "Information"
"Microsoft.Hosting.Lifetime": "Warning"
}
}
}
10 changes: 3 additions & 7 deletions samples/mqtt-grpc-device/mqtt-grpc-device.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
<Nullable>enable</Nullable>
<RootNamespace>mqtt_grpc_device</RootNamespace>
<IsPackable>false</IsPackable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.21.9" />
<PackageReference Include="Grpc.Tools" Version="2.50.0">
<PackageReference Include="Google.Protobuf" Version="3.21.11" />
<PackageReference Include="Grpc.Tools" Version="2.51.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.2" />
</ItemGroup>
<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions samples/mqtt-grpc-device/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="myget" value="https://www.myget.org/F/ridopackages/api/v3/index.json" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion samples/payload-size/payload-size.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>payload_size</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
8 changes: 4 additions & 4 deletions samples/pi-sense-device/SenseHatFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ public async Task<Isensehat> CreateSenseHatClientAsync(string connectionStringNa
return client;
}

private static async Task<dtmi_rido_pnp_sensehat.mqtt.sensehat> CreateBrokerClientAsync(string connectionString, CancellationToken cancellationToken = default)
private static async Task<dtmi_rido_pnp_sensehat.mqtt._sensehat> CreateBrokerClientAsync(string connectionString, CancellationToken cancellationToken = default)
{
var cs = new ConnectionSettings(connectionString) { ModelId = Isensehat.ModelId };
var mqtt = await BrokerClientFactory.CreateFromConnectionSettingsAsync(cs, true, cancellationToken);
var client = new dtmi_rido_pnp_sensehat.mqtt.sensehat(mqtt);
var client = new dtmi_rido_pnp_sensehat.mqtt._sensehat(mqtt);
computedSettings = BrokerClientFactory.ComputedSettings!;
nugetPackageVersion = BrokerClientFactory.NuGetPackageVersion;
return client;
}

private static async Task<dtmi_rido_pnp_sensehat.hub.sensehat> CreateHubClientAsync(string connectionString, CancellationToken cancellationToken = default)
private static async Task<dtmi_rido_pnp_sensehat.hub._sensehat> CreateHubClientAsync(string connectionString, CancellationToken cancellationToken = default)
{
var cs = connectionString + ";ModelId=" + Isensehat.ModelId;
var hub = await HubDpsFactory.CreateFromConnectionSettingsAsync(cs, cancellationToken);
var client = new dtmi_rido_pnp_sensehat.hub.sensehat(hub);
var client = new dtmi_rido_pnp_sensehat.hub._sensehat(hub);
computedSettings = HubDpsFactory.ComputedSettings!;
nugetPackageVersion = HubDpsFactory.NuGetPackageVersion;
//await client.InitState();
Expand Down
4 changes: 2 additions & 2 deletions samples/pi-sense-device/dtmi_rido_pnp_sensehat-1.hub.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace dtmi_rido_pnp_sensehat.hub;

public class sensehat : HubMqttClient, Isensehat
public class _sensehat : HubMqttClient, Isensehat
{
public IReadOnlyProperty<string> Property_piri { get; set; }
public IReadOnlyProperty<string> Property_ipaddr { get; set; }
Expand All @@ -23,7 +23,7 @@ public class sensehat : HubMqttClient, Isensehat

public ICommand<string, string> Command_ChangeLCDColor { get; set; }

internal sensehat(IMqttClient c) : base(c)
internal _sensehat(IMqttClient c) : base(c)
{
Property_piri = new ReadOnlyProperty<string>(c, "piri");
Property_ipaddr = new ReadOnlyProperty<string>(c, "ipaddr");
Expand Down
4 changes: 2 additions & 2 deletions samples/pi-sense-device/dtmi_rido_pnp_sensehat-1.mqtt.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace dtmi_rido_pnp_sensehat.mqtt;

public class sensehat : Isensehat
public class _sensehat : Isensehat
{
public IMqttClient Connection { get; set; }
public string InitialState { get; set; }
Expand All @@ -27,7 +27,7 @@ public class sensehat : Isensehat



internal sensehat(IMqttClient c)
internal _sensehat(IMqttClient c)
{
Connection = c;
Property_piri = new ReadOnlyProperty<string>(c, "piri");
Expand Down
2 changes: 1 addition & 1 deletion samples/pi-sense-device/pi-sense-device.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-pi_sense_device-15259864-24f9-45ee-8722-c72ed515d0ba</UserSecretsId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ internal static bool ValidateChain(X509Certificate cert, string caCertFile = "")
caCerts.ImportFromPemFile(caCertFile);
chain.ChainPolicy.CustomTrustStore.AddRange(caCerts);
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
Trace.TraceError($"Loaded {caCerts.Count} certs from caFile: {caCertFile} ");
caCerts.ToList().ForEach(c => Trace.TraceError(c.Subject));
Trace.TraceWarning($"Loaded {caCerts.Count} certs from caFile: {caCertFile} ");
caCerts.ToList().ForEach(c => Trace.TraceWarning(c.Subject));
}
var x5092 = new X509Certificate2(cert);
var res = chain.Build(x5092);
Expand Down

0 comments on commit 41ed16a

Please sign in to comment.