/// <summary>
        ///  A helper function that generates the report with reportTitle from the SrmDocument.
        ///  Throws an error if the reportSpec no longer exists in Settings.Default.
        /// </summary>
        /// <param name="doc">Document to create the report from.</param>
        /// <param name="reportTitle">Title of the reportSpec to make a report from.</param>
        /// <param name="toolTitle">Title of tool for exception error message.</param>
        /// <param name="progressMonitor">Progress monitor.</param>
        /// <returns> Returns a string representation of the ReportTitle report, or throws an error that the reportSpec no longer exist. </returns>
        public static string GetReport(SrmDocument doc, string reportTitle, string toolTitle, IProgressMonitor progressMonitor)
        {
            var container = new MemoryDocumentContainer();

            container.SetDocument(doc, container.Document);
            var      dataSchema  = new SkylineDataSchema(container, DataSchemaLocalizer.INVARIANT);
            var      viewContext = new DocumentGridViewContext(dataSchema);
            ViewInfo viewInfo    = viewContext.GetViewInfo(PersistedViews.ExternalToolsGroup.Id.ViewName(reportTitle));

            if (null == viewInfo)
            {
                throw new ToolExecutionException(
                          string.Format(
                              Resources.ToolDescriptionHelpers_GetReport_Error_0_requires_a_report_titled_1_which_no_longer_exists__Please_select_a_new_report_or_import_the_report_format,
                              toolTitle, reportTitle));
            }
            var status =
                new ProgressStatus(string.Format(Resources.ReportSpec_ReportToCsvString_Exporting__0__report,
                                                 reportTitle));
            var writer = new StringWriter();

            if (viewContext.Export(progressMonitor, ref status, viewInfo, writer,
                                   new DsvWriter(CultureInfo.InvariantCulture, TextUtil.SEPARATOR_CSV)))
            {
                return(writer.ToString());
            }
            return(null);
        }
Exemple #2
0
        /// <summary>
        ///  A helper function that generates the report with reportTitle from the SrmDocument.
        ///  Throws an error if the reportSpec no longer exists in Settings.Default.
        /// </summary>
        /// <param name="doc">Document to create the report from.</param>
        /// <param name="reportTitle">Title of the reportSpec to make a report from.</param>
        /// <param name="toolTitle">Title of tool for exception error message.</param>
        /// <param name="progressMonitor">Progress monitor.</param>
        /// <param name="writer">TextWriter that the report should be written to.</param>
        /// <returns> Returns a string representation of the ReportTitle report, or throws an error that the reportSpec no longer exist. </returns>
        public static void GetReport(SrmDocument doc, string reportTitle, string toolTitle, IProgressMonitor progressMonitor, TextWriter writer)
        {
            var container = new MemoryDocumentContainer();

            container.SetDocument(doc, container.Document);
            var      dataSchema  = new SkylineDataSchema(container, DataSchemaLocalizer.INVARIANT);
            var      viewContext = new DocumentGridViewContext(dataSchema);
            ViewInfo viewInfo    = viewContext.GetViewInfo(PersistedViews.ExternalToolsGroup.Id.ViewName(reportTitle));

            if (null == viewInfo)
            {
                throw new ToolExecutionException(
                          string.Format(
                              Resources.ToolDescriptionHelpers_GetReport_Error_0_requires_a_report_titled_1_which_no_longer_exists__Please_select_a_new_report_or_import_the_report_format,
                              toolTitle, reportTitle));
            }
            IProgressStatus status =
                new ProgressStatus(string.Format(Resources.ReportSpec_ReportToCsvString_Exporting__0__report,
                                                 reportTitle));

            progressMonitor.UpdateProgress(status);
            if (!viewContext.Export(CancellationToken.None, progressMonitor, ref status, viewInfo, writer,
                                    viewContext.GetCsvWriter()))
            {
                throw new OperationCanceledException();
            }
        }
