Example #1
0
        public static Type GetRootTable(ReportSpec reportSpec)
        {
            var types = reportSpec.Select.Select(GetRootTable).Distinct().ToArray();

            if (types.Length == 1)
            {
                return(types[0]);
            }
            return(null);
        }
Example #2
0
 public override void WriteXml(XmlWriter writer)
 {
     if (ViewSpec != null)
     {
         ViewSpec.WriteXml(writer);
     }
     else
     {
         ReportSpec.WriteXml(writer);
     }
 }
Example #3
0
 public override void ReadXml(XmlReader reader)
 {
     base.ReadXml(reader);
     if (null != reader.GetAttribute("rowsource") || null != reader.GetAttribute("sublist")) // Not L10N
     {
         ViewSpec = ViewSpec.ReadXml(reader);
     }
     else
     {
         ReportSpec = ReportSpec.Deserialize(reader);
     }
 }
Example #4
0
 public new ReportOrViewSpec ChangeName(string newName)
 {
     if (null != ViewSpec)
     {
         return(new ReportOrViewSpec(ViewSpec.SetName(newName)));
     }
     if (null != ReportSpec)
     {
         return(new ReportOrViewSpec((ReportSpec)ReportSpec.ChangeName(newName)));
     }
     return((ReportOrViewSpec)base.ChangeName(newName));
 }
Example #5
0
 public override void ReadXml(XmlReader reader)
 {
     base.ReadXml(reader);
     if (null != reader.GetAttribute(@"rowsource") || null != reader.GetAttribute(@"sublist"))
     {
         ViewSpecLayout = new ViewSpecLayout(ViewSpec.ReadXml(reader), ViewLayoutList.EMPTY);
     }
     else
     {
         ReportSpec = ReportSpec.Deserialize(reader);
     }
 }
 private bool TryGetReport(SrmDocument document, ReportSpec reportSpec, out string report)
 {
     lock (_cacheLock)
     {
         if (ReferenceEquals(document, _document) && _dictionary.TryGetValue(reportSpec, out report))
         {
             _list.Remove(reportSpec);
             _list.AddFirst(reportSpec);
             return(true);
         }
     }
     report = null;
     return(false);
 }
Example #7
0
        public new ReportOrViewSpec ChangeName(string newName)
        {
            if (null != ViewSpecLayout)
            {
                return(new ReportOrViewSpec(ViewSpecLayout.ChangeName(newName)));
            }

            if (null != ReportSpec)
            {
                return(new ReportOrViewSpec((ReportSpec)ReportSpec.ChangeName(newName)));
            }

            throw new InvalidOperationException();
        }
Example #8
0
 public void SetReportSpec(ReportSpec reportSpec)
 {
     if (reportSpec == null)
     {
         textName.Text = string.Empty;
         SetReport(new SimpleReport());
     }
     else
     {
         textName.Text = reportSpec.Name;
         SetReport(Report.Load(reportSpec));
     }
     _reportSpec = reportSpec;
 }
Example #9
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());
            }
        }
Example #10
0
 public void ReportToCsv(ReportSpec reportSpec, SrmDocument doc, string fileName, CultureInfo cultureInfo)
 {
     Report report = Report.Load(reportSpec);
     using (var saver = new FileSaver(fileName))
     using (var writer = new StreamWriter(saver.SafeName))
     using (var database = new Database(doc.Settings))
     {
         database.AddSrmDocument(doc);
         var resultSet = report.Execute(database);
         char separator = TextUtil.GetCsvSeparator(cultureInfo);
         ResultSet.WriteReportHelper(resultSet, separator, writer, cultureInfo);
         writer.Flush();
         writer.Close();
         saver.Commit();
     }
 }
Example #11
0
        public void ReportToCsv(ReportSpec reportSpec, SrmDocument doc, string fileName)
        {
            Report report = Report.Load(reportSpec);

            using (var saver = new FileSaver(fileName))
                using (var writer = new StreamWriter(saver.SafeName))
                    using (var database = new Database(doc.Settings))
                    {
                        database.AddSrmDocument(doc);
                        var  resultSet = report.Execute(database);
                        char separator = TextUtil.CsvSeparator;
                        ResultSet.WriteReportHelper(resultSet, separator, writer, LocalizationHelper.CurrentCulture);
                        writer.Flush();
                        writer.Close();
                        saver.Commit();
                    }
        }
Example #12
0
        /// <summary>
        /// Returns the .csv file generated by exporting the given ReportSpec using data from the given Document.
        /// </summary>
        /// <param name="document">The current document open in Skyline</param>
        /// <param name="reportSpec">The export report format</param>
        /// <param name="progressMonitor"></param>
        public string GetReport(SrmDocument document, ReportSpec reportSpec, IProgressMonitor progressMonitor)
        {
            string report;

            if (TryGetReport(document, reportSpec, out report))
            {
                return(report);
            }

            // Only on report at a time can be generated
            lock (_reportGenLock)
            {
                // Try again, in case we were waiting for the report we want to be generated
                if (TryGetReport(document, reportSpec, out report))
                {
                    return(report);
                }

                report = TestReport ?? reportSpec.ReportToCsvString(document, progressMonitor);
                lock (_cacheLock)
                {
                    // if the document has changed while the report was exporting, don't add it to the cache
                    if (ReferenceEquals(document, _document))
                    {
                        CurrentSize += ReportSize(report);
                        while (CurrentSize > (TestMaximumSize ?? MAXIMUM_SIZE))
                        {
                            // remove the oldest reports
                            ReportSpec oldestSpec = _list.Last.Value;
                            string     oldestReport;
                            if (_dictionary.TryGetValue(oldestSpec, out oldestReport))
                            {
                                _dictionary.Remove(oldestSpec);
                                CurrentSize -= ReportSize(oldestReport);
                            }
                            _list.RemoveLast();
                        }
                        _list.AddFirst(reportSpec);
                        _dictionary.Add(reportSpec, report);
                    }
                }
                return(report);
            }
        }
Example #13
0
 public static Report Load(ReportSpec reportSpec)
 {
     SimpleReport simpleReport;
     if (reportSpec.CrossTabHeaders != null)
     {
         PivotReport pivotReport = new PivotReport
                                       {
                                           GroupByColumns = reportSpec.GroupBy,
                                           CrossTabHeaders = reportSpec.CrossTabHeaders,
                                           CrossTabValues = reportSpec.CrossTabValues
                                       };
         simpleReport = pivotReport;
     }
     else
     {
         simpleReport = new SimpleReport();
     }
     simpleReport.Columns = reportSpec.Select;
     return simpleReport;
 }
