public static ReportLayout ReadReportLayout(this PBIFile pbiFile) { var reportLayoutFile = pbiFile.ArchiveEntries .FirstOrDefault(x => x.FullName == PbiFileContents.ReportLayout); if (reportLayoutFile == null) { throw new ContentNotFoundException("Unable to read Report Layout content."); } var reader = new StreamReader(reportLayoutFile.Open(), Encoding.Unicode); var reportLayoutFileContent = reader.ReadToEnd(); if (reportLayoutFileContent == null) { throw new ContentEmptyException("Report Layout is empty"); } var options = new JsonDocumentOptions { AllowTrailingCommas = true }; var report = JsonDocument.Parse(reportLayoutFileContent, options); var reportLayout = new ReportLayout { Id = GetReportId(report.RootElement), ReportPages = GetPages(report.RootElement), Configuration = GetConfiguration(report.RootElement) }; return(reportLayout); }
private ReportLayout ExtractLayout() { File.Copy(this.originalFilePath, this.zipFilePath); ZipArchive zip = ZipFile.Open(zipFilePath, ZipArchiveMode.Read); ReportLayout layout = null; foreach (ZipArchiveEntry entry in zip.Entries) { if (entry.Name == "Layout") { using (StreamReader sr = new StreamReader(entry.Open(), Encoding.Unicode, true)) { string jsonText = sr.ReadToEnd(); layout = JsonConvert.DeserializeObject <ReportLayout>(jsonText); } break; } } zip.Dispose(); File.Delete(zipFilePath); return(layout); }
public void Extract() { ReportLayout layout = this.ExtractLayout(); List <XmlDocument> visualConfigsXml = this.ExtractVisualConfigs(layout); List <VisualConfig> visualConfigs = new List <VisualConfig>(); foreach (XmlDocument xmlDoc in visualConfigsXml) { VisualConfig config = this.GetVisualConfig(xmlDoc); visualConfigs.Add(config); } List <VisualConfig> uniqueVisualConfigs = visualConfigs.GroupBy(p => p.VisualTypeName).Select(g => g.First()).ToList(); if (visualConfigs.Count != uniqueVisualConfigs.Count) { MessageBox.Show("More visuals of the same type has been found. The program will extract one visual of every type in report.", "More visuals of the same type", MessageBoxButton.OK, MessageBoxImage.Warning); } string text = this.GetThemeText(uniqueVisualConfigs); File.WriteAllText(themePath, text); MessageBox.Show("Theme has been successfully extracted to: " + themePath, "Success", MessageBoxButton.OK, MessageBoxImage.Information); }
private List <XmlDocument> ExtractVisualConfigs(ReportLayout layout) { List <XmlDocument> configs = new List <XmlDocument>(); foreach (Sections section in layout.Sections) { foreach (VisualContainers container in section.VisualContainers) { XmlDocument doc = JsonConvert.DeserializeXmlNode(container.Config, "Root"); configs.Add(doc); } } return(configs); }
public ExcelMail(ReportLayout layout) { Layout = layout; }