|
|
|
@ -12,6 +12,8 @@ using Windows.UI.Xaml.Data;
|
|
|
|
|
using Windows.UI.Xaml.Input; |
|
|
|
|
using Windows.UI.Xaml.Media; |
|
|
|
|
using Windows.UI.Xaml.Navigation; |
|
|
|
|
using AdaptiveCards.Rendering.Uwp; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
|
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 |
|
|
|
|
|
|
|
|
@ -22,9 +24,81 @@ namespace Adaptive_Card_Editor_UWP
|
|
|
|
|
/// </summary> |
|
|
|
|
public sealed partial class MainPage : Page |
|
|
|
|
{ |
|
|
|
|
public DispatcherTimer keyTimer = new DispatcherTimer(); |
|
|
|
|
|
|
|
|
|
public long lastKeyUp; |
|
|
|
|
|
|
|
|
|
public bool isRendered; |
|
|
|
|
|
|
|
|
|
public long interval = 5000000; |
|
|
|
|
|
|
|
|
|
public MainPage() |
|
|
|
|
{ |
|
|
|
|
TimerSetup(); |
|
|
|
|
this.InitializeComponent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void TimerSetup() |
|
|
|
|
{ |
|
|
|
|
keyTimer.Tick += TimerTick; |
|
|
|
|
// keyTimer.Interval = new TimeSpan(0, 0, 1); |
|
|
|
|
keyTimer.Interval = TimeSpan.Parse("00:00:00.05"); |
|
|
|
|
keyTimer.Start(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void txtInput_KeyUp(object sender, KeyRoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
// last key up event = integer value of current time |
|
|
|
|
lastKeyUp = DateTime.Now.Ticks; |
|
|
|
|
|
|
|
|
|
// user is inputting text, so we're going to rerender |
|
|
|
|
isRendered = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void TimerTick(object sender, object args) |
|
|
|
|
{ |
|
|
|
|
if (isRendered) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if (DateTime.Now.Ticks >= lastKeyUp + interval ) |
|
|
|
|
{ |
|
|
|
|
// we done got some input! let's render it. |
|
|
|
|
// we don't care what the input is; if it's not valid JSON ignore this keystroke |
|
|
|
|
|
|
|
|
|
// render the text as a plain textbox |
|
|
|
|
TextBlock txtOutput = new TextBlock(); |
|
|
|
|
txtOutput.TextWrapping = TextWrapping.Wrap; |
|
|
|
|
txtOutput.Padding = new Thickness(10); |
|
|
|
|
txtOutput.Text = txtInput.Text; |
|
|
|
|
|
|
|
|
|
// clear the grid of existing content |
|
|
|
|
grdCard.Children.Clear(); |
|
|
|
|
|
|
|
|
|
// render an adaptive card |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
AdaptiveCardRenderer cardRenderer = new AdaptiveCardRenderer(); |
|
|
|
|
AdaptiveCardParseResult parsedCard = AdaptiveCard.FromJsonString(txtInput.Text); |
|
|
|
|
RenderedAdaptiveCard theCard = cardRenderer.RenderAdaptiveCard(parsedCard.AdaptiveCard); |
|
|
|
|
grdCard.Children.Add(theCard.FrameworkElement); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
txtOutput.Text = ex.ToString(); |
|
|
|
|
grdCard.Children.Add(txtOutput); |
|
|
|
|
} |
|
|
|
|
grdCard.UpdateLayout(); |
|
|
|
|
|
|
|
|
|
isRendered = true; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|