Example #14
0
        public static Type GetNewTableType(ReportSpec reportSpec)
        {
            var rowTypes = new List <Type>();

            foreach (var column in reportSpec.Select)
            {
                var rowType = GetRootTable(column);
                if (null != rowType)
                {
                    rowTypes.Add(rowType);
                }
            }
            var unique = rowTypes.Distinct().ToArray();

            if (unique.Length != 1)
            {
                return(null);
            }
            return(unique[0]);
        }
Example #15
0
        public static Report Load(ReportSpec reportSpec)
        {
            SimpleReport simpleReport;

            if (reportSpec.CrossTabHeaders != null)
            {
                PivotReport pivotReport = new PivotReport
                {
                    GroupByColumns  = reportSpec.GroupBy,
                    CrossTabHeaders = reportSpec.CrossTabHeaders,
                    CrossTabValues  = reportSpec.CrossTabValues
                };
                simpleReport = pivotReport;
            }
            else
            {
                simpleReport = new SimpleReport();
            }
            simpleReport.Columns = reportSpec.Select;
            return(simpleReport);
        }
 /// <summary>
 /// In old custom reports, if the report was showing rows from a Results table,
 /// the report would not include any DocNode's which did not have any results.
 /// To preserve this behavior we add a filter that only DocNode's which have at
 /// least one Result get included.
 /// </summary>
 public static ViewSpec AddFilter(ViewSpec viewSpec, ReportSpec reportSpec)
 {
     var propertyPaths = new HashSet<PropertyPath>();
     IEnumerable<ReportColumn> columns = reportSpec.Select;
     if (reportSpec.CrossTabValues != null)
     {
         columns = columns.Concat(reportSpec.CrossTabValues);
     }
     foreach (var reportColumn in columns)
     {
         var databindingTableAttribute = GetDatabindingTableAttribute(reportColumn);
         if (null != databindingTableAttribute.Property && !databindingTableAttribute.Property.EndsWith("Summary")) // Not L10N
         {
             propertyPaths.Add(PropertyPath.Parse(databindingTableAttribute.Property));
         }
     }
     var newFilters =
         propertyPaths.Select(
             propertyPath => new FilterSpec(propertyPath, FilterOperations.OP_IS_NOT_BLANK, null));
     viewSpec = viewSpec.SetFilters(viewSpec.Filters.Concat(newFilters));
     return viewSpec;
 }
Example #17
0
        /// <summary>
        /// In old custom reports, if the report was showing rows from a Results table,
        /// the report would not include any DocNode's which did not have any results.
        /// To preserve this behavior we add a filter that only DocNode's which have at
        /// least one Result get included.
        /// </summary>
        public static ViewSpec AddFilter(ViewSpec viewSpec, ReportSpec reportSpec)
        {
            var propertyPaths = new HashSet <PropertyPath>();
            IEnumerable <ReportColumn> columns = reportSpec.Select;

            if (reportSpec.CrossTabValues != null)
            {
                columns = columns.Concat(reportSpec.CrossTabValues);
            }
            foreach (var reportColumn in columns)
            {
                var databindingTableAttribute = GetDatabindingTableAttribute(reportColumn);
                if (null != databindingTableAttribute.Property && !databindingTableAttribute.Property.EndsWith(@"Summary"))
                {
                    propertyPaths.Add(PropertyPath.Parse(databindingTableAttribute.Property));
                }
            }
            var newFilters = propertyPaths.Select(propertyPath => new FilterSpec(propertyPath, FilterPredicate.IS_NOT_BLANK));

            viewSpec = viewSpec.SetFilters(viewSpec.Filters.Concat(newFilters));
            return(viewSpec);
        }
        public void CheckReport(ReportSpec reportSpec)
        {
            string message = string.Format("Report {0}", reportSpec.Name);
            var converter = new ReportSpecConverter(_dataSchema);
            var viewInfo = converter.Convert(reportSpec);
            var report = Report.Load(reportSpec);
            ResultSet resultSet;
            try
            {
                resultSet = report.Execute(_database);
            }
            catch (Exception)
            {
                return;
            }
            using (var bindingListSource = new BindingListSource())
            {
                bindingListSource.SetViewContext(new SkylineViewContext(viewInfo.ParentColumn, GetRowSource(viewInfo)),
                    viewInfo);
                var oldCaptions = resultSet.ColumnInfos.Select(columnInfo => columnInfo.Caption).ToArray();
                var properties = bindingListSource.GetItemProperties(null);
                IList resultRows = bindingListSource;
                var newCaptions = properties.Cast<PropertyDescriptor>().Select(pd => pd.DisplayName).ToArray();
                if (!oldCaptions.SequenceEqual(newCaptions))
                {
                    CollectionAssert.AreEqual(oldCaptions, newCaptions, message);
                }
                if (resultSet.RowCount != resultRows.Count)
                {
                    Assert.AreEqual(resultSet.RowCount, resultRows.Count, message);
                }
                resultRows = SortRows(resultRows, properties);
                resultSet = SortResultSet(resultSet);
                for (int iRow = 0; iRow < resultSet.RowCount; iRow++)
                {
                    for (int iCol = 0; iCol < resultSet.ColumnInfos.Count; iCol++)
                    {
                        var propertyDescriptor = properties[iCol];
                        object oldValue = resultSet.GetRow(iRow)[iCol];
                        object newValue = propertyDescriptor.GetValue(resultRows[iRow]);
                        if (!Equals(oldValue, newValue))
                        {
                            Assert.AreEqual(oldValue, newValue,
                                message + "{0}:Values are not equal on Row {1} Column {2} ({3}) FullName:{4}",
                                message, iRow, iCol, propertyDescriptor.DisplayName, propertyDescriptor.Name);

                        }
                    }
                }
                foreach (char separator in new[] { ',', '\t' })
                {
                    StringWriter oldStringWriter = new StringWriter();
                    var cultureInfo = LocalizationHelper.CurrentCulture;
                    ResultSet.WriteReportHelper(resultSet, separator, oldStringWriter, cultureInfo);
                    StringWriter newStringWriter = new StringWriter();
                    var skylineViewContext = (SkylineViewContext) bindingListSource.ViewContext;
                    ProgressStatus progressStatus = new ProgressStatus("Status");
                    skylineViewContext.Export(null, ref progressStatus, viewInfo, newStringWriter,
                        new DsvWriter(cultureInfo, separator));
                    var newLineSeparators = new[] { "\r\n" };
                    var oldLines = oldStringWriter.ToString().Split(newLineSeparators, StringSplitOptions.None);
                    var newLines = newStringWriter.ToString().Split(newLineSeparators, StringSplitOptions.None);
                    // TODO(nicksh): Old reports would hide columns for annotations that were not in the document.
                    bool anyHiddenColumns = resultSet.ColumnInfos.Any(column => column.IsHidden);
                    if (!anyHiddenColumns)
                    {
                        Assert.AreEqual(oldLines[0], newLines[0]);
                        CollectionAssert.AreEquivalent(oldLines, newLines);
                    }
                }
            }
        }
