Skip to content

Commit

Permalink
Upgrade to AdaptiveCards.Templating 2.0.0 (#13)
Browse files Browse the repository at this point in the history
* Upgrade to `AdaptiveCards.Templating` 2.0.1
  • Loading branch information
MaceWindu authored Jul 10, 2024
1 parent de5569b commit 460469f
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.vs/
obj/
bin/
.build/
*.pubxml
*.pubxml.user
*.csproj.user
Expand Down
3 changes: 3 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<ReportAnalyzer>true</ReportAnalyzer>

<GenerateDocumentationFile>true</GenerateDocumentationFile>

<ArtifactsPath>$(MSBuildThisFileDirectory).build</ArtifactsPath>
<ArtifactsPivots>$(Configuration)</ArtifactsPivots>
</PropertyGroup>

<ItemGroup Label="External Code Analyzers">
Expand Down
30 changes: 15 additions & 15 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project>
<ItemGroup>
<PackageVersion Include="Seq.Apps" Version="2023.4.0" />
<PackageVersion Include="AdaptiveCards.Templating" Version="1.5.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="PolySharp" Version="1.13.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="System.Text.Json" Version="7.0.3" />
<PackageVersion Include="Lindhart.Analyser.MissingAwaitWarning" Version="3.0.0-beta" />
<PackageVersion Include="NUnit.Analyzers" Version="3.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview.23472.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0-beta1.23472.1" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Seq.Apps" Version="2023.4.0" />
<PackageVersion Include="AdaptiveCards.Templating" Version="2.0.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="NUnit" Version="4.1.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="Lindhart.Analyser.MissingAwaitWarning" Version="3.1.0-beta" />
<PackageVersion Include="NUnit.Analyzers" Version="4.2.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0-preview.24318.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0-beta1.24318.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)

Copyright (c) 2016
Copyright (c) 2023 [email protected]
Copyright (c) 2024 [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 12 additions & 11 deletions ci/Seq.App.Teams.AdaptiveCard.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>Seq alerting application to send notifications to Microsoft Teams channels using AdaptiveCard templates.</description>
<summary />
<tags>teams seq adaptivecard seq-app</tags>
<copyright>Copyright &#169; 2023</copyright>
<copyright>Copyright &#169; 2024</copyright>
<authors>[email protected]</authors>
<owners>[email protected]</owners>
<license type="file">LICENSE.txt</license>
Expand All @@ -22,19 +22,20 @@
</metadata>

<files>
<file src="..\LICENSE.txt" />
<file src="..\README.md" />
<file src="../LICENSE.txt" />
<file src="../README.md" />
<file src="icon.png" />

<file src="..\src\Seq.App.Teams.AdaptiveCard\bin\Release\netstandard2.0\Seq.App.Teams.AdaptiveCard.pdb" target="lib\netstandard2.0\" />
<file src="..\src\Seq.App.Teams.AdaptiveCard\bin\Release\netstandard2.0\Seq.App.Teams.AdaptiveCard.xml" target="lib\netstandard2.0\" />
<file src="..\src\Seq.App.Teams.AdaptiveCard\bin\Release\netstandard2.0\Seq.App.Teams.AdaptiveCard.dll" target="lib\netstandard2.0\" />
<file src="../.build/bin/Seq.App.Teams.AdaptiveCard/Release/Seq.App.Teams.AdaptiveCard.pdb" target="lib/netstandard2.0/" />
<file src="../.build/bin/Seq.App.Teams.AdaptiveCard/Release/Seq.App.Teams.AdaptiveCard.xml" target="lib/netstandard2.0/" />
<file src="../.build/bin/Seq.App.Teams.AdaptiveCard/Release/Seq.App.Teams.AdaptiveCard.dll" target="lib/netstandard2.0/" />

<!--seq doesn't resolve nuget dependencies or does it incorrectly-->
<file src="..\src\Seq.App.Teams.AdaptiveCard\bin\Release\netstandard2.0\publish\AdaptiveCards.Templating.dll" target="lib\netstandard2.0\" />
<file src="..\src\Seq.App.Teams.AdaptiveCard\bin\Release\netstandard2.0\publish\AdaptiveExpressions.dll" target="lib\netstandard2.0\" />
<file src="..\src\Seq.App.Teams.AdaptiveCard\bin\Release\netstandard2.0\publish\Antlr4.Runtime.Standard.dll" target="lib\netstandard2.0\" />
<file src="..\src\Seq.App.Teams.AdaptiveCard\bin\Release\netstandard2.0\publish\Microsoft.Recognizers.Text.DataTypes.TimexExpression.dll" target="lib\netstandard2.0\" />
<!--seq doesn't resolve nuget dependencies (?)-->
<file src="../.build/publish/AdaptiveCards.Templating.dll" target="lib/netstandard2.0/" />
<file src="../.build/publish/Antlr4.Runtime.Standard.dll" target="lib/netstandard2.0/" />
<file src="../.build/publish/Microsoft.Bot.AdaptiveExpressions.Core.dll" target="lib/netstandard2.0/" />
<file src="../.build/publish/Microsoft.Recognizers.Text.DataTypes.TimexExpression.dll" target="lib/netstandard2.0/" />
<file src="../.build/publish/Json.More.dll" target="lib/netstandard2.0/" />

</files>
</package>
66 changes: 34 additions & 32 deletions ci/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ variables:
- name: build_configuration
value: Release
- name: assemblyVersion
value: 1.2.0
value: 2.0.0
- name: packageVersion
value: 1.2.0
value: 2.0.0
- name: nugetDevVersion
value: 1.2.1
value: 2.0.1

trigger:
- master
Expand All @@ -33,11 +33,6 @@ stages:
#########
# BUILD #
#########
- task: UseDotNet@2
displayName: 'Install .NET 8'
inputs:
includePreviewVersions: true
version: 8.x

- task: PowerShell@2
inputs:
Expand All @@ -59,29 +54,15 @@ stages:
projects: '$(Build.SourcesDirectory)/src/Seq.App.Teams.AdaptiveCard/Seq.App.Teams.AdaptiveCard.csproj'
publishWebProjects: false
zipAfterPublish: false
arguments: -f netstandard2.0 -c Release
arguments: -f netstandard2.0 -c Release -o $(Build.SourcesDirectory)/.build/publish
nobuild: true
modifyOutputPath: false
displayName: Publish project

########
# TEST #
########
################
# CREATE NUGET #
################

- script: dotnet test $(Build.SourcesDirectory)/$(solution) -c $(build_configuration) -l trx
displayName: 'Run Tests'
condition: succeededOrFailed()

- task: PublishTestResults@2
inputs:
testRunner: VsTest
testResultsFiles: '**/*.trx'
testRunTitle: 'Tests'
displayName: 'Publish test results'
condition: succeededOrFailed()

##########################
# CREATE / PUBLISH NUGET #
##########################
- powershell: echo "##vso[task.setvariable variable=packageVersion]$(nugetDevVersion)-rc.$(Build.BuildId)"
displayName: Update nuget version
condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'release'))
Expand All @@ -95,28 +76,49 @@ stages:

