private static async Task <string> ConvertHtmlToXamlRichTextBlock(string xhtml) { // Load XHTML fragment as XML document XmlDocument xhtmlDoc = new XmlDocument(); xhtmlDoc.LoadXml(xhtml); if (Html2XamlProcessor == null) { // Read XSLT. In design mode we cannot access the xslt from the file system (with Build Action = Content), // so we use it as an embedded resource instead: Assembly assembly = typeof(Properties).GetTypeInfo().Assembly; using (Stream stream = assembly.GetManifestResourceStream("WinRT_RichTextBlock.Html2Xaml.RichTextBlockHtml2Xaml.xslt")) { StreamReader reader = new StreamReader(stream); string content = await reader.ReadToEndAsync(); XmlDocument html2XamlXslDoc = new XmlDocument(); html2XamlXslDoc.LoadXml(content); Html2XamlProcessor = new XsltProcessor(html2XamlXslDoc); } } // Apply XSLT to XML string xaml = Html2XamlProcessor.TransformToString(xhtmlDoc.FirstChild); return(xaml); }
public MainBackgroundWorker(string templatesPath) { this.templatesPath = templatesPath; WorkerReportsProgress = true; // // Create the background workers. // this.validatorBackgroundWorker = new ValidatorBackgroundWorker(); this.validatorBackgroundWorker.WorkerReportsProgress = true; this.xsltProcessor = new XsltProcessor(); // // Assign methods to handle these events. // DoWork += HandleDoWork; this.validatorBackgroundWorker.ProgressChanged += ValidatorBackgroundWorkerHandleProgressChanged; this.validatorBackgroundWorker.RunWorkerCompleted += ValidatorBackgroundWorkerHandleRunWorkerCompleted; this.xsltProcessor.ProgressChanged += XsltProcessorHandleProgressChanged; this.xsltProcessor.ProcessingCompleted += XsltProcessorHandleRunWorkerCompleted; }
private static async Task <string> ConvertHtmlToXamlRichTextBlock(string xhtml) { // Load XHTML fragment as XML document try { XmlDocument xhtmlDoc = new XmlDocument(); xhtmlDoc.LoadXml(xhtml); if (html2XamlProcessor == null) { // Read XSLT. In design mode we cannot access the xslt from the file system (with Build Action = Content), // so we use it as an embedded resource instead: XmlDocument html2XamlXslDoc = new XmlDocument(); var xlstContent = await FileIO.ReadTextAsync(await Package.Current.InstalledLocation.GetFileAsync(@"UIHelpers\HTML2XamlRichText\RichTextBlockHtml2Xaml.xslt")); html2XamlXslDoc.LoadXml(xlstContent); html2XamlProcessor = new XsltProcessor(html2XamlXslDoc); } // Apply XSLT to XML string xaml = html2XamlProcessor.TransformToString(xhtmlDoc.FirstChild); return(xaml); } catch (Exception ex) { return(ex.Message); } }
public MainPage() { this.InitializeComponent(); var nunit = new Runner.App(); // If you want to add tests in another assembly, add a reference and // duplicate the following line with a type from the referenced assembly nunit.AddTestAssembly(typeof(AsyncTests).GetTypeInfo().Assembly); var resultsPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "Nunit", "Results.xml"); // Available options for testing nunit.Options = new TestOptions { // If True, the tests will run automatically when the app starts // otherwise you must run them manually. AutoRun = true, // If True, the application will terminate automatically after running the tests. //TerminateAfterExecution = true, // Information about the tcp listener host and port. // For now, send result as XML to the listening server. // NOTE: Your UWP App must have Private Networks capability enabled //TcpWriterParameters = new TcpWriterInfo("192.168.0.108", 13000), // Creates a NUnit Xml result file on the host file system using PCLStorage library. CreateXmlResultFile = true, // Choose a different path for the xml result file ResultFilePath = resultsPath, OnCompletedCallback = async() => { var resultFile = await StorageFile.GetFileFromPathAsync(resultsPath); var doc = await XmlDocument.LoadFromFileAsync(resultFile); var transformFile = Path.Combine(Package.Current.InstalledLocation.Path, "nunit3-junit.xslt"); var xslt = await StorageFile.GetFileFromPathAsync(transformFile); var xsltDoc = await XmlDocument.LoadFromFileAsync(xslt); var processor = new XsltProcessor(xsltDoc); var transformed = processor.TransformToDocument(doc.FirstChild); await transformed.SaveToFileAsync(resultFile); } }; LoadApplication(nunit); }
/// <summary> /// The transform_ on click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private async void Transform_OnClick(object sender, RoutedEventArgs e) { var xsltFile = await StorageFile.GetFileFromApplicationUriAsync(booksXslt); var xslt = await XmlDocument.LoadFromFileAsync(xsltFile); var processor = new XsltProcessor(xslt); var xmlFile = await StorageFile.GetFileFromApplicationUriAsync(booksUri); var xml = await XmlDocument.LoadFromFileAsync(xmlFile); TransformedText.Text = processor.TransformToString(xml.DocumentElement); }
private static async Task <string> ConvertHtmlToXamlRichTextBlock(string xhtml) { // Load XHTML fragment as XML document XmlDocument xhtmlDoc = new XmlDocument(); if (Windows.ApplicationModel.DesignMode.DesignModeEnabled) { // In design mode we swallow all exceptions to make editing more friendly try { xhtmlDoc.LoadXml(xhtml); } catch { } // For some reason code in catch is not executed when an exception occurs in design mode, so we can't display a friendly error here. } else { // When not in design mode, we let the application handle any exceptions xhtmlDoc.LoadXml(xhtml); } if (Html2XamlProcessor == null) { // Read XSLT. In design mode we cannot access the xslt from the file system (with Build Action = Content), // so we use it as an embedded resource instead: Assembly assembly = typeof(Properties).GetTypeInfo().Assembly; using ( Stream stream = assembly.GetManifestResourceStream("SocialMediaDashboard.W8.Common.RichTextBlockHtml2Xaml.xslt") ) { StreamReader reader = new StreamReader(stream); string content = await reader.ReadToEndAsync(); XmlDocument html2XamlXslDoc = new XmlDocument(); html2XamlXslDoc.LoadXml(content); Html2XamlProcessor = new XsltProcessor(html2XamlXslDoc); } } // Apply XSLT to XML string xaml = Html2XamlProcessor.TransformToString(xhtmlDoc.FirstChild); return(xaml); }
private static async Task <string> ConvertHtmlToXamlRichTextBlock(string xhtml) { // Load XHTML fragment as XML document XmlDocument xhtmlDoc = new XmlDocument(); xhtmlDoc.LoadXml(xhtml); if (Html2XamlProcessor == null) { var xsldocument = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///html2xaml/RichTextBlockHtml2Xaml.xslt")); XmlDocument html2Xamlxsldoc = await XmlDocument.LoadFromFileAsync(xsldocument); Html2XamlProcessor = new XsltProcessor(html2Xamlxsldoc); //I can't get this part to work, so we've gone back to Build Action Content // Read XSLT. In design mode we cannot access the xslt from the file system (with Build Action = Content), // so we use it as an embedded resource instead: /** * Assembly assembly = typeof(Properties).GetTypeInfo().Assembly; * using (Stream stream = assembly.GetManifestResourceStream("RichTextBlockHtml2Xaml.xslt")) * { * StreamReader reader = new StreamReader(stream); * string content = await reader.ReadToEndAsync(); * XmlDocument html2XamlXslDoc = new XmlDocument(); * html2XamlXslDoc.LoadXml(content); * Html2XamlProcessor = new XsltProcessor(html2XamlXslDoc); * }**/ } // Apply XSLT to XML string xaml = Html2XamlProcessor.TransformToString(xhtmlDoc.FirstChild); return(xaml); }