예제 #1
0
        public static void SaveReport(ViewGroup viewGroup, ReportOrViewSpec reportOrViewSpec)
        {
            var srmDocument             = GetDefaultDocument();
            var documentGridViewContext = new DocumentGridViewContext(GetSkylineDataSchema(srmDocument, DataSchemaLocalizer.INVARIANT));

            documentGridViewContext.AddOrReplaceViews(viewGroup.Id, ConvertAll(new[] { reportOrViewSpec }, srmDocument));
        }
예제 #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");
            char separator = TextUtil.GetCsvSeparator(cultureInfo);
            var dsvWriter = new DsvWriter(cultureInfo, separator);
            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(separator);
            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 static IDictionary <ViewName, ReportOrViewSpec> GetExistingReports()
        {
            var documentGridViewContext = new DocumentGridViewContext(GetSkylineDataSchema(GetDefaultDocument(), DataSchemaLocalizer.INVARIANT));
            var items = documentGridViewContext.ViewGroups.SelectMany(group => documentGridViewContext.GetViewSpecList(group.Id).ViewSpecs.Select(
                                                                          viewSpec => new KeyValuePair <ViewName, ReportOrViewSpec>(
                                                                              new ViewName(group.Id, viewSpec.Name), new ReportOrViewSpec(viewSpec))));

            return(SafeToDictionary(items));
        }
예제 #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);
     var 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,
         new DsvWriter(CultureInfo.InvariantCulture, TextUtil.SEPARATOR_CSV)))
     {
         return writer.ToString();
     }
     return null;
 }
예제 #5
0
        public void ConsoleReportExportTest()
        {
            var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE);
            string docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky");
            string outPath = testFilesDir.GetTestPath("Exported_test_report.csv");

            // Import the first RAW file (or mzML for international)
            string rawPath = testFilesDir.GetTestPath("ah_20101011y_BSA_MS-MS_only_5-2" +
                ExtensionTestContext.ExtThermoRaw);
            const string replicate = "Single";

            //Before generating this report, check that it exists
            string reportName = Resources.ReportSpecList_GetDefaults_Peptide_Ratio_Results;
            Settings.Default.PersistedViews.ResetDefaults();
            Assert.IsNotNull(Settings.Default.PersistedViews.GetViewSpecList(PersistedViews.MainGroup.Id)
                .GetView(Resources.ReportSpecList_GetDefaults_Peptide_Ratio_Results));

            //First, programmatically generate the report
            SrmDocument doc = ResultsUtil.DeserializeDocument(docPath);

            //Attach replicate
            ProgressStatus status;
            doc = CommandLine.ImportResults(doc, docPath, replicate, MsDataFileUri.Parse(rawPath), null, null, out status);
            Assert.IsNull(status);

            string programmaticReport;
            MemoryDocumentContainer memoryDocumentContainer = new MemoryDocumentContainer();
            Assert.IsTrue(memoryDocumentContainer.SetDocument(doc, memoryDocumentContainer.Document));
            SkylineDataSchema skylineDataSchema = new SkylineDataSchema(memoryDocumentContainer, SkylineDataSchema.GetLocalizedSchemaLocalizer());
            DocumentGridViewContext viewContext = new DocumentGridViewContext(skylineDataSchema);
            ViewInfo viewInfo = viewContext.GetViewInfo(PersistedViews.MainGroup.Id.ViewName(reportName));
            StringWriter writer = new StringWriter();
            status = new ProgressStatus("Exporting report");
            viewContext.Export(null, ref status, viewInfo, writer,
                new DsvWriter(CultureInfo.CurrentCulture, TextUtil.GetCsvSeparator(LocalizationHelper.CurrentCulture)));
            programmaticReport = writer.ToString();

            RunCommand("--in=" + docPath,
                       "--import-file=" + rawPath,
                       "--import-replicate-name=" + replicate,
                       "--report-name=" + reportName,
                       "--report-format=CSV",
                       "--report-file=" + outPath);

            string reportLines = File.ReadAllText(outPath);
            AssertEx.NoDiff(reportLines, programmaticReport);
        }
예제 #6
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 = new DsvWriter(CultureInfo.InvariantCulture, ',');
            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);
        }
예제 #7
0
 protected override void OnHandleDestroyed(EventArgs e)
 {
     base.OnHandleDestroyed(e);
     if (null != _viewContext)
     {
         _viewContext.ViewsChanged -= OnViewsChanged;
         _viewContext = null;
     }
 }
예제 #8
0
 protected override void OnHandleCreated(EventArgs e)
 {
     base.OnHandleCreated(e);
     if (null != _documentUiContainer)
     {
         _viewContext = new DocumentGridViewContext(new SkylineDataSchema(_documentUiContainer,
                 DataSchemaLocalizer.INVARIANT));
         _viewContext.ViewsChanged += OnViewsChanged;
         imageList1.Images.Clear();
         imageList1.Images.Add(Resources.Folder);
         imageList1.Images.Add(Resources.Blank);
         imageList1.Images.AddRange(_viewContext.GetImageList());
         Repopulate();
     }
 }