Example #19
0
        /// <summary>
        /// Добавление контента, прописанного в базе конфигурации
        /// </summary>
        protected void AddContentFromBase(UserRights userRights, Dictionary <string, UiObjSpec> uiObjSpecs,
                                          DataAccess dataAccess)
        {
            if (userRights != null && uiObjSpecs != null)
            {
                List <UiObjProps> uiObjPropsList = dataAccess.GetUiObjPropsList(
                    UiObjProps.BaseUiTypes.Report | UiObjProps.BaseUiTypes.DataWnd);

                foreach (UiObjProps uiObjProps in uiObjPropsList)
                {
                    int uiObjID = uiObjProps.UiObjID;

                    if (userRights.GetUiObjRights(uiObjID).ViewRight)
                    {
                        UiObjSpec uiObjSpec;
                        uiObjSpecs.TryGetValue(uiObjProps.TypeCode, out uiObjSpec);

                        if (uiObjProps.BaseUiType == UiObjProps.BaseUiTypes.Report)
                        {
                            // добавление элемента отчёта
                            ReportItem reportItem = new ReportItem()
                            {
                                UiObjID = uiObjID,
                                Text    = uiObjProps.Title,
                                Path    = uiObjProps.Path
                            };

                            if (uiObjSpec is ReportSpec)
                            {
                                ReportSpec reportSpec = (ReportSpec)uiObjSpec;
                                if (string.IsNullOrEmpty(reportItem.Text))
                                {
                                    reportItem.Text = reportSpec.Name;
                                }
                                reportItem.Url        = uiObjSpec.GetUrl(uiObjID);
                                reportItem.ReportSpec = reportSpec;
                            }

                            if (!string.IsNullOrEmpty(reportItem.Text))
                            {
                                ReportItems.Add(reportItem);
                                reportItemDict[uiObjID] = reportItem;
                            }
                        }
                        else if (uiObjProps.BaseUiType == UiObjProps.BaseUiTypes.DataWnd)
                        {
                            // добавление элемента окна данных
                            DataWndItem dataWndItem = new DataWndItem()
                            {
                                UiObjID = uiObjID,
                                Text    = uiObjProps.Title,
                                Path    = uiObjProps.Path
                            };

                            if (uiObjSpec is DataWndSpec)
                            {
                                DataWndSpec dataWndSpec = (DataWndSpec)uiObjSpec;
                                if (string.IsNullOrEmpty(dataWndItem.Text))
                                {
                                    dataWndItem.Text = dataWndSpec.Name;
                                }
                                dataWndItem.Url         = uiObjSpec.GetUrl(uiObjID);
                                dataWndItem.DataWndSpec = dataWndSpec;
                            }

                            if (!string.IsNullOrEmpty(dataWndItem.Text))
                            {
                                DataWndItems.Add(dataWndItem);
                                dataWndItemDict[uiObjID] = dataWndItem;
                            }
                        }
                    }
                }
            }
        }
Example #20
0
 public bool ContainsKey(ReportSpec reportSpec)
 {
     return _dictionary.ContainsKey(reportSpec) && _list.Contains(reportSpec);
 }
        public void CheckReport(ReportSpec reportSpec)
        {
            string    message   = string.Format("Report {0}", reportSpec.Name);
            var       converter = new ReportSpecConverter(_dataSchema);
            var       viewInfo  = converter.Convert(reportSpec);
            var       report    = Report.Load(reportSpec);
            ResultSet resultSet;

            try
            {
                resultSet = report.Execute(_database);
            }
            catch (Exception)
            {
                return;
            }
            using (var bindingListSource = new BindingListSource())
            {
                bindingListSource.SetViewContext(new SkylineViewContext(viewInfo.ParentColumn, GetRowSource(viewInfo)),
                                                 viewInfo);
                var   oldCaptions = resultSet.ColumnInfos.Select(columnInfo => columnInfo.Caption).ToArray();
                var   properties  = bindingListSource.GetItemProperties(null);
                IList resultRows  = bindingListSource;
                var   newCaptions = properties.Cast <PropertyDescriptor>().Select(pd => pd.DisplayName).ToArray();
                if (!oldCaptions.SequenceEqual(newCaptions))
                {
                    CollectionAssert.AreEqual(oldCaptions, newCaptions, message);
                }
                if (resultSet.RowCount != resultRows.Count)
                {
                    Assert.AreEqual(resultSet.RowCount, resultRows.Count, message);
                }
                resultRows = SortRows(resultRows, properties);
                resultSet  = SortResultSet(resultSet);
                for (int iRow = 0; iRow < resultSet.RowCount; iRow++)
                {
                    for (int iCol = 0; iCol < resultSet.ColumnInfos.Count; iCol++)
                    {
                        var    propertyDescriptor = properties[iCol];
                        object oldValue           = resultSet.GetRow(iRow)[iCol];
                        object newValue           = propertyDescriptor.GetValue(resultRows[iRow]);
                        if (!Equals(oldValue, newValue))
                        {
                            Assert.AreEqual(oldValue, newValue,
                                            message + "{0}:Values are not equal on Row {1} Column {2} ({3}) FullName:{4}",
                                            message, iRow, iCol, propertyDescriptor.DisplayName, propertyDescriptor.Name);
                        }
                    }
                }
                foreach (char separator in new[] { ',', '\t' })
                {
                    StringWriter oldStringWriter = new StringWriter();
                    var          cultureInfo     = LocalizationHelper.CurrentCulture;
                    ResultSet.WriteReportHelper(resultSet, separator, oldStringWriter, cultureInfo);
                    StringWriter   newStringWriter    = new StringWriter();
                    var            skylineViewContext = (SkylineViewContext)bindingListSource.ViewContext;
                    ProgressStatus progressStatus     = new ProgressStatus("Status");
                    skylineViewContext.Export(null, ref progressStatus, viewInfo, newStringWriter,
                                              new DsvWriter(cultureInfo, separator));
                    var newLineSeparators = new[] { "\r\n" };
                    var oldLines          = oldStringWriter.ToString().Split(newLineSeparators, StringSplitOptions.None);
                    var newLines          = newStringWriter.ToString().Split(newLineSeparators, StringSplitOptions.None);
                    // TODO(nicksh): Old reports would hide columns for annotations that were not in the document.
                    bool anyHiddenColumns = resultSet.ColumnInfos.Any(column => column.IsHidden);
                    if (!anyHiddenColumns)
                    {
                        Assert.AreEqual(oldLines[0], newLines[0]);
                        CollectionAssert.AreEquivalent(oldLines, newLines);
                    }
                }
            }
        }