Exemple #3
0
        public static void ReportToCsv(ReportSpec reportSpec, SrmDocument doc, string fileName, CultureInfo cultureInfo)
        {
            var documentContainer = new MemoryDocumentContainer();

            Assert.IsTrue(documentContainer.SetDocument(doc, documentContainer.Document));
            var skylineDataSchema = new SkylineDataSchema(documentContainer, new DataSchemaLocalizer(cultureInfo, cultureInfo));
            var viewSpec          = ReportSharing.ConvertAll(new[] { new ReportOrViewSpec(reportSpec) }, doc).First();
            var viewContext       = new DocumentGridViewContext(skylineDataSchema);

            using (var writer = new StreamWriter(fileName))
            {
                IProgressStatus status = new ProgressStatus();
                viewContext.Export(CancellationToken.None, new SilentProgressMonitor(), ref status,
                                   viewContext.GetViewInfo(ViewGroup.BUILT_IN, viewSpec), writer, viewContext.GetCsvWriter());
            }
        }
        private void Repopulate()
        {
            treeView1.Nodes.Clear();
            if (null == _viewContext)
            {
                return;
            }
            var newNodes = new List <TreeNode>();

            foreach (var group in _viewContext.ViewGroups)
            {
                var groupNode = new TreeNode(group.Label)
                {
                    Name = group.Id.Name, Tag = group
                };
                groupNode.SelectedImageIndex = groupNode.ImageIndex = indexImageFolder;
                foreach (var viewSpec in _viewContext.GetViewSpecList(group.Id).ViewSpecs)
                {
                    if (null == _viewContext.GetViewInfo(group, viewSpec))
                    {
                        continue;
                    }
                    var viewNode = new TreeNode(viewSpec.Name)
                    {
                        Name = viewSpec.Name
                    };
                    int imageIndex = _viewContext.GetImageIndex(viewSpec);
                    if (imageIndex >= 0)
                    {
                        imageIndex += indexFirstImage;
                    }
                    else
                    {
                        imageIndex = indexImageBlank;
                    }
                    if (imageIndex >= 0)
                    {
                        viewNode.SelectedImageIndex = viewNode.ImageIndex = imageIndex;
                    }
                    groupNode.Nodes.Add(viewNode);
                }
                newNodes.Add(groupNode);
            }
            treeView1.Nodes.AddRange(newNodes.ToArray());
            treeView1.ExpandAll();
            UpdateButtons();
        }
Exemple #5
0
        private string GetReportRows(SrmDocument document, ViewSpec viewSpec, IProgressMonitor progressMonitor)
        {
            var container = new MemoryDocumentContainer();

            container.SetDocument(document, container.Document);
            var             dataSchema  = new SkylineDataSchema(container, DataSchemaLocalizer.INVARIANT);
            var             viewContext = new DocumentGridViewContext(dataSchema);
            IProgressStatus status      = new ProgressStatus(string.Format(Resources.ReportSpec_ReportToCsvString_Exporting__0__report,
                                                                           viewSpec.Name));
            var writer = new StringWriter();

            if (viewContext.Export(progressMonitor, ref status, viewContext.GetViewInfo(null, viewSpec), writer,
                                   viewContext.GetCsvWriter()))
            {
                return(writer.ToString());
            }
            return(null);
        }
Exemple #6
0
        public void TestGenerateMsStatsInput()
        {
            SrmDocument testDocument            = OpenTestDocument();
            var         memoryDocumentContainer = new MemoryDocumentContainer();

            Assert.IsTrue(memoryDocumentContainer.SetDocument(testDocument, memoryDocumentContainer.Document));
            SkylineDataSchema skylineDataSchema = new SkylineDataSchema(memoryDocumentContainer, DataSchemaLocalizer.INVARIANT);
            var             view           = ReportSharing.DeserializeReportList(OpenTestFile("MSstats_report.skyr")).First().ViewSpec;
            var             viewContext    = new DocumentGridViewContext(skylineDataSchema);
            StringWriter    stringWriter   = new StringWriter();
            IProgressStatus progressStatus = new ProgressStatus();

            viewContext.Export(new SilentProgressMonitor(), ref progressStatus,
                               viewContext.GetViewInfo(ViewGroup.BUILT_IN, view), stringWriter,
                               viewContext.GetCsvWriter());
            string expectedReport = new StreamReader(OpenTestFile("BrudererSubset_MSstatsInput.csv")).ReadToEnd();

            AssertEx.NoDiff(expectedReport, stringWriter.ToString());
        }