Exemple #1
0
        private static string GetExceptionDisplayMessage(Exception x)
        {
            var match = REGEX_MISSING_COLUMN.Match(x.Message);

            if (match.Success)
            {
                try
                {
                    string columnName = match.Groups[1].ToString();
                    if (AnnotationDef.IsAnnotationProperty(columnName))
                    {
                        columnName = AnnotationDef.GetColumnDisplayName(columnName);
                    }
                    else if (RatioPropertyAccessor.IsRatioOrRdotpProperty(columnName))
                    {
                        columnName = RatioPropertyAccessor.GetDisplayName(columnName);
                    }
                    return(string.Format(Resources.ExportReportDlg_GetExceptionDisplayMessage_The_field__0__does_not_exist_in_this_document, columnName));
                }
// ReSharper disable EmptyGeneralCatchClause
                catch
                {
                    // Could throw a variety of SQLiteException & NHibernat exceptions
                }
// ReSharper restore EmptyGeneralCatchClause
            }

            return(x.Message);
        }
Exemple #2
0
        protected List <TreeNode> GetTreeNodes(IClassMetadata classMetadata, Identifier identifier)
        {
            List <TreeNode> result = new List <TreeNode>();
            // Add special ratio names in order after the default ratio name
            int lastRatioIndex = -1;

            foreach (String propertyName in classMetadata.PropertyNames)
            {
                IType propertyType = classMetadata.GetPropertyType(propertyName);
                if (propertyType is ManyToOneType)
                {
                    continue;
                }
                var  label   = propertyName;
                bool isRatio = RatioPropertyAccessor.IsRatioOrRdotpProperty(label);
                if (isRatio)
                {
                    label = RatioPropertyAccessor.GetDisplayName(label);
                }
                else if (AnnotationDef.IsAnnotationProperty(label))
                {
                    label = AnnotationDef.GetColumnDisplayName(label);
                }
                else if (label.IndexOf("Ratio", StringComparison.Ordinal) != -1) // Not L10N: Label is only used in this file. Never displayed.
                {
                    lastRatioIndex = result.Count;
                }
                var columnInfo = CreateColumnInfo(identifier, classMetadata, propertyName);
                if (columnInfo.IsHidden)
                {
                    continue;
                }
                TreeNode propertyNode
                    = new TreeNode
                    {
                    Name = propertyName,
                    Text = label,
                    Tag  = columnInfo
                    };
                if (isRatio && lastRatioIndex != -1)
                {
                    result.Insert(++lastRatioIndex, propertyNode);
                }
                else
                {
                    result.Add(propertyNode);
                }
            }
            return(result);
        }
Exemple #3
0
        public ColumnInfo GetColumnInfo(Type table, String column)
        {
            var columnInfo = new ColumnInfo
            {
                ReportColumn = new ReportColumn(table, new Identifier(column)),
                Caption      = column
            };

            if (AnnotationDef.IsAnnotationProperty(column))
            {
                var classMetadata = GetClassMetadata(table);
                columnInfo.Caption    = AnnotationDef.GetColumnDisplayName(column);
                columnInfo.ColumnType = classMetadata.GetPropertyType(column).ReturnedClass;
                columnInfo.IsHidden   = !_annotationDefNames.Contains(
                    AnnotationDef.GetColumnKey(column));
            }
            else if (RatioPropertyAccessor.IsRatioOrRdotpProperty(column))
            {
                var classMetadata = GetClassMetadata(table);
                columnInfo.Caption    = RatioPropertyAccessor.GetDisplayName(column);
                columnInfo.ColumnType = classMetadata.GetPropertyType(column).ReturnedClass;
                if (RatioPropertyAccessor.IsRatioGsProperty(column))
                {
                    columnInfo.Format = Formats.GLOBAL_STANDARD_RATIO;
                }
                else if (RatioPropertyAccessor.IsRatioProperty(column))
                {
                    columnInfo.Format = Formats.STANDARD_RATIO;
                }
                else if (RatioPropertyAccessor.IsRdotpProperty(column))
                {
                    columnInfo.Format = Formats.STANDARD_RATIO;
                }
            }
            else
            {
                PropertyInfo propertyInfo = table.GetProperty(column);
                columnInfo.ColumnType = propertyInfo.PropertyType;
                foreach (QueryColumn attr in propertyInfo.GetCustomAttributes(typeof(QueryColumn), true))
                {
                    columnInfo.Caption  = attr.FullName ?? columnInfo.Caption;
                    columnInfo.Format   = attr.Format ?? columnInfo.Format;
                    columnInfo.IsHidden = attr.IsHidden;
                }
            }
            return(columnInfo);
        }
