private void ExportToXAML_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Select visualisation file"; openDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openDialog.FilterIndex = 0; Nullable<bool> result = openDialog.ShowDialog(); if (result == true) { string tempFileName = openDialog.FileName; //string tempFileName = @"C:\Users\Iman\Documents\Visual Studio 2012\Projects\CONVErT\CONVErT\Test\Working\HorBarchart.xml"; try { XAMLRenderer rend = new XAMLRenderer(); string rendResult = rend.renderToStillXAML(tempFileName); if (!String.IsNullOrEmpty(rendResult)) { //save the xaml file SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "Export to XAML file"; saveDialog.Filter = "XAML files (*.xaml)|*.xaml|All files (*.*)|*.*"; saveDialog.FileName = ""; saveDialog.ShowDialog(); if (!saveDialog.FileName.Equals("")) { //resulted visualisation model file string saveXamlFile = saveDialog.FileName; //where the reaulted reverse will be saved if (!saveXamlFile.ToLower().EndsWith(".xaml")) saveXamlFile += ".xaml"; //save string to file using (StreamWriter outfile = new StreamWriter(saveXamlFile)) { outfile.Write(rendResult); outfile.Close(); reportMessage("XAML file generated successfully", ReportIcon.OK); } } else reportMessage("Failed to save XAML file!", ReportIcon.Error); } else reportMessage("Rendered XAML returned empty!", ReportIcon.Error); } catch (Exception ex) { reportMessage("Exception in Visualiser.ExportToXAML -> " + ex.Message, ReportIcon.Error); } } }
private void ExportToHTML_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Select visualisation file"; openDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"; openDialog.FilterIndex = 0; Nullable<bool> result = openDialog.ShowDialog(); if (result == true) { string tempFileName = openDialog.FileName; try { XAMLRenderer rend = new XAMLRenderer(); string rendResult = rend.renderToStillXAML(tempFileName); if (!String.IsNullOrEmpty(rendResult)) { //save the xaml file SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Title = "Export to HTML file"; saveDialog.Filter = "HTML files (*.html)|*.html|All files (*.*)|*.*"; saveDialog.FileName = ""; saveDialog.ShowDialog(); if (!saveDialog.FileName.Equals("")) { string dialogFile = saveDialog.FileName; string saveHtmlFile = ""; //resulted visualisation html file string xamlFile = ""; //where the xaml to be viewed will be saved if (!dialogFile.ToLower().EndsWith(".xaml")) xamlFile = dialogFile + ".xaml"; else xamlFile = dialogFile; if (!dialogFile.ToLower().EndsWith(".html")) saveHtmlFile = dialogFile + ".html"; else saveHtmlFile = dialogFile; //save xaml string to file using (StreamWriter outfile = new StreamWriter(xamlFile)) { outfile.Write(rendResult); outfile.Close(); reportMessage("HTML files generated successfully", ReportIcon.OK); } string htmlResult = rend.renderToStillHTML(tempFileName, xamlFile); //save xaml string to file using (StreamWriter outfile = new StreamWriter(saveHtmlFile)) { outfile.Write(htmlResult); outfile.Close(); reportMessage("HTML files generated successfully", ReportIcon.OK); } //get } else reportMessage("Failed to save HTML file!", ReportIcon.Error); } else reportMessage("Rendered HTML returned empty!", ReportIcon.Error); } catch (Exception ex) { reportMessage("Exception in Visualiser.ExportToHTML -> " + ex.Message, ReportIcon.Error); } } }