Example #22
0
        public void TestImportPeakBoundary()
        {
            // Load the SRM document and relevant files
            var  testFilesDir        = new TestFilesDir(TestContext, TEST_ZIP_PATH);
            bool isIntl              = (TextUtil.CsvSeparator != TextUtil.SEPARATOR_CSV);
            var  precursorMzs        = isIntl ? _precursorMzsIntl : _precursorMzsUs;
            var  peakBoundaryFileTsv = testFilesDir.GetTestPath(isIntl
                                                                   ? "PeakBoundaryTsvIntl.tsv"
                                                                   : "PeakBoundaryTsv.tsv");
            var peakBoundaryFileCsv = testFilesDir.GetTestPath(isIntl
                                                                   ? "PeakBoundaryIntl.csv"
                                                                   : "PeakBoundaryUS.csv");
            var         peakBoundaryDoc = testFilesDir.GetTestPath("Chrom05.sky");
            SrmDocument doc             = ResultsUtil.DeserializeDocument(peakBoundaryDoc);

            var    cult     = LocalizationHelper.CurrentCulture;
            var    cultI    = CultureInfo.InvariantCulture;
            string csvSep   = TextUtil.CsvSeparator.ToString(cultI);
            string spaceSep = TextUtil.SEPARATOR_SPACE.ToString(cultI);

            // Load an empty doc, so that we can make a change and
            // cause the .skyd to be loaded
            using (var docContainer = new ResultsTestDocumentContainer(null, peakBoundaryDoc))
            {
                docContainer.SetDocument(doc, null, true);
                docContainer.AssertComplete();
                SrmDocument docResults = docContainer.Document;
                // Test Tsv import, looking at first .raw file
                DoFileImportTests(docResults, peakBoundaryFileTsv, _precursorCharge,
                                  _tsvMinTime1, _tsvMaxTime1, _tsvIdentified1, _tsvAreas1, _peptides, 0, precursorMzs, annote);
                // Test Tsv import, looking at second .raw file
                DoFileImportTests(docResults, peakBoundaryFileTsv, _precursorCharge,
                                  _tsvMinTime2, _tsvMaxTime2, _tsvIdentified2, _tsvAreas2, _peptides, 1, precursorMzs, annote);

                // Test Csv import for local format
                DoFileImportTests(docResults, peakBoundaryFileCsv, _precursorCharge,
                                  _csvMinTime1, _csvMaxTime1, _csvIdentified1, _csvAreas1, _peptides, 0, precursorMzs, annote);
                DoFileImportTests(docResults, peakBoundaryFileCsv, _precursorCharge,
                                  _csvMinTime2, _csvMaxTime2, _csvIdentified2, _csvAreas2, _peptides, 1, precursorMzs, annote);

                // Test that importing same file twice leads to no change to document the second time
                var docNew     = ImportFileToDoc(docResults, peakBoundaryFileTsv);
                var docNewSame = ImportFileToDoc(docNew, peakBoundaryFileTsv);
                Assert.AreSame(docNew, docNewSame);
                Assert.AreNotSame(docNew, docResults);

                // Test that exporting peak boundaries and then importing them leads to no change
                string     peakBoundaryExport = testFilesDir.GetTestPath("TestRoundTrip.csv");
                ReportSpec reportSpec         = MakeReportSpec();
                ReportToCsv(reportSpec, docNew, peakBoundaryExport);
                var docRoundTrip = ImportFileToDoc(docNew, peakBoundaryExport);
                Assert.AreSame(docNew, docRoundTrip);


                // 1. Empty file -
                ImportThrowsException(docResults, string.Empty,
                                      Resources.PeakBoundaryImporter_Import_Failed_to_read_the_first_line_of_the_file);

                // 2. No separator in first line
                ImportThrowsException(docResults, "No-valid-separators",
                                      TextUtil.CsvSeparator == TextUtil.SEPARATOR_CSV
                        ? Resources.PeakBoundaryImporter_DetermineCorrectSeparator_The_first_line_does_not_contain_any_of_the_possible_separators_comma__tab_or_space_
                        : Resources.PeakBoundaryImporter_DetermineCorrectSeparator_The_first_line_does_not_contain_any_of_the_possible_separators_semicolon__tab_or_space_);

                // 3. Missing field names
                ImportThrowsException(docResults, string.Join(csvSep, PeakBoundaryImporter.STANDARD_FIELD_NAMES.Take(3).ToArray()),
                                      Resources.PeakBoundaryImporter_Import_Failed_to_find_the_necessary_headers__0__in_the_first_line);

                string   headerRow       = string.Join(csvSep, PeakBoundaryImporter.STANDARD_FIELD_NAMES.Take(6));
                string   headerRowSpaced = string.Join(spaceSep, PeakBoundaryImporter.STANDARD_FIELD_NAMES.Take(6));
                string[] values          =
                {
                    "TPEVDDEALEK", "Q_2012_0918_RJ_13.raw", (3.5).ToString(cult), (4.5).ToString(cult), 2.ToString(cult), 0.ToString(cult)
                };

                // 4. Mismatched field count
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRow, string.Join(spaceSep, values)),
                                      Resources.PeakBoundaryImporter_Import_Line__0__field_count__1__differs_from_the_first_line__which_has__2_);

                // 5. Invalid charge state
                string[] valuesBadCharge = new List <string>(values).ToArray();
                valuesBadCharge[(int)PeakBoundaryImporter.Field.charge] = (3.5).ToString(cult);
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRow, string.Join(csvSep, valuesBadCharge)),
                                      Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_charge_state_);
                valuesBadCharge[(int)PeakBoundaryImporter.Field.charge] = TextUtil.EXCEL_NA;
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRow, string.Join(csvSep, valuesBadCharge)),
                                      Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_charge_state_);

                // 6. Invalid start time
                string[] valuesBadTime = new List <string>(values).ToArray();
                valuesBadTime[(int)PeakBoundaryImporter.Field.start_time] = "bad";
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadTime)),
                                      Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_start_time_);
                valuesBadTime[(int)PeakBoundaryImporter.Field.end_time] = "bad";
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadTime)),
                                      Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_start_time_);

                // But ok if not adjusting peaks
                ImportNoException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadTime)), true, false, false);

                // 7. Invalid end time
                valuesBadTime[(int)PeakBoundaryImporter.Field.start_time] =
                    values[(int)PeakBoundaryImporter.Field.start_time];
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadTime)),
                                      Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_end_time_);

                // But ok if not adjusting peaks
                ImportNoException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadTime)), true, false, false);

                // #N/A in times ok
                valuesBadTime[(int)PeakBoundaryImporter.Field.start_time]   =
                    valuesBadTime[(int)PeakBoundaryImporter.Field.end_time] = TextUtil.EXCEL_NA;
                ImportNoException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadTime)));
                // If only start time #N/A throws exception
                valuesBadTime[(int)PeakBoundaryImporter.Field.start_time] = (3.5).ToString(cult);
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadTime)),
                                      Resources.PeakBoundaryImporter_Import_Missing_end_time_on_line__0_);
                // If only end time #N/A throws exception
                valuesBadTime[(int)PeakBoundaryImporter.Field.start_time] = TextUtil.EXCEL_NA;
                valuesBadTime[(int)PeakBoundaryImporter.Field.end_time]   = (3.5).ToString(cult);
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadTime)),
                                      Resources.PeakBoundaryImporter_Import_Missing_start_time_on_line__0_);
                // Empty times throws exception
                valuesBadTime[(int)PeakBoundaryImporter.Field.start_time]   =
                    valuesBadTime[(int)PeakBoundaryImporter.Field.end_time] = string.Empty;
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadTime)),
                                      Resources.PeakBoundaryImporter_Import_The_value___0___on_line__1__is_not_a_valid_start_time_);

                // 8. Not imported file gets skipped
                string[] valuesBadFile = new List <string>(values).ToArray();
                valuesBadFile[(int)PeakBoundaryImporter.Field.filename] = "Q_2012_0918_RJ_15.raw";
                ImportNoException(docResults, TextUtil.LineSeparate(headerRowSpaced, string.Join(spaceSep, valuesBadFile)));

                // 9. Unknown modification state gets skipped
                string[] valuesBadSequence = new List <string>(values).ToArray();
                valuesBadSequence[(int)PeakBoundaryImporter.Field.modified_peptide] = "T[+80]PEVDDEALEK";
                ImportNoException(docResults, TextUtil.LineSeparate(headerRow, string.Join(csvSep, valuesBadSequence)));

                // 10. Unknown peptide sequence gets skipped
                valuesBadSequence[(int)PeakBoundaryImporter.Field.modified_peptide] = "PEPTIDER";
                ImportNoException(docResults, TextUtil.LineSeparate(headerRow, string.Join(csvSep, valuesBadSequence)));

                // 11. Bad value in decoy field
                string[] valuesBadDecoys = new List <string>(values).ToArray();
                valuesBadDecoys[(int)PeakBoundaryImporter.Field.is_decoy] = 3.ToString(cult);
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRow, string.Join(csvSep, valuesBadDecoys)),
                                      Resources.PeakBoundaryImporter_Import_The_decoy_value__0__on_line__1__is_invalid__must_be_0_or_1_);

                // 12. Import with bad sample throws exception
                string[] valuesSample =
                {
                    "TPEVDDEALEK", "Q_2012_0918_RJ_13.raw", (3.5).ToString(cult), (4.5).ToString(cult), 2.ToString(cult), 0.ToString(cult), "badSample"
                };
                string headerRowSample = string.Join(csvSep, PeakBoundaryImporter.STANDARD_FIELD_NAMES);
                ImportThrowsException(docResults, TextUtil.LineSeparate(headerRowSample, string.Join(csvSep, valuesSample)),
                                      Resources.PeakBoundaryImporter_Import_Sample__0__on_line__1__does_not_match_the_file__2__);

                // 13. Decoys, charge state, and sample missing ok
                var    valuesFourFields = valuesSample.Take(4);
                string headerFourFields = string.Join(csvSep, PeakBoundaryImporter.STANDARD_FIELD_NAMES.Take(4));
                ImportNoException(docResults, TextUtil.LineSeparate(headerFourFields, string.Join(csvSep, valuesFourFields)));

                // 14. Valid (charge state, fileName, peptide) combo that is not in document gets skipped
                string[] valuesBadCombo = new List <string>(values).ToArray();
                valuesBadCombo[(int)PeakBoundaryImporter.Field.charge] = (5).ToString(cult);
                ImportNoException(docResults, TextUtil.LineSeparate(headerRow, string.Join(csvSep, valuesBadCombo)));

                // Note: Importing with all 7 columns is tested as part of MProphetResultsHandlerTest
            }

            // Now check a file that has peptide ID's, and see that they're properly ported
            var         peptideIdPath = testFilesDir.GetTestPath("Template_MS1Filtering_1118_2011_3-2min.sky");
            SrmDocument docId         = ResultsUtil.DeserializeDocument(peptideIdPath);

            docId = docId.ChangeSettings(docId.Settings.ChangePeptideLibraries(libraries =>
            {
                var lib = libraries.Libraries[0];
                return(libraries.ChangeLibrarySpecs(new LibrarySpec[]
                {
                    new BiblioSpecLiteSpec(lib.Name, testFilesDir.GetTestPath(lib.FileNameHint))
                }));
            }));

            using (var docContainerId = new ResultsTestDocumentContainer(null, peptideIdPath))
            {
                docContainerId.SetDocument(docId, null, true);
                docContainerId.AssertComplete();
                SrmDocument docResultsId       = docContainerId.Document;
                var         peakBoundaryFileId = testFilesDir.GetTestPath(isIntl
                                                                      ? "Template_MS1Filtering_1118_2011_3-2min_new_intl.tsv"
                                                                      : "Template_MS1Filtering_1118_2011_3-2min_new.tsv");
                DoFileImportTests(docResultsId, peakBoundaryFileId, _precursorChargeId,
                                  _idMinTime1, _idMaxTime1, _idIdentified1, _idAreas1, _peptidesId, 0);

                // 15. Decminal import format ok
                var headerUnimod = string.Join(csvSep, PeakBoundaryImporter.STANDARD_FIELD_NAMES.Take(4));
                var valuesUnimod = new[]
                {
                    "LGGLRPES[+" + string.Format("{0:F01}", 80.0) + "]PESLTSVSR", "100803_0005b_MCF7_TiTip3.wiff", (80.5).ToString(cult), (82.0).ToString(cult)
                };
                ImportNoException(docResultsId, TextUtil.LineSeparate(headerUnimod, string.Join(csvSep, valuesUnimod)));

                // 16. Integer import format ok
                valuesUnimod[0] = "LGGLRPES[+80]PESLTSVSR";
                ImportNoException(docResultsId, TextUtil.LineSeparate(headerUnimod, string.Join(csvSep, valuesUnimod)));

                // 17. Unimod import format ok
                valuesUnimod[0] = "LGGLRPES(UniMod:21)PESLTSVSR";
                ImportNoException(docResultsId, TextUtil.LineSeparate(headerUnimod, string.Join(csvSep, valuesUnimod)));

                // 18. Strange capitalizations OK
                valuesUnimod[0] = "LGGLRPES(uniMoD:21)PESLTSVSR";
                ImportNoException(docResultsId, TextUtil.LineSeparate(headerUnimod, string.Join(csvSep, valuesUnimod)));

                // 18. Unimod with brackets OK
                valuesUnimod[0] = "LGGLRPES[uniMoD:21]PESLTSVSR";
                ImportNoException(docResultsId, TextUtil.LineSeparate(headerUnimod, string.Join(csvSep, valuesUnimod)));
            }
        }
