Browse Source

updated rendering code to only run if text field is non-empty

master
Claire 4 years ago
parent
commit
0690513c22
  1. 4
      Adaptive Card Editor UWP.sln
  2. 11
      Adaptive Card Editor UWP/Adaptive Card Editor UWP.csproj
  3. 83
      Adaptive Card Editor UWP/MainPage.xaml.cs

4
Adaptive Card Editor UWP.sln

@ -21,7 +21,9 @@ Global
Release|x86 = Release|x86 Release|x86 = Release|x86
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|Any CPU.ActiveCfg = Debug|x86 {E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|Any CPU.ActiveCfg = Debug|x64
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|Any CPU.Build.0 = Debug|x64
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|Any CPU.Deploy.0 = Debug|x64
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|ARM.ActiveCfg = Debug|ARM {E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|ARM.ActiveCfg = Debug|ARM
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|ARM.Build.0 = Debug|ARM {E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|ARM.Build.0 = Debug|ARM
{E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|ARM.Deploy.0 = Debug|ARM {E2F5AF78-D3E6-43F9-AF44-F342449B63A5}.Debug|ARM.Deploy.0 = Debug|ARM

11
Adaptive Card Editor UWP/Adaptive Card Editor UWP.csproj

@ -12,7 +12,7 @@
<DefaultLanguage>en-US</DefaultLanguage> <DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier> <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion> <TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion> <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion> <MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
@ -99,6 +99,7 @@
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
<UseDotNetNativeToolchain>false</UseDotNetNativeToolchain>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath> <OutputPath>bin\x64\Release\</OutputPath>
@ -216,6 +217,14 @@
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' "> <PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion> <VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputPath>bin\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
<OutputPath>bin\Release\</OutputPath>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

83
Adaptive Card Editor UWP/MainPage.xaml.cs

@ -142,50 +142,57 @@ namespace Adaptive_Card_Editor_UWP
// clear the grid of existing content // clear the grid of existing content
grdCard.Children.Clear(); grdCard.Children.Clear();
grdTemplated.Children.Clear();
// render an adaptive card // render the adaptive card content
try if (txtInput.Text.Length > 0)
{ {
AdaptiveCardRenderer cardRenderer = new AdaptiveCardRenderer(); // render an adaptive card
AdaptiveCardParseResult parsedCard = AdaptiveCard.FromJsonString(txtInput.Text); try
RenderedAdaptiveCard theCard = cardRenderer.RenderAdaptiveCard(parsedCard.AdaptiveCard); {
grdCard.Children.Add(theCard.FrameworkElement); AdaptiveCardRenderer cardRenderer = new AdaptiveCardRenderer();
} AdaptiveCardParseResult parsedCard = AdaptiveCard.FromJsonString(txtInput.Text);
catch (Exception ex) RenderedAdaptiveCard theCard = cardRenderer.RenderAdaptiveCard(parsedCard.AdaptiveCard);
{ grdCard.Children.Add(theCard.FrameworkElement);
// this means bad data was ingested by the adaptive card renderer }
// so just display the exception details catch (Exception ex)
cardOutput.Text = ex.ToString(); {
grdCard.Children.Add(cardOutput); // this means bad data was ingested by the adaptive card renderer
} // so just display the exception details
cardOutput.Text = ex.ToString();
grdCard.Children.Add(cardOutput);
}
// render a card using template and data // render a card using template and data
try try
{ {
string template = txtInput.Text; string template = txtInput.Text;
string data = txtData.Text; string data = txtData.Text;
string rendered = JsonFromTemplate(template, data); string rendered = JsonFromTemplate(template, data);
// render the card from the rendered template + data // render the card from the rendered template + data
AdaptiveCardRenderer cardRenderer = new AdaptiveCardRenderer(); AdaptiveCardRenderer cardRenderer = new AdaptiveCardRenderer();
AdaptiveCardParseResult parsedCard = AdaptiveCard.FromJsonString(rendered); AdaptiveCardParseResult parsedCard = AdaptiveCard.FromJsonString(rendered);
RenderedAdaptiveCard theCard = cardRenderer.RenderAdaptiveCard(parsedCard.AdaptiveCard); RenderedAdaptiveCard theCard = cardRenderer.RenderAdaptiveCard(parsedCard.AdaptiveCard);
grdTemplated.Children.Add(theCard.FrameworkElement); grdTemplated.Children.Add(theCard.FrameworkElement);
} }
catch (Exception ex) catch (Exception ex)
{ {
// render the text as a plain textbox // render the text as a plain textbox
TextBlock templateOutput = new TextBlock(); TextBlock templateOutput = new TextBlock();
templateOutput.TextWrapping = TextWrapping.Wrap; templateOutput.TextWrapping = TextWrapping.Wrap;
templateOutput.Padding = new Thickness(10); templateOutput.Padding = new Thickness(10);
templateOutput.Text = txtInput.Text; templateOutput.Text = txtInput.Text;
// this means bad data was ingested by the adaptive card renderer // this means bad data was ingested by the adaptive card renderer
// so just display the exception details // so just display the exception details
templateOutput.Text = ex.ToString(); templateOutput.Text = ex.ToString();
grdTemplated.Children.Add(templateOutput); grdTemplated.Children.Add(templateOutput);
}
} }
// update the XAML layout
grdCard.UpdateLayout(); grdCard.UpdateLayout();
isRendered = true; isRendered = true;

Loading…
Cancel
Save