Repository navigation
[.NET] Port WPF renderer to work for .NETCore3.0 #3156
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
23c016d
Add .net core project
almedina-ms 1239d01
Remove generated images
almedina-ms 948d360
Merge branch 'master' into user/almedina-ms/NETCore
dce07f8
Merge branch 'master' into user/almedina-ms/NETCore
almedina-ms c74d9a3
Add reference for handling fonts
almedina-ms 407b246
Merge branch 'master' into user/almedina-ms/NETCore
e37bbf8
Add global.json
almedina-ms ffd0115
Merge branch 'user/almedina-ms/NETCore' of https://github.com/Microso…
almedina-ms e0e938a
Update global.json
almedina-ms 3ca791f
Change globals location
almedina-ms d909fba
Go back in time to use a previous 3.0 version
almedina-ms 36ccde4
Change global.json version
almedina-ms 33d836e
Merge branch 'master' into user/almedina-ms/NETCore
almedina-ms cbeb3c9
Retry v 3.0.100
almedina-ms 4f8e3fa
Go gack in version before contacting support
almedina-ms 3d6007f
Change version to last for 16.2
almedina-ms 76771fe
Fix version
almedina-ms 0a27d94
Try to fix test file
almedina-ms 456ee6a
Try to not add extra file
almedina-ms 9d36a8e
Revert "Try to not add extra file"
almedina-ms 352d961
Merge branch 'master' into user/almedina-ms/NETCore
almedina-ms b076776
Merge branch 'master' into user/almedina-ms/NETCore
almedina-ms 78d44bb
Fix tabs
almedina-ms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...e/dotnet/Library/AdaptiveCards.Rendering.Wpf.Core/AdaptiveCards.Rendering.Wpf.Core.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <TargetFramework>netcoreapp3.0</TargetFramework> | ||
| <UseWPF>true</UseWPF> | ||
|
|
||
| <GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
| <AssemblyName>AdaptiveCards.Rendering.Wpf.Core</AssemblyName> | ||
| <RootNamespace>AdaptiveCards.Rendering.Wpf</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\AdaptiveCards\AdaptiveCards.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="..\AdaptiveCards.Rendering.Wpf\**\*.cs" Exclude="..\AdaptiveCards.Rendering.Wpf\obj\**" /> | ||
| <None Include="..\AdaptiveCards.Rendering.Wpf\**\*.settings" /> | ||
| <EmbeddedResource Include="..\AdaptiveCards.Rendering.Wpf\**\*.resx" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.MarkedNet" Version="1.0.13" /> | ||
| <PackageReference Include="System.Drawing.Common" Version="4.6.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Page Include="..\AdaptiveCards.Rendering.Wpf\Themes\generic.xaml"> | ||
| <Generator>MSBuild:Compile</Generator> | ||
| </Page> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...amples/AdaptiveCards.Core.Sample.ImageRender/AdaptiveCards.Core.Sample.ImageRender.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp3.0</TargetFramework> | ||
| <StartupObject></StartupObject> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
| <PlatformTarget>x86</PlatformTarget> | ||
| <AllowUnsafeBlocks>false</AllowUnsafeBlocks> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\Library\AdaptiveCards.Rendering.Wpf.Core\AdaptiveCards.Rendering.Wpf.Core.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
138 changes: 138 additions & 0 deletions
138
source/dotnet/Samples/AdaptiveCards.Core.Sample.ImageRender/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using AdaptiveCards.Rendering; | ||
| using AdaptiveCards.Rendering.Wpf; | ||
| using Microsoft.Extensions.CommandLineUtils; | ||
|
|
||
| namespace AdaptiveCards.Core.Sample.ImageRender | ||
| { | ||
| class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| var app = new CommandLineApplication(); | ||
|
|
||
| app.HelpOption("-h|--help"); | ||
|
|
||
| var pathArg = app.Argument("path", "The path that contains JSON card payloads"); | ||
| var optionRecurse = app.Option("-r|--recursive", "Recurse the directory for all JSON files", CommandOptionType.NoValue); | ||
| var optionOutput = app.Option("-o|--out", "The directory to output the image(s) to", CommandOptionType.SingleValue); | ||
| var optionSupportsInteracitivty = app.Option("-i|--supports-interactivity", "Include actions and inputs in the output", CommandOptionType.NoValue); | ||
| var hostConfigOption = app.Option("--host-config", "Specify a host config file", CommandOptionType.SingleValue); | ||
|
|
||
| app.OnExecute(() => | ||
| { | ||
| var outPath = optionOutput.HasValue() | ||
| ? optionOutput.Value() | ||
| : Environment.CurrentDirectory; | ||
|
|
||
| if (!Directory.Exists(outPath)) | ||
| Directory.CreateDirectory(outPath); | ||
|
|
||
| // Get payload search path | ||
| var payloadPath = pathArg.Value ?? "..\\..\\..\\..\\samples\\v1.0\\Scenarios"; | ||
| if (pathArg.Value == null) | ||
| { | ||
| Console.WriteLine($"No path argument specified, trying {payloadPath}..."); | ||
| } | ||
|
|
||
| var files = new List<string>(); | ||
|
|
||
| if (File.Exists(payloadPath)) | ||
| { | ||
| files.Add(payloadPath); | ||
| } | ||
| else if (Directory.Exists(payloadPath)) | ||
| { | ||
| var recurse = optionRecurse.HasValue() | ||
| ? SearchOption.AllDirectories | ||
| : SearchOption.TopDirectoryOnly; | ||
|
|
||
| files = Directory.GetFiles(payloadPath, "*.json", recurse).ToList(); | ||
| Console.WriteLine($"Found {files.Count} card payloads..."); | ||
| } | ||
| else | ||
| { | ||
| Console.WriteLine($"{payloadPath} does not contain any JSON files. Nothing to do."); | ||
| return 1; | ||
| } | ||
|
|
||
| AdaptiveHostConfig hostConfig = new AdaptiveHostConfig() | ||
| { | ||
| SupportsInteractivity = optionSupportsInteracitivty.HasValue() | ||
| }; | ||
|
|
||
|
|
||
| if (hostConfigOption.HasValue()) | ||
| { | ||
| hostConfig = AdaptiveHostConfig.FromJson(File.ReadAllText(hostConfigOption.Value())); | ||
| } | ||
|
|
||
| AdaptiveCardRenderer renderer = new AdaptiveCardRenderer(hostConfig); | ||
|
|
||
| foreach (var file in files) | ||
| { | ||
| RenderCard(file, renderer, outPath).Wait(); | ||
| } | ||
|
|
||
| Console.WriteLine($"All cards were written to {Path.GetFullPath(outPath)}"); | ||
| return 0; | ||
| }); | ||
|
|
||
| app.Execute(args); | ||
|
|
||
|
|
||
| // if output, launch the file | ||
| if (Debugger.IsAttached) | ||
| { | ||
| Console.ReadLine(); | ||
| } | ||
| } | ||
|
|
||
| private static async Task RenderCard(string file, AdaptiveCardRenderer renderer, string outPath) | ||
| { | ||
| try | ||
| { | ||
| var watch = new Stopwatch(); | ||
| watch.Start(); | ||
|
|
||
| AdaptiveCardParseResult parseResult = AdaptiveCard.FromJson(File.ReadAllText(file, Encoding.UTF8)); | ||
| AdaptiveCard card = parseResult.Card; | ||
|
|
||
| // Timeout after 30 seconds | ||
| var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); | ||
|
|
||
| // Render the card to an image | ||
| RenderedAdaptiveCardImage renderedCard = await renderer.RenderCardToImageAsync(card, true, 400, cts.Token); | ||
|
|
||
| // Report any warnings | ||
| foreach (var warning in parseResult.Warnings.Union(renderedCard.Warnings)) | ||
| { | ||
| Console.WriteLine($"[{Path.GetFileName(file)}] WARNING: {warning.Message}"); | ||
| } | ||
|
|
||
| // Write to a png file with the same name as the json file | ||
| var outputFile = Path.Combine(outPath, | ||
| Path.ChangeExtension(Path.GetFileName(file), ".png")); | ||
|
|
||
| using (var fileStream = new FileStream(outputFile, FileMode.Create)) | ||
| { | ||
| renderedCard.ImageStream.CopyTo(fileStream); | ||
| Console.WriteLine($"[{watch.ElapsedMilliseconds}ms T{Thread.CurrentThread.ManagedThreadId}]\t{Path.GetFileName(file)} => {Path.GetFileName(outputFile)}"); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.Error.WriteLine($"[FAILED]\t{Path.GetFileName(file)} => {ex.Message}"); | ||
| } | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
source/dotnet/Samples/AdaptiveCards.Core.Sample.ImageRender/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "profiles": { | ||
| "AdaptiveCards.Core.Sample.ImageRender": { | ||
| "commandName": "Project", | ||
| "commandLineArgs": "..\\..\\..\\..\\..\\..\\..\\samples\\v1.0\\Scenarios -r -i -o ./out --host-config ..\\..\\..\\..\\..\\..\\..\\samples\\HostConfig\\windows-notification.json" | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're not ready to support VS2019 at this time :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this page we should use .net core 3.0 with the latest preview of Visual Studio, I could try Visual Studio 17 to check if it works too there
https://dotnet.microsoft.com/download/dotnet-core/3.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But according to this one we must use 2019
https://docs.microsoft.com/en-us/dotnet/core/windows-prerequisites?tabs=netcore2x
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Paul Campbell (@paulcam206), almedina-ms what happened around this one? Are we ready to roll up to VS 2019? Let's try to close on this one!