- task: CmdLine@2
inputs:
script: nuget pack $(Build.SourcesDirectory)/ci/Seq.App.Teams.AdaptiveCard.nuspec -OutputDirectory $(Build.SourcesDirectory)/built
script: nuget pack $(Build.SourcesDirectory)/ci/Seq.App.Teams.AdaptiveCard.nuspec -OutputDirectory $(Build.SourcesDirectory)/.build/nuget
workingDirectory: $(Build.SourcesDirectory)/ci
displayName: Build nuget for artifacts
condition: and(succeeded(), ne(variables['Build.SourceBranchName'], 'release'))

- task: CmdLine@2
inputs:
script: nuget pack $(Build.SourcesDirectory)/ci/Seq.App.Teams.AdaptiveCard.nuspec -OutputDirectory $(Build.SourcesDirectory)/built -Symbols -SymbolPackageFormat snupkg
script: nuget pack $(Build.SourcesDirectory)/ci/Seq.App.Teams.AdaptiveCard.nuspec -OutputDirectory $(Build.SourcesDirectory)/.build/nuget -Symbols -SymbolPackageFormat snupkg
workingDirectory: $(Build.SourcesDirectory)/ci
displayName: Build nuget for nuget.org
condition: and(succeeded(), eq(variables['Build.SourceBranchName'], 'release'))

- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.SourcesDirectory)/built'
pathToPublish: '$(Build.SourcesDirectory)/.build/nuget'
artifactName: 'nuget'
displayName: Publish nuget to artifacts

########
# TEST #
########

- script: dotnet test $(Build.SourcesDirectory)/$(solution) -c $(build_configuration) -l trx
displayName: 'Run Tests'
condition: succeededOrFailed()

- task: PublishTestResults@2
inputs:
testRunner: VsTest
testResultsFiles: '**/*.trx'
testRunTitle: 'Tests'
failTaskOnMissingResultsFile: true
displayName: 'Publish test results'
condition: succeededOrFailed()

#################
# PUBLISH NUGET #
#################

- task: NuGetCommand@2
inputs:
command: 'push'
packagesToPush: '$(Build.SourcesDirectory)/built/Seq.App.Teams.AdaptiveCard.*.nupkg'
packagesToPush: '$(Build.SourcesDirectory)/.build/nuget/Seq.App.Teams.AdaptiveCard.*.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'projects/projects'
displayName: Publish to Azure Artifacts feed
Expand All @@ -125,7 +127,7 @@ stages:
- task: NuGetCommand@2
inputs:
command: 'push'
packagesToPush: '$(Build.SourcesDirectory)/built/Seq.App.Teams.AdaptiveCard.*.nupkg'
packagesToPush: '$(Build.SourcesDirectory)/.build/nuget/Seq.App.Teams.AdaptiveCard.*.nupkg'
nuGetFeedType: 'external'
publishFeedCredentials: 'nuget.org'
displayName: Publish to Nuget.org
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>1.0.0</Version>
<Version>2.0.0</Version>

<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>CS1591</NoWarn>
Expand All @@ -14,12 +14,13 @@
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\default-template.json" />
<EmbeddedResource Include="Resources/default-template.json" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Seq.Apps" />
<PackageReference Include="AdaptiveCards.Templating" />
<PackageReference Include="Newtonsoft.Json" />

<PackageReference Include="PolySharp" />
<PackageReference Include="Microsoft.SourceLink.GitHub">
Expand Down
14 changes: 9 additions & 5 deletions src/Seq.App.Teams.AdaptiveCard/TeamsApp.CustomFunctions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Newtonsoft.Json;
using Microsoft.Bot.AdaptiveExpressions.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text.Json.Nodes;

namespace Seq.App.Teams;