Example #23
0
 public void SetReportSpec(ReportSpec reportSpec)
 {
     if (reportSpec == null)
     {
         textName.Text = string.Empty;
         SetReport(new SimpleReport());
     }
     else
     {
         textName.Text = reportSpec.Name;
         SetReport(Report.Load(reportSpec));
     }
     _reportSpec = reportSpec;
 }
 public static Type GetRootTable(ReportSpec reportSpec)
 {
     var types = reportSpec.Select.Select(GetRootTable).Distinct().ToArray();
     if (types.Length == 1)
     {
         return types[0];
     }
     return null;
 }
 private void ValidateReport(ReportSpec reportSpec, Type rowType)
 {
     var dataSchema = GetDataSchema();
     var converter = new ReportSpecConverter(dataSchema);
     var viewInfo = converter.Convert(reportSpec);
     Assert.AreEqual(rowType, viewInfo.ParentColumn.PropertyType);
     EnsureViewRoundTrips(viewInfo);
 }
 public static Type GetNewTableType(ReportSpec reportSpec)
 {
     var rowTypes = new List<Type>();
     foreach (var column in reportSpec.Select)
     {
         var rowType = GetRootTable(column);
         if (null != rowType)
         {
             rowTypes.Add(rowType);
         }
     }
     var unique = rowTypes.Distinct().ToArray();
     if (unique.Length != 1)
     {
         return null;
     }
     return unique[0];
 }
