From 45cc4080ca286d8362665818fcd411ed461145eb Mon Sep 17 00:00:00 2001 From: Michael Hallock Date: Wed, 24 Jun 2020 01:54:21 -0400 Subject: [PATCH] Updated build config, dependencies, and moved to .NET core 3.1 --- appveyor.yml | 28 +++++++++++++++++++ src/Dockerfile | 4 +-- src/Dockerfile.arm32 | 4 +-- .../HarmonyMqttService.cs | 25 +++++++++-------- .../HomeAutio.Mqtt.Harmony.csproj | 19 +++++++------ src/HomeAutio.Mqtt.Harmony/Program.cs | 12 +------- 6 files changed, 56 insertions(+), 36 deletions(-) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..a5521ea --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,28 @@ +version: 1.0.0.{build} +branches: + only: + - master +skip_tags: true +image: Visual Studio 2019 +configuration: Release +dotnet_csproj: + patch: true + file: '**\*.csproj' + version: '{version}' + version_prefix: '{version}' + package_version: '{version}' + assembly_version: '{version}' + file_version: '{version}' + informational_version: '{version}' +build_script: +- ps: >- + dotnet restore src/HomeAutio.Mqtt.Harmony.sln + + dotnet publish -c Release src/HomeAutio.Mqtt.Harmony.sln +artifacts: +- path: src\HomeAutio.Mqtt.Harmony\bin\$(configuration)\netcoreapp3.1\publish + name: HomeAutio.Mqtt.Harmony-$(appveyor_build_version) +deploy: +- provider: GitHub + auth_token: $(GITHUB_API_KEY) + artifact: src\HomeAutio.Mqtt.Harmony\bin\$(configuration)\netcoreapp3.1\HomeAutio.Mqtt.Harmony-$(appveyor_build_version).zip \ No newline at end of file diff --git a/src/Dockerfile b/src/Dockerfile index 3522c37..5e5222a 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -1,4 +1,4 @@ -FROM microsoft/dotnet:2.1-sdk-alpine AS build +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build WORKDIR /app # copy csproj and restore as distinct layers @@ -17,7 +17,7 @@ WORKDIR /app/HomeAutio.Mqtt.Harmony RUN dotnet publish -o out # build runtime image -FROM microsoft/dotnet:2.1-runtime-alpine AS runtime +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS runtime WORKDIR /app COPY --from=publish /app/HomeAutio.Mqtt.Harmony/out ./ diff --git a/src/Dockerfile.arm32 b/src/Dockerfile.arm32 index 4aa89ff..651217f 100644 --- a/src/Dockerfile.arm32 +++ b/src/Dockerfile.arm32 @@ -1,4 +1,4 @@ -FROM microsoft/dotnet:2.1-sdk-alpine AS build +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build WORKDIR /app # copy csproj and restore as distinct layers @@ -17,7 +17,7 @@ WORKDIR /app/HomeAutio.Mqtt.Harmony RUN dotnet publish -o out # build runtime image -FROM microsoft/dotnet:2.1-aspnetcore-runtime-stretch-slim-arm32v7 AS runtime +FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim-arm32v7 AS runtime WORKDIR /app COPY --from=publish /app/HomeAutio.Mqtt.Harmony/out ./ diff --git a/src/HomeAutio.Mqtt.Harmony/HarmonyMqttService.cs b/src/HomeAutio.Mqtt.Harmony/HarmonyMqttService.cs index 6859db9..eb0c432 100644 --- a/src/HomeAutio.Mqtt.Harmony/HarmonyMqttService.cs +++ b/src/HomeAutio.Mqtt.Harmony/HarmonyMqttService.cs @@ -11,6 +11,7 @@ using HomeAutio.Mqtt.Core.Utilities; using Microsoft.Extensions.Logging; using MQTTnet; +using MQTTnet.Extensions.ManagedClient; using Newtonsoft.Json; namespace HomeAutio.Mqtt.Harmony @@ -20,18 +21,19 @@ namespace HomeAutio.Mqtt.Harmony /// public class HarmonyMqttService : ServiceBase { - private ILogger _log; - private bool _disposed = false; - - private IClient _client; - private string _harmonyName; - private int _harmonyKeyPressLength; - private HarmonyConfig _harmonyConfig; + private readonly ILogger _log; /// /// Holds mapping of possible MQTT topics mapped to Harmony command actions they trigger. /// - private IDictionary _topicActionMap; + private readonly IDictionary _topicActionMap; + + private readonly IClient _client; + private readonly string _harmonyName; + private readonly int _harmonyKeyPressLength; + private HarmonyConfig _harmonyConfig; + + private bool _disposed = false; /// /// Initializes a new instance of the class. @@ -75,7 +77,7 @@ public HarmonyMqttService( #region Service implementation /// - protected override async Task StartServiceAsync(CancellationToken cancellationToken = default(CancellationToken)) + protected override async Task StartServiceAsync(CancellationToken cancellationToken = default) { // Connect to Harmony _client.Connect(); @@ -84,7 +86,7 @@ await GetConfigAsync() } /// - protected override Task StopServiceAsync(CancellationToken cancellationToken = default(CancellationToken)) + protected override Task StopServiceAsync(CancellationToken cancellationToken = default) { return Task.CompletedTask; } @@ -96,9 +98,8 @@ await GetConfigAsync() /// /// Handles commands for the Harmony published to MQTT. /// - /// Event sender. /// Event args. - protected override async void Mqtt_MqttMsgPublishReceived(object sender, MqttApplicationMessageReceivedEventArgs e) + protected override async void Mqtt_MqttMsgPublishReceived(MqttApplicationMessageReceivedEventArgs e) { var message = e.ApplicationMessage.ConvertPayloadToString(); _log.LogInformation("MQTT message received for topic " + e.ApplicationMessage.Topic + ": " + message); diff --git a/src/HomeAutio.Mqtt.Harmony/HomeAutio.Mqtt.Harmony.csproj b/src/HomeAutio.Mqtt.Harmony/HomeAutio.Mqtt.Harmony.csproj index 187c3b4..babf376 100644 --- a/src/HomeAutio.Mqtt.Harmony/HomeAutio.Mqtt.Harmony.csproj +++ b/src/HomeAutio.Mqtt.Harmony/HomeAutio.Mqtt.Harmony.csproj @@ -2,7 +2,8 @@ Exe - netcoreapp2.1 + netcoreapp3.1 + latest https://github.com/i8beef/HomeAutio.Mqtt.Harmony https://github.com/i8beef/HomeAutio.Mqtt.Harmony/blob/master/LICENSE @@ -15,11 +16,11 @@ - bin\Debug\netcoreapp2.1\HomeAutio.Mqtt.Harmony.xml + bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml - bin\Release\netcoreapp2.1\HomeAutio.Mqtt.Harmony.xml + bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml @@ -32,12 +33,12 @@ all - - - - - - + + + + + + diff --git a/src/HomeAutio.Mqtt.Harmony/Program.cs b/src/HomeAutio.Mqtt.Harmony/Program.cs index 31dc8d2..146f913 100644 --- a/src/HomeAutio.Mqtt.Harmony/Program.cs +++ b/src/HomeAutio.Mqtt.Harmony/Program.cs @@ -20,18 +20,8 @@ public class Program /// /// Main program entry point. /// - /// Arguments. - public static void Main(string[] args) - { - MainAsync(args).GetAwaiter().GetResult(); - } - - /// - /// Main program entry point. - /// - /// Arguments. /// Awaitable . - public static async Task MainAsync(string[] args) + public static async Task Main() { var environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT"); if (string.IsNullOrEmpty(environmentName))