Expand All @@ -13,7 +15,7 @@ public sealed partial class TeamsApp
public static void RegisterCustomFunctions()
{
// _nomd function escapes markdown control characters to disable markdown
AdaptiveExpressions.Expression.Functions.Add("_nomd", args =>
Expression.Functions.Add("_nomd", args =>
{
var input = args[0];

Expand All @@ -36,7 +38,7 @@ public static void RegisterCustomFunctions()
return input;
});

AdaptiveExpressions.Expression.Functions.Add("_jsonPrettify", args =>
Expression.Functions.Add("_jsonPrettify", args =>
{
using var sw = new StringWriter();

Expand All @@ -57,14 +59,16 @@ public static void RegisterCustomFunctions()
NullValueHandling = NullValueHandling.Ignore
};

serializer.Serialize(jtw, args[0]);
var data = args[0] is JsonNode n ? JsonConvert.DeserializeObject(n.ToJsonString()) : args[0];

serializer.Serialize(jtw, data);
}

sw.Flush();
return sw.ToString();
});

AdaptiveExpressions.Expression.Functions.Add("_colorUri", args =>
Expression.Functions.Add("_colorUri", args =>
{
if (args[0] is string colorString
&& colorString.Length == 6
Expand Down
9 changes: 5 additions & 4 deletions src/Seq.App.Teams.AdaptiveCard/TeamsApp.OnEvent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AdaptiveCards.Templating;
using Newtonsoft.Json;
using Seq.Apps;
using Seq.Apps.LogEvents;
using System;
Expand All @@ -8,6 +7,7 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace Seq.App.Teams;
Expand Down Expand Up @@ -82,13 +82,13 @@ public sealed partial class TeamsApp

if (TraceEnabled)
{
_log.Information("Template data: {json}", JsonConvert.SerializeObject(data));
_log.Information("Template data: {json}", JsonSerializer.Serialize(data));
}

return data;
}

private async Task SendCart(string card)
private async Task SendCard(string card)
{
using var client = new HttpClient(_httpClientHandler, disposeHandler: false)
{
Expand Down Expand Up @@ -132,6 +132,7 @@ async Task ISubscribeToAsync<LogEventData>.OnAsync(Event<LogEventData> evt)
}

var template = new AdaptiveCardTemplate(string.IsNullOrWhiteSpace(CardTemplate) ? _defaultTemplate : CardTemplate);

var bodyJson = template.Expand(BuildPayload(evt));

if (TraceEnabled)
Expand All @@ -145,7 +146,7 @@ async Task ISubscribeToAsync<LogEventData>.OnAsync(Event<LogEventData> evt)
_log.Warning("AdaptiveCard template warning: {Warning}", warn);
}

await SendCart(bodyJson).ConfigureAwait(false);
await SendCard(bodyJson).ConfigureAwait(false);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Seq.App.Teams.Tests;

public sealed class CustomFunctionsTests
internal sealed class CustomFunctionsTests
{
[TestCase(null, "\"${val}\"")]
[TestCase(123, "123")]
Expand Down Expand Up @@ -32,14 +32,14 @@ public void TestJsonFormatting()
var errors = cardTemplate.GetLastTemplateExpansionWarnings();

Assert.That(errors, Is.Empty);
Assert.That(result, Is.EqualTo(/*lang=json,strict*/ "{\"key\":\"{\\n\\n⠀⠀\\\"one\\\": 1,\\n\\n⠀⠀\\\"two\\\": \\\"two\\\",\\n\\n⠀⠀\\\"three\\\": null\\n\\n}\"}"));
Assert.That(result, Is.EqualTo(/*lang=json,strict*/ "{\"key\":\"{\\n\\n\\u2800\\u2800\\u0022one\\u0022: 1,\\n\\n\\u2800\\u2800\\u0022two\\u0022: \\u0022two\\u0022,\\n\\n\\u2800\\u2800\\u0022three\\u0022: null\\n\\n}\"}"));
Assert.DoesNotThrow(() => JsonDocument.Parse(result));
}

[TestCase("222222", "data:image/gif;base64,R0lGODlhAQABAIAAACIiIgAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==")]
[TestCase("921b3c", "data:image/gif;base64,R0lGODlhAQABAIAAAJIbPAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==")]
[TestCase("921B3C", "data:image/gif;base64,R0lGODlhAQABAIAAAJIbPAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==")]
[TestCase("ffb748", "data:image/gif;base64,R0lGODlhAQABAIAAAP+3SAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==")]
[TestCase("ffb748", "data:image/gif;base64,R0lGODlhAQABAIAAAP\\u002B3SAAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==")]
[TestCase("016DA9", "data:image/gif;base64,R0lGODlhAQABAIAAAAFtqQAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==")]
[TestCase("777777", "data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==")]
[TestCase(null, "")]
Expand Down
2 changes: 1 addition & 1 deletion tests/Seq.App.Teams.AdaptiveCard.Tests/Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[SetUpFixture]
#pragma warning disable CA1050 // Declare types in namespaces
public sealed class TestsInitialization
internal sealed class TestsInitialization
#pragma warning restore CA1050 // Declare types in namespaces
{
[OneTimeSetUp]
Expand Down
Loading

0 comments on commit 460469f

Please sign in to comment.