Example #27
0
 private bool TryGetReport(SrmDocument document, ReportSpec reportSpec, out string report)
 {
     lock (_cacheLock)
     {
         if (ReferenceEquals(document, _document) && _dictionary.TryGetValue(reportSpec, out report))
         {
             _list.Remove(reportSpec);
             _list.AddFirst(reportSpec);
             return true;
         }
     }
     report = null;
     return false;
 }
Example #28
0
 public bool IsLast(ReportSpec report)
 {
     return _list.Last.Value.Equals(report);
 }
Example #29
0
        /// <summary>
        /// Returns the .csv file generated by exporting the given ReportSpec using data from the given Document.
        /// </summary>
        /// <param name="document">The current document open in Skyline</param>
        /// <param name="reportSpec">The export report format</param>
        /// <param name="progressMonitor"></param>
        public string GetReport(SrmDocument document, ReportSpec reportSpec, IProgressMonitor progressMonitor)
        {
            string report;
            if (TryGetReport(document, reportSpec, out report))
                return report;

            // Only on report at a time can be generated
            lock (_reportGenLock)
            {
                // Try again, in case we were waiting for the report we want to be generated
                if (TryGetReport(document, reportSpec, out report))
                    return report;

                report = TestReport ?? reportSpec.ReportToCsvString(document, progressMonitor);
                lock (_cacheLock)
                {
                    // if the document has changed while the report was exporting, don't add it to the cache
                    if (ReferenceEquals(document, _document))
                    {
                        CurrentSize += ReportSize(report);
                        while (CurrentSize > (TestMaximumSize ?? MAXIMUM_SIZE))
                        {
                            // remove the oldest reports
                            ReportSpec oldestSpec = _list.Last.Value;
                            string oldestReport;
                            if (_dictionary.TryGetValue(oldestSpec, out oldestReport))
                            {
                                _dictionary.Remove(oldestSpec);
                                CurrentSize -= ReportSize(oldestReport);
                            }
                            _list.RemoveLast();
                        }
                        _list.AddFirst(reportSpec);
                        _dictionary.Add(reportSpec, report);
                    }
                }
                return report;
            }
        }
 public void TestMapping()
 {
     var settings = SrmSettingsList.GetDefault();
     var document = new SrmDocument(settings);
     var documentContainer = new MemoryDocumentContainer();
     documentContainer.SetDocument(document, null);
     using (var database = new Database(settings))
     {
         var dataSchema = new SkylineDataSchema(documentContainer, DataSchemaLocalizer.INVARIANT);
         var sessionFactory = database.SessionFactory;
         foreach (var classMetaData in sessionFactory.GetAllClassMetadata().Values)
         {
             var tableType = classMetaData.GetMappedClass(EntityMode.Poco);
             foreach (var propertyName in classMetaData.PropertyNames)
             {
                 if (propertyName == "Protein" && tableType == typeof (DbProteinResult))
                 {
                     continue;
                 }
                 var queryDef = new QueryDef
                     {
                         Select = new[] {new ReportColumn(tableType, propertyName),}
                     };
                 var reportSpec = new ReportSpec("test", queryDef);
                 var newTableType = ReportSpecConverter.GetNewTableType(reportSpec);
                 Assert.IsNotNull(newTableType, "No table for type {0}", tableType);
                 var converter = new ReportSpecConverter(dataSchema);
                 var viewInfo = converter.Convert(reportSpec);
                 Assert.IsNotNull(viewInfo, "Unable to convert property {0} in table {1}", propertyName, tableType);
                 Assert.AreEqual(1, viewInfo.DisplayColumns.Count, "No conversion for property {0} in table {1}", propertyName, tableType);
                 Assert.IsNotNull(viewInfo.DisplayColumns[0].ColumnDescriptor, "Column not found for property {0} in table {1}", propertyName, tableType);
                 var report = Report.Load(reportSpec);
                 var resultSet = report.Execute(database);
                 var bindingListSource = new BindingListSource();
                 bindingListSource.SetViewContext(new SkylineViewContext(viewInfo.ParentColumn, Array.CreateInstance(viewInfo.ParentColumn.PropertyType, 0)), viewInfo);
                 var properties = bindingListSource.GetItemProperties(null);
                 var oldCaptions = resultSet.ColumnInfos.Select(columnInfo => columnInfo.Caption).ToArray();
                 var newCaptions = properties.Cast<PropertyDescriptor>().Select(pd=>pd.DisplayName).ToArray();
                 if (oldCaptions.Length != newCaptions.Length)
                 {
                     Console.Out.WriteLine(oldCaptions);
                 }
                 CollectionAssert.AreEqual(oldCaptions, newCaptions, "Caption mismatch on {0} in {1}", propertyName, tableType);
                 for (int i = 0; i < resultSet.ColumnInfos.Count; i++)
                 {
                     var columnInfo = resultSet.ColumnInfos[i];
                     var formatAttribute = (FormatAttribute)properties[i].Attributes[typeof(FormatAttribute)];
                     string message = string.Format("Format problem on column converted from {0} in {1}",
                         columnInfo.ReportColumn.Column, columnInfo.ReportColumn.Table);
                     if (null == columnInfo.Format)
                     {
                         Assert.IsTrue(null == formatAttribute || null == formatAttribute.Format, message);
                     }
                     else
                     {
                         Assert.IsNotNull(formatAttribute, message);
                         Assert.AreEqual(columnInfo.Format, formatAttribute.Format, message);
                     }
                     if (columnInfo.IsNumeric)
                     {
                         Assert.IsNotNull(formatAttribute, message);
                         Assert.AreEqual(TextUtil.EXCEL_NA, formatAttribute.NullValue, message);
                     }
                     else
                     {
                         Assert.IsTrue(null == formatAttribute || null == formatAttribute.NullValue, message);
                     }
                 }
             }
         }
     }
 }
