Skip to content

Commit

Permalink
Updated build config, dependencies, and moved to .NET core 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
i8beef committed Jun 24, 2020
1 parent 1098b96 commit 45cc408
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 36 deletions.
28 changes: 28 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ./

Expand Down
4 changes: 2 additions & 2 deletions src/Dockerfile.arm32
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 ./

Expand Down
25 changes: 13 additions & 12 deletions src/HomeAutio.Mqtt.Harmony/HarmonyMqttService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,18 +21,19 @@ namespace HomeAutio.Mqtt.Harmony
/// </summary>
public class HarmonyMqttService : ServiceBase
{
private ILogger<HarmonyMqttService> _log;
private bool _disposed = false;

private IClient _client;
private string _harmonyName;
private int _harmonyKeyPressLength;
private HarmonyConfig _harmonyConfig;
private readonly ILogger<HarmonyMqttService> _log;

/// <summary>
/// Holds mapping of possible MQTT topics mapped to Harmony command actions they trigger.
/// </summary>
private IDictionary<string, string> _topicActionMap;
private readonly IDictionary<string, string> _topicActionMap;

private readonly IClient _client;
private readonly string _harmonyName;
private readonly int _harmonyKeyPressLength;
private HarmonyConfig _harmonyConfig;

private bool _disposed = false;

/// <summary>
/// Initializes a new instance of the <see cref="HarmonyMqttService"/> class.
Expand Down Expand Up @@ -75,7 +77,7 @@ public HarmonyMqttService(
#region Service implementation

/// <inheritdoc />
protected override async Task StartServiceAsync(CancellationToken cancellationToken = default(CancellationToken))
protected override async Task StartServiceAsync(CancellationToken cancellationToken = default)
{
// Connect to Harmony
_client.Connect();
Expand All @@ -84,7 +86,7 @@ await GetConfigAsync()
}

/// <inheritdoc />
protected override Task StopServiceAsync(CancellationToken cancellationToken = default(CancellationToken))
protected override Task StopServiceAsync(CancellationToken cancellationToken = default)
{
return Task.CompletedTask;
}
Expand All @@ -96,9 +98,8 @@ await GetConfigAsync()
/// <summary>
/// Handles commands for the Harmony published to MQTT.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event args.</param>
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);
Expand Down
19 changes: 10 additions & 9 deletions src/HomeAutio.Mqtt.Harmony/HomeAutio.Mqtt.Harmony.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<PackageProjectUrl>https://github.com/i8beef/HomeAutio.Mqtt.Harmony</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/i8beef/HomeAutio.Mqtt.Harmony/blob/master/LICENSE</PackageLicenseUrl>
<Company></Company>
Expand All @@ -15,11 +16,11 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\netcoreapp2.1\HomeAutio.Mqtt.Harmony.xml</DocumentationFile>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netcoreapp2.1\HomeAutio.Mqtt.Harmony.xml</DocumentationFile>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand All @@ -32,12 +33,12 @@
<PackageReference Include="I8Beef.CodeAnalysis.RuleSet" Version="1.0.15">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="HarmonyHub" Version="3.0.0.10" />
<PackageReference Include="HomeAutio.Mqtt.Core" Version="3.0.0.51" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
<PackageReference Include="Serilog.Settings.Configuration" Version="2.6.1" />
<PackageReference Include="HarmonyHub" Version="3.0.0.12" />
<PackageReference Include="HomeAutio.Mqtt.Core" Version="3.0.0.57" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.5" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
</ItemGroup>
Expand Down
12 changes: 1 addition & 11 deletions src/HomeAutio.Mqtt.Harmony/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,8 @@ public class Program
/// <summary>
/// Main program entry point.
/// </summary>
/// <param name="args">Arguments.</param>
public static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();
}

/// <summary>
/// Main program entry point.
/// </summary>
/// <param name="args">Arguments.</param>
/// <returns>Awaitable <see cref="Task" />.</returns>
public static async Task MainAsync(string[] args)
public static async Task Main()
{
var environmentName = Environment.GetEnvironmentVariable("ENVIRONMENT");
if (string.IsNullOrEmpty(environmentName))
Expand Down

0 comments on commit 45cc408

Please sign in to comment.