コード例 #1
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();
            }
        }
コード例 #2
0
        public void TestExportWithCurrentLanguage()
        {
            CultureInfo       cultureInfo       = CultureInfo.CurrentUICulture;
            SkylineDataSchema skylineDataSchema =
                new SkylineDataSchema(CreateMemoryDocumentContainer(LoadTestDocument()), SkylineDataSchema.GetLocalizedSchemaLocalizer());
            SkylineViewContext viewContext = new DocumentGridViewContext(skylineDataSchema);

            string testFile  = Path.Combine(TestContext.TestDir, "TestExportWithCurrentLanguage.csv");
            var    dsvWriter = viewContext.GetCsvWriter();

            viewContext.ExportToFile(null, GetTestReport(skylineDataSchema), testFile, dsvWriter);
            string strExported   = File.ReadAllText(testFile);
            var    actualLines   = strExported.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            var    expectedLines = ExpectedInvariantReport.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            var invariantHeaders = expectedLines[0].Split(',');
            var expectedHeaders  =
                invariantHeaders.Select(header => ColumnCaptions.ResourceManager.GetString(header, cultureInfo) ?? header).ToArray();
            var actualHeaders = actualLines[0].Split(TextUtil.GetCsvSeparator(cultureInfo));

            CollectionAssert.AreEqual(expectedHeaders, actualHeaders);
            // If the language in English, then the exported report will be identical to the invariant report except for the headers
            if (cultureInfo.Name == "en-US")
            {
                CollectionAssert.AreEqual(expectedLines.Skip(1).ToArray(), actualLines.Skip(1).ToArray());
            }
        }
コード例 #3
0
        public void TestInvariantExport()
        {
            SkylineDataSchema skylineDataSchema =
                new SkylineDataSchema(CreateMemoryDocumentContainer(LoadTestDocument()), DataSchemaLocalizer.INVARIANT);
            SkylineViewContext viewContext = new DocumentGridViewContext(skylineDataSchema);

            string testFile  = Path.Combine(TestContext.TestDir, "TestInvariantExport.csv");
            var    dsvWriter = viewContext.GetCsvWriter();

            viewContext.ExportToFile(null, GetTestReport(skylineDataSchema), testFile, dsvWriter);
            string strExported = File.ReadAllText(testFile);

            Assert.AreEqual(ExpectedInvariantReport, strExported);
            // Assert that the file written out was UTF8 encoding without any byte order mark
            byte[] bytesExported = File.ReadAllBytes(testFile);
            CollectionAssert.AreEqual(Encoding.UTF8.GetBytes(strExported), bytesExported);
        }
コード例 #4
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(CancellationToken.None, progressMonitor, ref status, viewContext.GetViewInfo(null, viewSpec), writer,
                                   viewContext.GetCsvWriter()))
            {
                return(writer.ToString());
            }
            return(null);
        }
コード例 #5
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());
        }
コード例 #6
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());
            }
        }