Example #31
0
        public ViewInfo Convert(ReportSpec reportSpec)
        {
            var rootTable = GetRootTable(reportSpec);

            if (null == rootTable)
            {
                return(null);
            }
            var columns     = new List <ColumnSpec>();
            var columnNames = new HashSet <PropertyPath>();
            var sublistId   = PropertyPath.Root;

            foreach (var reportColumn in reportSpec.Select)
            {
                var columnSpec         = ConvertReportColumn(reportColumn);
                var collectionProperty = columnSpec.PropertyPath;
                while (!collectionProperty.IsRoot && !collectionProperty.IsUnboundLookup)
                {
                    collectionProperty = collectionProperty.Parent;
                }
                if (collectionProperty.StartsWith(sublistId))
                {
                    sublistId = collectionProperty;
                }
                if (columnNames.Add(columnSpec.PropertyPath))
                {
                    columns.Add(columnSpec);
                }
            }
            if (null != reportSpec.GroupBy)
            {
                foreach (var reportColumn in reportSpec.GroupBy)
                {
                    var columnSpec = ConvertReportColumn(reportColumn);
                    if (!columns.Any(col => Equals(col.PropertyPath, columnSpec.PropertyPath)))
                    {
                        columns.Add(columnSpec.SetHidden(true));
                    }
                }
            }
            bool pivotIsotopeLabel = false;

            if (null != reportSpec.CrossTabHeaders)
            {
                pivotIsotopeLabel =
                    reportSpec.CrossTabHeaders.Any(reportColumn => !reportColumn.Column.ToString().EndsWith(@"Replicate"));
                if (pivotIsotopeLabel)
                {
                    sublistId = PropertyPath.Root.Property(@"Results").LookupAllItems();
                }
                foreach (var reportColumn in reportSpec.CrossTabHeaders)
                {
                    if (pivotIsotopeLabel || !reportColumn.Column.ToString().EndsWith(@"Replicate"))
                    {
                        var columnSpec = ConvertReportColumn(reportColumn).SetTotal(TotalOperation.PivotKey).SetHidden(true);
                        columns.Add(columnSpec);
                    }
                }
            }
            if (null != reportSpec.CrossTabValues)
            {
                foreach (var reportColumn in reportSpec.CrossTabValues)
                {
                    var convertedColumn = ConvertReportColumn(reportColumn);
                    if (pivotIsotopeLabel)
                    {
                        convertedColumn = convertedColumn.SetTotal(TotalOperation.PivotValue);
                    }
                    if (columnNames.Add(convertedColumn.PropertyPath))
                    {
                        columns.Add(convertedColumn);
                    }
                }
            }
            var viewSpec = new ViewSpec()
                           .SetName(reportSpec.Name)
                           .SetSublistId(sublistId)
                           .SetColumns(columns)
                           .SetRowType(rootTable);

            viewSpec = AddFilter(viewSpec, reportSpec);
            return(new ViewInfo(DataSchema, rootTable, viewSpec));
        }
Example #32
0
 public bool ContainsKey(ReportSpec reportSpec)
 {
     return(_dictionary.ContainsKey(reportSpec) && _list.Contains(reportSpec));
 }
Example #33
0
 public bool IsLast(ReportSpec report)
 {
     return(_list.Last.Value.Equals(report));
 }
 public ViewInfo Convert(ReportSpec reportSpec)
 {
     var rootTable = GetRootTable(reportSpec);
     if (null == rootTable)
     {
         return null;
     }
     var columns = new List<ColumnSpec>();
     var columnNames = new HashSet<PropertyPath>();
     var sublistId = PropertyPath.Root;
     foreach (var reportColumn in reportSpec.Select)
     {
         var columnSpec = ConvertReportColumn(reportColumn);
         var collectionProperty = columnSpec.PropertyPath;
         while (!collectionProperty.IsRoot && !collectionProperty.IsUnboundLookup)
         {
             collectionProperty = collectionProperty.Parent;
         }
         if (collectionProperty.StartsWith(sublistId))
         {
             sublistId = collectionProperty;
         }
         if (columnNames.Add(columnSpec.PropertyPath))
         {
             columns.Add(columnSpec);
         }
     }
     if (null != reportSpec.GroupBy)
     {
         foreach (var reportColumn in reportSpec.GroupBy)
         {
             var columnSpec = ConvertReportColumn(reportColumn);
             if (!columns.Any(col => Equals(col.PropertyPath, columnSpec.PropertyPath)))
             {
                 columns.Add(columnSpec.SetHidden(true));
             }
         }
     }
     bool pivotIsotopeLabel = false;
     if (null != reportSpec.CrossTabHeaders)
     {
         pivotIsotopeLabel =
             reportSpec.CrossTabHeaders.Any(reportColumn => !reportColumn.Column.ToString().EndsWith("Replicate")); // Not L10N
         if (pivotIsotopeLabel)
         {
             sublistId = PropertyPath.Root.Property("Results").LookupAllItems(); // Not L10N
         }
         foreach (var reportColumn in reportSpec.CrossTabHeaders)
         {
             if (pivotIsotopeLabel || !reportColumn.Column.ToString().EndsWith("Replicate")) // Not L10N
             {
                 var columnSpec = ConvertReportColumn(reportColumn).SetTotal(TotalOperation.PivotKey).SetHidden(true);
                 columns.Add(columnSpec);
             }
         }
     }
     if (null != reportSpec.CrossTabValues)
     {
         foreach (var reportColumn in reportSpec.CrossTabValues)
         {
             var convertedColumn = ConvertReportColumn(reportColumn);
             if (pivotIsotopeLabel)
             {
                 convertedColumn = convertedColumn.SetTotal(TotalOperation.PivotValue);
             }
             if (columnNames.Add(convertedColumn.PropertyPath))
             {
                 columns.Add(convertedColumn);
             }
         }
     }
     var viewSpec = new ViewSpec()
         .SetName(reportSpec.Name)
         .SetSublistId(sublistId)
         .SetColumns(columns)
         .SetRowType(rootTable);
     viewSpec = AddFilter(viewSpec, reportSpec);
     return new ViewInfo(DataSchema, rootTable, viewSpec);
 }
