public byte[] CreateReport(RepositoryItemMetadata item, RepositoryClientBase client) { // Get the DDI PhysicalInstance (dataset description) var dataset = client.GetItem(item.CompositeId, ChildReferenceProcessing.Instantiate) as PhysicalInstance; // Populate all its variable information. var populator = new GraphPopulator(client); dataset.Accept(populator); // Use the Colectica.Reporting MigraDoc helper to create a PDF that // simply lists all variables with their names, labels, and types. var document = new Document(); document.Info.Title = "Sample Variable Summary"; // Add a title. var section = document.AddSection(); var paragraph = section.AddParagraph(dataset.DublinCoreMetadata.Title.Best); paragraph.Format.Font.Bold = true; // Create the report helper. ReportContext context = new ReportContext(); var builder = new ItemBuilderBase(document, context); // Get all variables in the dataset. var allVariables = dataset .DataRelationships .SelectMany(x => x.LogicalRecords) .SelectMany(x => x.VariablesInRecord) .ToList(); // Make a list with one item for each variable. builder.DefineList(); foreach (var variable in allVariables) { string lineText = $"{variable.ItemName.Best} - {variable.Label.Best} - {variable.RepresentationType}"; builder.AddListItem(lineText); } // Render the PDF and return it. var pdfRenderer = new PdfDocumentRenderer(true); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); using (var stream = new MemoryStream()) { pdfRenderer.Save(stream, true); var fileContents = stream.ToArray(); return(fileContents); } }
public byte[] CreateReport(DublinCore citation, List <RepositoryItemMetadata> items, RepositoryClientBase client) { // Get identification for all the DDI variables in the item list. var variableIDs = items .Where(x => x.ItemType == DdiItemType.Variable) .Select(x => x.CompositeId) .ToIdentifierCollection(); // Fetch all the variables. var allVariables = client.GetItems(variableIDs) .OfType <Variable>(); // Use the Colectica.Reporting MigraDoc helper to create a PDF that // simply lists all variables with their names, labels, and types. var document = new Document(); document.Info.Title = "Sample Variable Summary"; // Add a title. var section = document.AddSection(); var paragraph = section.AddParagraph(citation.Title.Best); paragraph.Format.Font.Bold = true; // Create the report helper. ReportContext context = new ReportContext(); var builder = new ItemBuilderBase(document, context); // Make a list with one item for each variable. builder.DefineList(); foreach (var variable in allVariables) { string lineText = $"{variable.ItemName.Best} - {variable.Label.Best} - {variable.RepresentationType}"; builder.AddListItem(lineText); } // Render the PDF and return it. var pdfRenderer = new PdfDocumentRenderer(true); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); using (var stream = new MemoryStream()) { pdfRenderer.Save(stream, true); var fileContents = stream.ToArray(); return(fileContents); } }