/// <summary> /// Processes a positive scan result. /// </summary> private void ProcessResult(Result result) { if (_isDone) { // this is sometimes called once too many?? return; } string url = result.Text; if (url.StartsWith(CustomUrlPrefix)) { Messenger.Send(new EventLogRequest("QRCodeScanned", url.Replace(CustomUrlLogPrefix, ""))); LauncherEx.Launch(url); Close(); } else { WrongCodeMessage.Visibility = Visibility.Visible; } }
/// <summary> /// Converts an HTML node into an Inline. /// </summary> private static Inline ToInline(HtmlNode node) { switch (node.Name) { case "br": return(new LineBreak()); case "a": string text = node.InnerText; string url = node.GetAttributeValue("href", ""); if (string.IsNullOrWhiteSpace(text)) { text = url; } var link = new Hyperlink { Inlines = { new Run { Text = text, Foreground = new SolidColorBrush(Colors.Blue) } }, NavigateUri = new Uri(url, UriKind.Absolute), TargetName = "42" // can be anything, it just needs to be set }; link.Click += (_, __) => LauncherEx.Launch(url); return(new Span { Inlines = { new Run { Text = " " }, link, new Run { Text = " " }, } }); case "strong": case "b": var bold = new Bold(); foreach (var child in node.ChildNodes) { bold.Inlines.Add(ToInline(child)); } return(bold); case "em": case "i": var italic = new Italic(); foreach (var child in node.ChildNodes) { italic.Inlines.Add(ToInline(child)); } return(italic); case "ul": var unorderedList = new Span(); foreach (var child in node.ChildNodes) { var listElem = new Span(); listElem.Inlines.Add(new Run { Text = "● " }); listElem.Inlines.Add(ToInline(child)); unorderedList.Inlines.Add(listElem); unorderedList.Inlines.Add(new LineBreak()); } return(unorderedList); case "ol": var orderedList = new Span(); for (int n = 0; n < node.ChildNodes.Count; n++) { var listElem = new Span(); listElem.Inlines.Add(new Run { Text = n.ToString() + " " }); listElem.Inlines.Add(ToInline(node.ChildNodes[n])); orderedList.Inlines.Add(listElem); orderedList.Inlines.Add(new LineBreak()); } return(orderedList); case "h1": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.Bold, FontSize = 32 }); case "h2": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.SemiBold, FontSize = 24 }); case "h3": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.SemiBold, FontSize = 19 }); case "h4": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.Medium, FontSize = 17 }); case "h5": return(new Run { Text = node.InnerText + Environment.NewLine, FontWeight = FontWeights.Medium, FontSize = 16 }); case "div": case "p": case "blockquote": var container = new Span(); foreach (var child in node.ChildNodes) { container.Inlines.Add(ToInline(child)); } container.Inlines.Add(new LineBreak()); container.Inlines.Add(new LineBreak()); return(container); } return(new Run { Text = node.PreviousSibling == null?node.InnerText.TrimStart() : node.InnerText }); }
/// <summary> /// Navigates to the specified URL. /// </summary> public void NavigateTo(string url) { LauncherEx.Launch(url); }