Example #35
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string name;
            if (!helper.ValidateNameTextBox(textName, out name))
                return;

            if (_columns.Count == 0)
            {
                MessageBox.Show(this, Resources.PivotReportDlg_OkDialog_A_report_must_have_at_least_one_column, Program.Name);
                return;
            }

            ReportSpec reportSpec = GetReport().GetReportSpec(name);

            if ((_reportSpec == null || !Equals(reportSpec.Name, _reportSpec.Name)) &&
                    _existing.Contains(reportSpec, new NameComparer<ReportSpec>()))
            {
                helper.ShowTextBoxError(textName, Resources.PivotReportDlg_OkDialog_The_report__0__already_exists, name);
                return;
            }

            _reportSpec = reportSpec;

            DialogResult = DialogResult.OK;
            Close();
        }
Example #36
0
 public void ReportToCsv(ReportSpec reportSpec, SrmDocument doc, string fileName)
 {
     CheckReportCompatibility.ReportToCsv(reportSpec, doc, fileName, LocalizationHelper.CurrentCulture);
 }
Example #37
0
 public ReportOrViewSpec(ReportSpec reportSpec) : base(reportSpec.Name ?? NAME_INTERNAL)
 {
     ReportSpec = reportSpec;
 }
Example #38
0
 public void ReportToCsv(ReportSpec reportSpec, SrmDocument doc, string fileName, CultureInfo cultureInfo)
 {
     CheckReportCompatibility.ReportToCsv(reportSpec, doc, fileName, cultureInfo);
 }
Example #39
0
        public void TestMapping()
        {
            var settings          = SrmSettingsList.GetDefault();
            var document          = new SrmDocument(settings);
            var documentContainer = new MemoryDocumentContainer();

            documentContainer.SetDocument(document, null);
            using (var database = new Database(settings))
            {
                var dataSchema     = new SkylineDataSchema(documentContainer, DataSchemaLocalizer.INVARIANT);
                var sessionFactory = database.SessionFactory;
                foreach (var classMetaData in sessionFactory.GetAllClassMetadata().Values)
                {
                    var tableType = classMetaData.GetMappedClass(EntityMode.Poco);
                    foreach (var propertyName in classMetaData.PropertyNames)
                    {
                        if (propertyName == "Protein" && tableType == typeof(DbProteinResult))
                        {
                            continue;
                        }
                        var queryDef = new QueryDef
                        {
                            Select = new[] { new ReportColumn(tableType, propertyName), }
                        };
                        var reportSpec   = new ReportSpec("test", queryDef);
                        var newTableType = ReportSpecConverter.GetNewTableType(reportSpec);
                        Assert.IsNotNull(newTableType, "No table for type {0}", tableType);
                        var converter = new ReportSpecConverter(dataSchema);
                        var viewInfo  = converter.Convert(reportSpec);
                        Assert.IsNotNull(viewInfo, "Unable to convert property {0} in table {1}", propertyName, tableType);
                        Assert.AreEqual(1, viewInfo.DisplayColumns.Count, "No conversion for property {0} in table {1}", propertyName, tableType);
                        Assert.IsNotNull(viewInfo.DisplayColumns[0].ColumnDescriptor, "Column not found for property {0} in table {1}", propertyName, tableType);
                        var report            = Report.Load(reportSpec);
                        var resultSet         = report.Execute(database);
                        var bindingListSource = new BindingListSource();
                        bindingListSource.SetViewContext(new SkylineViewContext(viewInfo.ParentColumn, Array.CreateInstance(viewInfo.ParentColumn.PropertyType, 0)), viewInfo);
                        var properties  = bindingListSource.GetItemProperties(null);
                        var oldCaptions = resultSet.ColumnInfos.Select(columnInfo => columnInfo.Caption).ToArray();
                        var newCaptions = properties.Cast <PropertyDescriptor>().Select(pd => pd.DisplayName).ToArray();
                        if (oldCaptions.Length != newCaptions.Length)
                        {
                            Console.Out.WriteLine(oldCaptions);
                        }
                        CollectionAssert.AreEqual(oldCaptions, newCaptions, "Caption mismatch on {0} in {1}", propertyName, tableType);
                        for (int i = 0; i < resultSet.ColumnInfos.Count; i++)
                        {
                            var    columnInfo      = resultSet.ColumnInfos[i];
                            var    formatAttribute = (FormatAttribute)properties[i].Attributes[typeof(FormatAttribute)];
                            string message         = string.Format("Format problem on column converted from {0} in {1}",
                                                                   columnInfo.ReportColumn.Column, columnInfo.ReportColumn.Table);
                            if (null == columnInfo.Format)
                            {
                                Assert.IsTrue(null == formatAttribute || null == formatAttribute.Format, message);
                            }
                            else
                            {
                                Assert.IsNotNull(formatAttribute, message);
                                Assert.AreEqual(columnInfo.Format, formatAttribute.Format, message);
                            }
                            if (columnInfo.IsNumeric)
                            {
                                Assert.IsNotNull(formatAttribute, message);
                                Assert.AreEqual(TextUtil.EXCEL_NA, formatAttribute.NullValue, message);
                            }
                            else
                            {
                                Assert.IsTrue(null == formatAttribute || null == formatAttribute.NullValue, message);
                            }
                        }
                    }
                }
            }
        }
Example #40
0
 public ReportOrViewSpec(ReportSpec reportSpec) : base(reportSpec.Name)
 {
     ReportSpec = reportSpec;
 }