Exemple #4
0
        private ColumnSpec ConvertReportColumn(ReportColumn reportColumn)
        {
            var    identifierPath            = PropertyPath.Root;
            var    databindingTableAttribute = GetDatabindingTableAttribute(reportColumn);
            var    component  = reportColumn.Table;
            string oldCaption = null;

            foreach (string part in reportColumn.Column.Parts)
            {
                PropertyPath propertyPath;
                if (part.StartsWith(AnnotationDef.ANNOTATION_PREFIX))
                {
                    string annotationName = AnnotationDef.GetColumnDisplayName(part);
                    if (component == typeof(DbProteinResult))
                    {
                        propertyPath = PropertyPath.Root.Property(@"Replicate").Property(AnnotationDef.ANNOTATION_PREFIX + annotationName);
                    }
                    else
                    {
                        propertyPath = PropertyPath.Root.Property(AnnotationDef.ANNOTATION_PREFIX + annotationName);
                    }
                    oldCaption = annotationName;
                    component  = typeof(string);
                }
                else if (RatioPropertyAccessor.IsRatioOrRdotpProperty(part))
                {
                    propertyPath = null;
                    if (component == typeof(DbPeptideResult))
                    {
                        const string prefixPeptideRatio = "ratio_Ratio";
                        string       labelName, standardName;
                        if (part.StartsWith(prefixPeptideRatio))
                        {
                            if (TryParseLabelNames(part.Substring(prefixPeptideRatio.Length), out labelName, out standardName))
                            {
                                propertyPath = PropertyPath.Root.Property(RatioPropertyDescriptor.MakePropertyName(
                                                                              RatioPropertyDescriptor.RATIO_PREFIX, labelName, standardName));
                            }
                        }
                        const string prefixPeptideRdotp = "rdotp_DotProduct";
                        if (part.StartsWith(prefixPeptideRdotp))
                        {
                            if (TryParseLabelNames(part.Substring(prefixPeptideRdotp.Length), out labelName, out standardName))
                            {
                                propertyPath = PropertyPath.Root.Property(RatioPropertyDescriptor.MakePropertyName(
                                                                              RatioPropertyDescriptor.RDOTP_PREFIX, labelName, standardName));
                            }
                        }
                    }
                    else if (component == typeof(DbPrecursorResult))
                    {
                        const string prefixPrecursorRatio = "ratio_TotalAreaRatioTo";
                        const string prefixPrecursorRdotp = "rdotp_DotProductTo";
                        if (part.StartsWith(prefixPrecursorRatio))
                        {
                            propertyPath = PropertyPath.Root.Property(
                                RatioPropertyDescriptor.MakePropertyName(RatioPropertyDescriptor.RATIO_PREFIX, part.Substring(prefixPrecursorRatio.Length)));
                        }
                        else if (part.StartsWith(prefixPrecursorRdotp))
                        {
                            propertyPath = PropertyPath.Root.Property(
                                RatioPropertyDescriptor.MakePropertyName(RatioPropertyDescriptor.RDOTP_PREFIX,
                                                                         part.Substring(prefixPrecursorRdotp.Length)));
                        }
                    }
                    else if (component == typeof(DbTransitionResult))
                    {
                        const string prefixTransitionRatio = "ratio_AreaRatioTo";
                        if (part.StartsWith(prefixTransitionRatio))
                        {
                            propertyPath = PropertyPath.Root.Property(
                                RatioPropertyDescriptor.MakePropertyName(RatioPropertyDescriptor.RATIO_PREFIX,
                                                                         part.Substring(prefixTransitionRatio.Length)));
                        }
                    }
                    component  = typeof(double);
                    oldCaption = null;
                    if (null == propertyPath)
                    {
                        Trace.TraceWarning(@"Unable to parse ratio property {0}", part);
                        propertyPath = PropertyPath.Root.Property(part);
                    }
                }
//                else if (component == typeof (DbProteinResult) && part == "ResultFile")
//                {
//                    propertyPath = PropertyPath.Parse("Results!*.Value");
//                }
                else
                {
                    PropertyInfo property = component.GetProperty(part);
                    if (null == property)
                    {
                        Trace.TraceWarning(@"Could not find property {0}", part);
                        continue;
                    }
                    propertyPath = PropertyPath.Root.Property(part);
                    foreach (DatabindingColumnAttribute databindingColumn in
                             property.GetCustomAttributes(typeof(DatabindingColumnAttribute), true))
                    {
                        if (null != databindingColumn.Name)
                        {
                            propertyPath = PropertyPath.Parse(databindingColumn.Name);
                            break;
                        }
                    }
                    oldCaption = property.Name;
                    foreach (QueryColumn attr in property.GetCustomAttributes(typeof(QueryColumn), true))
                    {
                        oldCaption = attr.FullName ?? oldCaption;
                    }
                    component = property.PropertyType;
                }
                identifierPath = identifierPath.Concat(propertyPath);
            }
            var columnDescriptor = GetColumnDescriptor(databindingTableAttribute, identifierPath);

            if (null == columnDescriptor)
            {
                return(new ColumnSpec(identifierPath));
            }
            var columnSpec = new ColumnSpec(columnDescriptor.PropertyPath);
            var newCaption = DataSchema.GetColumnCaption(columnDescriptor).GetCaption(DataSchemaLocalizer.INVARIANT);

            if (oldCaption != newCaption)
            {
                columnSpec = columnSpec.SetCaption(oldCaption);
            }
            return(columnSpec);
        }