Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to .NET 5.0 #228

Merged
merged 10 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster
FROM mcr.microsoft.com/dotnet/sdk:5.0.100

# This Dockerfile adds a non-root 'vscode' user with sudo access. However, for Linux,
# this user's GID/UID must match your local user UID/GID to avoid permission issues
Expand All @@ -24,9 +24,6 @@ ARG INSTALL_AZURE_CLI="false"
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Stockholm

# Configure apt and install packages
RUN apt-get update \
&& apt-get -y install dialog git iproute2 procps 2>&1

# Switch back to dialog for any ad-hoc use of apt-get
ENV DEBIAN_FRONTEND=noninteractive
ENV TEST=AK
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"NETDAEMON__ADMIN": "${localEnv:NETDAEMON__ADMIN}",
"ASPNETCORE_URLS": "${localEnv:ASPNETCORE_URLS}"
},
"postCreateCommand": "dotnet restore && .devcontainer/install_prettyprompt.sh",
// "postCreateCommand": "dotnet restore && .devcontainer/install_prettyprompt.sh",
// Uncomment the next line if you want to publish or forward any ports.
"forwardPorts": [
5000
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

- uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.200' # SDK Version
dotnet-version: '5.0.100' # SDK Version

- name: Enable problem matchers
run: echo "::add-matcher::.github/matchers/dotnet.json"
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/push_docker_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ jobs:
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
# --platform linux/arm,linux/arm64,linux/amd64 \
- name: Run Buildx
run: |
docker buildx build \
--platform linux/arm,linux/arm64,linux/amd64 \
--platform linux/amd64 \
--output "type=image,push=true" \
--no-cache \
--file ./Dockerfile . \
--compress \
--tag netdaemon/netdaemon:dev
--tag netdaemon/netdaemon:dev_5
8 changes: 4 additions & 4 deletions .github/workflows/tags_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
- uses: actions/checkout@main
- name: Login to docker hub
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_TOKEN }}
- uses: olegtarasov/get-tag@v2
name: Set tag envronment variable
# - uses: olegtarasov/get-tag@v2
# name: Set tag envronment variable
- name: "Set version number"
run: |
sed -i '/ private const string Version = /c\ private const string Version = "${GIT_TAG_NAME}";' ${{github.workspace}}/src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
sed -i '/ private const string Version = /c\ private const string Version = "${GITHUB_REF#refs/tags/}";' ${{github.workspace}}/src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
- name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
Expand All @@ -32,4 +32,4 @@ jobs:
--file ./Dockerfile . \
--compress \
--tag netdaemon/netdaemon:latest \
--tag netdaemon/netdaemon:${GIT_TAG_NAME}
--tag netdaemon/netdaemon:${GITHUB_REF#refs/tags/}
14 changes: 7 additions & 7 deletions .github/workflows/tags_nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ jobs:
steps:
- uses: actions/checkout@main
- uses: actions/setup-dotnet@v1
- uses: olegtarasov/get-tag@v2
name: Set tag envronment variable
# - uses: olegtarasov/get-tag@v2
# name: Set tag envronment variable
- name: "Set version number"
run: |
sed -i '/ private const string Version = /c\ private const string Version = "${GIT_TAG_NAME}";' ${{github.workspace}}/src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
sed -i '/ private const string Version = /c\ private const string Version = "${GITHUB_REF#refs/tags/}";' ${{github.workspace}}/src/DaemonRunner/DaemonRunner/Service/RunnerService.cs
- name: pack DaemonRunner
run: dotnet pack src/DaemonRunner/DaemonRunner/DaemonRunner.csproj --configuration Release -p:PackageVersion=${GIT_TAG_NAME}-beta
run: dotnet pack src/DaemonRunner/DaemonRunner/DaemonRunner.csproj --configuration Release -p:PackageVersion=${GITHUB_REF#refs/tags/}-beta
- name: pack App
run: dotnet pack src/App/NetDaemon.App/NetDaemon.App.csproj --configuration Release -p:PackageVersion=${GIT_TAG_NAME}-beta
run: dotnet pack src/App/NetDaemon.App/NetDaemon.App.csproj --configuration Release -p:PackageVersion=${GITHUB_REF#refs/tags/}-beta
- name: pack Daemon
run: dotnet pack src/Daemon/NetDaemon.Daemon/NetDaemon.Daemon.csproj --configuration Release -p:PackageVersion=${GIT_TAG_NAME}-beta
run: dotnet pack src/Daemon/NetDaemon.Daemon/NetDaemon.Daemon.csproj --configuration Release -p:PackageVersion=${GITHUB_REF#refs/tags/}-beta
- name: pack Test
run: dotnet pack tests/NetDaemon.Test/NetDaemon.Test.csproj --configuration Release -p:PackageVersion=${GIT_TAG_NAME}-beta
run: dotnet pack tests/NetDaemon.Test/NetDaemon.Test.csproj --configuration Release -p:PackageVersion=${GITHUB_REF#refs/tags/}-beta
- name: push to nuget
run: dotnet nuget push **/*.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --no-symbols true
3 changes: 2 additions & 1 deletion .github/workflows/test_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ jobs:
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
# --platform linux/arm,linux/arm64,linux/amd64 \
- name: Run Buildx
run: |
docker buildx build \
--platform linux/arm,linux/arm64,linux/amd64 \
--platform linux/amd64 \
--output "type=image,push=false" \
--no-cache \
--file ./Dockerfile . \
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"preLaunchTask": "build",
"justMyCode": false,
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Service/bin/Debug/netcoreapp3.1/Service.dll",
"program": "${workspaceFolder}/src/Service/bin/Debug/net5.0/Service.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Service",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand Down
41 changes: 22 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
# Build the NetDaemon Admin with build container
FROM ludeeus/container:frontend as builder

RUN \
apk add make \
\
&& git clone https://github.com/net-daemon/admin.git /admin \
&& cd /admin \
&& git checkout tags/1.3.4 \
&& make deploy \
\
&& rm -fr /var/lib/apt/lists/* \
&& rm -fr /tmp/* /var/{cache,log}/* \
&& rm -R /admin/node_modules

# Build the NetDaemon with build container
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.302
FROM ludeeus/container:dotnet5-base-s6

# Copy the source to docker container
COPY ./src /usr/src

# COPY Docker/rootfs/etc /etc
COPY ./Docker/rootfs/etc /etc

# COPY admin
COPY --from=builder /admin /admin

# Install S6 and the Admin site
RUN wget -qO /s6 \
https://raw.githubusercontent.com/ludeeus/container/master/rootfs/s6/install \
&& bash /s6 \
\
&& wget -qO - https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
\
&& apt update && apt install -y \
RUN apt update && apt install -y \
nodejs \
yarn \
make \
\
&& git clone https://github.com/net-daemon/admin.git /admin \
&& cd /admin \
&& git checkout tags/1.3.4 \
&& make deploy \
\
&& rm -fr /var/lib/apt/lists/* \
&& rm -fr /tmp/* /var/{cache,log}/*
make

# Set default values of NetDaemon env
ENV \
Expand All @@ -42,4 +45,4 @@ ENV \
ASPNETCORE_URLS=http://+:5000


ENTRYPOINT ["/init"]
ENTRYPOINT ["/init"]
4 changes: 2 additions & 2 deletions src/App/NetDaemon.App/Common/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public static dynamic ToDynamic(this (string name, object val)[] attributeNameVa
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static ExpandoObject ToExpandoObject(this object obj)
public static ExpandoObject? ToExpandoObject(this object obj)
{
// Null-check

IDictionary<string, object> expando = new ExpandoObject();
IDictionary<string, object?> expando = new ExpandoObject();

foreach (PropertyDescriptor? property in TypeDescriptor.GetProperties(obj.GetType()))
{
Expand Down
26 changes: 20 additions & 6 deletions src/App/NetDaemon.App/Common/Fluent/FluentExpandoObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text.Json;
using JoySoftware.HomeAssistant.Client;

namespace NetDaemon.Common.Fluent
{
Expand Down Expand Up @@ -125,7 +127,7 @@ public object this[string key]
public ICollection<object> Values => ((IDictionary<string, object>)_dict).Values;

/// <inheritdoc/>
public override bool TrySetMember(SetMemberBinder binder, object value)
public override bool TrySetMember(SetMemberBinder binder, object? value)
{
UpdateDictionary(binder.Name, value);
if (_daemonApp != null)
Expand All @@ -137,7 +139,7 @@ public override bool TrySetMember(SetMemberBinder binder, object value)
}

/// <inheritdoc/>
public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object? value)
{
if (!(indexes[0] is string)) return base.TrySetIndex(binder, indexes, value);

Expand All @@ -146,7 +148,7 @@ public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object
}

/// <inheritdoc/>
public override bool TryGetMember(GetMemberBinder binder, out object result)
public override bool TryGetMember(GetMemberBinder binder, out object? result)
{
var key = NormalizePropertyName(binder.Name);

Expand Down Expand Up @@ -182,14 +184,25 @@ public dynamic Augment(FluentExpandoObject obj)
/// Copy all items from FluentExpandoObject
/// </summary>
/// <param name="obj">The object to copy from</param>
public dynamic CopyFrom(IDictionary<string, object> obj)
public dynamic CopyFrom(IDictionary<string, object?> obj)
{
// Clear any items before copy
Clear();

foreach (var keyValuePair in obj)
{
UpdateDictionary(keyValuePair.Key, keyValuePair.Value);
if (keyValuePair.Value is JsonElement val)
{
var dynValue = val.ToDynamicValue();
if (dynValue is object)
{
UpdateDictionary(keyValuePair.Key, dynValue);
}
}
else
{
UpdateDictionary(keyValuePair.Key, keyValuePair.Value);
}
}

return this;
Expand Down Expand Up @@ -235,8 +248,9 @@ public override string ToString()
return string.Join(", ", _dict.Select(pair => pair.Key + " = " + pair.Value ?? "(null)").ToArray());
}

private void UpdateDictionary(string name, object value)
private void UpdateDictionary(string name, object? value)
{
_ = value ?? throw new ArgumentNullException("value", "value cannot be null");
var key = NormalizePropertyName(name);
if (_dict.ContainsKey(key))
_dict[key] = value;
Expand Down
2 changes: 1 addition & 1 deletion src/App/NetDaemon.App/Common/NetDaemonAppBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public async Task RestoreAppStateAsync()
{
_ = _daemon as INetDaemon ?? throw new NullReferenceException($"{nameof(_daemon)} cant be null!");

var obj = await _daemon!.GetDataAsync<IDictionary<string, object>>(GetUniqueIdForStorage()).ConfigureAwait(false);
var obj = await _daemon!.GetDataAsync<IDictionary<string, object?>>(GetUniqueIdForStorage()).ConfigureAwait(false);

if (obj != null)
{
Expand Down
3 changes: 2 additions & 1 deletion src/App/NetDaemon.App/Common/Reactive/AppDaemonRxApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public abstract class NetDaemonRxApp : NetDaemonAppBase, INetDaemonReactive
_reactiveState ?? throw new ApplicationException("Application not initialized correctly (StateAllChanges>");

/// <inheritdoc/>
public IObservable<(EntityState Old, EntityState New)> StateChanges => _reactiveState.Where(e => e.New?.State != e.Old?.State);
public IObservable<(EntityState Old, EntityState New)> StateChanges =>
_reactiveState?.Where(e => e.New?.State != e.Old?.State) ?? throw new ApplicationException("Application not initialized correctly (StateAllChanges>");

/// <summary>
/// Returns the observables states implementation of AppDaemonRxApps
Expand Down
13 changes: 8 additions & 5 deletions src/App/NetDaemon.App/Common/Reactive/RxEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ internal static string GetDomainFromEntity(string entity)
/// </summary>
/// <param name="service">Name of the service to call</param>
/// <param name="data">Data to provide</param>
public void CallService(string service, dynamic? data = null)
public void CallService(string service, dynamic? data = null)
{
if (EntityIds is null || EntityIds is object && EntityIds.Count() == 0)
return;

foreach (var entityId in EntityIds!)
{
var serviceData = new FluentExpandoObject();
Expand All @@ -149,12 +149,15 @@ public void CallService(string service, dynamic? data = null)
{
// Maske sure we make a copy since we reuse all info but entity id
serviceData.CopyFrom(data);
}
}
else if (data is object)
{
// It is initialized with anonmous type new {transitio=10} for example
// It is initialized with anonmous type new {transition=10} for example
var expObject = ((object)data).ToExpandoObject();
serviceData.CopyFrom(expObject);
if (expObject is object)
{
serviceData.CopyFrom(expObject);
}
}

var domain = GetDomainFromEntity(entityId);
Expand Down
60 changes: 30 additions & 30 deletions src/App/NetDaemon.App/NetDaemon.App.csproj
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<RootNamespace>NetDaemon</RootNamespace>
<PackageId>JoySoftware.NetDaemon.App</PackageId>
<Version>0.1.29-alpha</Version>
<Authors>helto4real</Authors>
<Company>JoySoftware</Company>
<description>A .net core appdaemon for Home Assistant</description>
<projectUrl>https://github.com/helto4real/net-hassclient</projectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageDescription>
A application daemon for writing automations for the free open source home automations software Home Assisstant written in .net core 3.
Please see https://github.com/helto4real/netdaemon/blob/main/README.md for docs.
</PackageDescription>
<PackageReleaseNotes>First alpha version, expect things to change!</PackageReleaseNotes>
<tags>Home Assistant</tags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JoySoftware.HassClient" Version="0.7.0-beta" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.9" />
<PackageReference Include="System.Reactive" Version="4.4.1" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<RootNamespace>NetDaemon</RootNamespace>
<PackageId>JoySoftware.NetDaemon.App</PackageId>
<Version>0.1.29-alpha</Version>
<Authors>helto4real</Authors>
<Company>JoySoftware</Company>
<description>A .net core appdaemon for Home Assistant</description>
<projectUrl>https://github.com/helto4real/net-hassclient</projectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageDescription>
A application daemon for writing automations for the free open source home automations software Home Assisstant written in .net core 3.
Please see https://github.com/helto4real/netdaemon/blob/main/README.md for docs.
</PackageDescription>
<PackageReleaseNotes>First alpha version, expect things to change!</PackageReleaseNotes>
<tags>Home Assistant</tags>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JoySoftware.HassClient" Version="20.49.0-beta" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="System.Reactive" Version="5.0.0" />
</ItemGroup>

</Project>
Loading