Exemplo n.º 1
0
        /// <summary>
        /// Convert the specified object to the corresponding MobiusDataType
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>

        public static StringMx ConvertTo(
            object o)
        {
            StringMx sx;

            if (o is StringMx)
            {
                return((StringMx)o);
            }
            else if (NullValue.IsNull(o))
            {
                return(new StringMx());
            }
            else if (o is MobiusDataType)
            {
                MobiusDataType mdt = o as MobiusDataType;
                sx = new StringMx(mdt.ToString());
                mdt.MemberwiseCopy(sx);
                return(sx);
            }
            else
            {
                return(new StringMx(o.ToString()));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Activity class includes both a class name (High, Medium, Low) and an activity color (Green to Red)
        /// and is calculated from ActivityBin
        /// </summary>

        public void SetActivityClass()
        {
            UnpivotedAssayResult sRow = this;
            int bin = sRow.ActivityBin;

            StringMx sx = new StringMx();

            if (bin < 0)
            {
                sx.Value     = "Missing Data";
                sx.BackColor = CondFormat.CsfUndefined;
            }

            else if (bin <= 3)
            {
                sx.Value     = "Fail";
                sx.BackColor = CondFormat.CsfRed;
            }

            else if (bin <= 6)
            {
                sx.Value     = "BorderLine";
                sx.BackColor = CondFormat.CsfYellow;
            }

            else
            {
                sx.Value     = "Pass";
                sx.BackColor = CondFormat.CsfGreen;
            }

            sRow.ActivityClass = sx;
            return;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Binary Deserialize
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>

        public static StringMx DeserializeBinary(BinaryReader br)
        {
            StringMx sx = new StringMx();

            MobiusDataType.DeserializeBinary(br, sx);
            sx.Value = br.ReadString();
            return(sx);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Clone
        /// </summary>
        /// <returns></returns>

        public new StringMx Clone()
        {
            StringMx sx = (StringMx)this.MemberwiseClone();

            if (sx.MdtExAttr != null)
            {
                sx.MdtExAttr = MdtExAttr.Clone();
            }
            return(sx);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Format stats for a leaf node
        /// </summary>
        /// <param name="mtn"></param>
        /// <returns></returns>

        public static StringBuilder FormatStatistics(MetaTreeNode mtn)
        {
            StringBuilder sb = new StringBuilder(32);

            if (mtn.IsFolderType)
            {
                return(sb);
            }
            if (mtn.UpdateDateTime == DateTime.MinValue && mtn.Size < 0)
            {
                return(sb);
            }

            if (mtn.UpdateDateTime != DateTime.MinValue)
            {
                if (sb.Length > 0)
                {
                    sb.Append("; ");
                }
                sb.Append(String.Format("Updated: {0:d-MMM-yy}", mtn.UpdateDateTime));
            }

            if (mtn.Size >= 0)
            {
                if (sb.Length > 0)
                {
                    sb.Append("; ");
                }

                if (mtn.Type == MetaTreeNodeType.MetaTable || mtn.Type == MetaTreeNodeType.Annotation)
                {
                    sb.Append("Rows: ");
                }
                else if (mtn.Type == MetaTreeNodeType.Query)
                {
                    sb.Append("Tables: ");
                }
                else if (mtn.Type == MetaTreeNodeType.CnList)
                {
                    sb.Append("Ids: ");
                }
                else if (mtn.Type == MetaTreeNodeType.Library)
                {
                    sb.Append("Compounds: ");
                }

                sb.Append(StringMx.FormatIntegerWithCommas(mtn.Size));
            }

            return(sb);
        }
Exemplo n.º 6
0
        new public void ToValueObject(
            object[] vo,
            UnpivotedAssayResultFieldPositionMap voMap)
        {
            base.ToValueObject(vo, voMap);             // set the basic attribute values

            UnpivotedAssayResult row = this;

            //if (row.ResultValue != null) row = row; // debug

            SetVo(vo, voMap.CompoundId.Voi, row.CompoundId);
            SetVo(vo, voMap.Structure.Voi, row.Structure);

            SetVo(vo, voMap.ActivityBin.Voi, row.ActivityBin);
            SetVo(vo, voMap.ActivityClass.Voi, row.ActivityClass);
            SetVo(vo, voMap.ResultValueQn.Voi, row.ResultValue);
            SetVo(vo, voMap.ResultQualifier.Voi, row.ResultQualifier);
            SetVo(vo, voMap.ResultNumericValue.Voi, row.ResultNumericValue);
            SetVo(vo, voMap.ResultTextValue.Voi, row.ResultTextValue);
            SetVo(vo, voMap.NValue.Voi, row.NValue);
            SetVo(vo, voMap.NValueTested.Voi, row.NValueTested);
            SetVo(vo, voMap.StdDev.Voi, row.StdDev);
            SetVo(vo, voMap.Units.Voi, row.Units);
            SetVo(vo, voMap.Conc.Voi, row.Conc);
            SetVo(vo, voMap.ConcUnits.Voi, row.ConcUnits);
            SetVo(vo, voMap.RunDate.Voi, row.RunDate);

            SetVo(vo, voMap.MostPotentValueQn.Voi, row.MostPotentVal);
            SetVo(vo, voMap.ActivityBinMostPotent.Voi, row.ActivityBinMostPotent);

            StringMx sx = new StringMx(row.ResultDetail);             // put link to cid, targetId & resultType

            sx.DbLink = "'" + row.CompoundId + "','" + row.GeneId + "','" + row.ResultTypeConcType + "'";
            SetVo(vo, voMap.ResultDetailId.Voi, sx);

            //SetVo(vo, voMap.TargetMapX.Voi, row.TargetMapX);
            //SetVo(vo, voMap.TargetMapY.Voi, row.TargetMapY);

            SetVo(vo, voMap.Sources.Voi, row.Sources);
            SetVo(vo, voMap.DrawingOrder.Voi, row.DrawingOrder);
            SetVo(vo, voMap.CidOrder.Voi, row.CidOrder);

            return;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Convert object to a MobiusDataType
        /// </summary>
        /// <param name="o"></param>
        /// <param name="type"></param>
        /// <returns></returns>

        public static MobiusDataType ConvertToMobiusDataType(
            MetaColumnType type,
            Object o)
        {
            switch (type)
            {
            case MetaColumnType.Integer:
            case MetaColumnType.Number:
            case MetaColumnType.DictionaryId:
                return(NumberMx.ConvertTo(o));

            case MetaColumnType.QualifiedNo:
                return(QualifiedNumber.ConvertTo(o));

            case MetaColumnType.String:
            case MetaColumnType.MolFormula:
            case MetaColumnType.Hyperlink:
            case MetaColumnType.Html:
            case MetaColumnType.Binary:
                return(StringMx.ConvertTo(o));

            case MetaColumnType.Date:
                return(DateTimeMx.ConvertTo(o));

            case MetaColumnType.CompoundId:
                return(CompoundId.ConvertTo(o));

            case MetaColumnType.Structure:
                return(MoleculeMx.ConvertTo(o));

            case MetaColumnType.Image:
                return(ImageMx.ConvertTo(o));                        // assume text is dblink

            default:
                throw new Exception("Unrecognized data type: " + type);
            }
        }
Exemplo n.º 8
0
        /////////////////////////////////////////////////////////////////
        //////////////////////////// Methods ////////////////////////////
        /////////////////////////////////////////////////////////////////

/// <summary>
/// Create a Mobius data type based on the supplied MetaColumn type
/// </summary>
/// <param name="type"></param>
/// <returns></returns>

        public static MobiusDataType New(
            MetaColumnType type)
        {
            MobiusDataType o;

            if (type == MetaColumnType.Integer)
            {
                o = new NumberMx();
            }
            else if (type == MetaColumnType.Number)
            {
                o = new NumberMx();
            }
            else if (type == MetaColumnType.QualifiedNo)
            {
                o = new QualifiedNumber();
            }
            else if (type == MetaColumnType.String)
            {
                o = new StringMx();
            }
            else if (type == MetaColumnType.Date)
            {
                o = new DateTimeMx();
            }
            else if (type == MetaColumnType.Binary)
            {
                o = new StringMx();
            }
            else if (type == MetaColumnType.CompoundId)
            {
                o = new CompoundId();
            }
            else if (type == MetaColumnType.Structure)
            {
                o = new MoleculeMx();
            }
            else if (type == MetaColumnType.MolFormula)
            {
                o = new StringMx();
            }
            else if (type == MetaColumnType.Image)
            {
                o = new ImageMx();
            }
            else if (type == MetaColumnType.DictionaryId)
            {
                o = new NumberMx();
            }
            else if (type == MetaColumnType.Hyperlink)
            {
                o = new StringMx();
            }
            else if (type == MetaColumnType.Html)
            {
                o = new StringMx();
            }
            else
            {
                throw new Exception("Unrecognized data type: " + type);
            }

            return(o);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Custom compact Deserialization of MobiusDataType
        /// </summary>
        /// <returns></returns>

        public static MobiusDataType Deserialize(string[] sa)
        {
            int sai;

            MobiusDataType mdt  = null;
            char           type = sa[0][0];

            sai = 5;             // first array entry for specific subclass

            switch (type)
            {
            case 'M':                     // ChemicalStructure (Molecule)
                mdt = MoleculeMx.Deserialize(sa, sai);
                break;

            case 'C':                     // CompoundId
                mdt = CompoundId.Deserialize(sa, sai);
                break;

            case 'D':                     // DateTimeEx
                mdt = DateTimeMx.Deserialize(sa, sai);
                break;

            case 'I':                     // ImageEx
                mdt = ImageMx.Deserialize(sa, sai);
                break;

            case 'N':                     //NumberEx
                mdt = NumberMx.Deserialize(sa, sai);
                break;

            case 'Q':                     // QualifiedNumber
                mdt = QualifiedNumber.Deserialize(sa, sai);
                break;

            case 'S':                     // StringEx
                mdt = StringMx.Deserialize(sa, sai);
                break;

            default:
                throw new Exception("Unexpected MobiusDataType: " + type);
            }

            if (!Lex.IsNullOrEmpty(sa[1]))
            {
                mdt.BackColor = Color.FromArgb(int.Parse(sa[1]));
            }

            if (!Lex.IsNullOrEmpty(sa[2]))
            {
                mdt.ForeColor = Color.FromArgb(int.Parse(sa[2]));
            }

            if (!Lex.IsNullOrEmpty(sa[3]))
            {
                mdt.DbLink = sa[3];
            }

            if (!Lex.IsNullOrEmpty(sa[4]))
            {
                mdt.Hyperlink = sa[4];
            }

            return(mdt);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Compare two qualified numbers (IComparable.CompareTo)
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>

        public override int CompareTo(
            object o)
        {
            double compVal = NullNumber;

            if (o == null)
            {
                compVal = NullNumber;
            }

            else if (o is int)
            {
                compVal = (int)o;
            }

            else if (o is double)
            {
                compVal = (double)o;
            }

            else if (o is StringMx)
            {
                StringMx sx = o as StringMx;
                string   s  = this.TextValue;
                if (s == null)
                {
                    s = "";
                }
                return(s.CompareTo(sx.Value));
            }

            else if (o is MobiusDataType)
            {
                compVal = ((MobiusDataType)o).NumericValue;
            }

            else
            {
                throw new Exception("Can't compare a " + GetType().Name + " to a " + o.GetType());
            }

            if (this.NumberValue != NullNumber && compVal != NullNumber)             // both not null
            {
                return(this.NumberValue.CompareTo(compVal));
            }

            else if (this.NumberValue == NullNumber && compVal == NullNumber) // both null
            {
                if (o is QualifiedNumber)                                     // if object is QN compare any string values ignoring case
                {
                    return(String.Compare(this.TextValue, ((QualifiedNumber)o).TextValue, true));
                }
                else
                {
                    return(0);                 // say equal otherwise
                }
            }

            else if (this.NumberValue != NullNumber) // this not null, compValue is null
            {
                return(-1);                          // indicate this is less (put non-null first)
            }
            else                                     // compValue not null, this is null
            {
                return(1);                           // indicate that this is greater (put non-null first)
            }
        }
Exemplo n.º 11
0
        public void ToValueObject(
            object[] vo,
            TargetAssayAttrsFieldPositionMap voi)
        {
            AssayAttributes row = this;

            SetVo(vo, voi.Id.Voi, row.Id);

            SetVo(vo, voi.TargetSymbol.Voi, row.GeneSymbol);
            SetVo(vo, voi.TargetId.Voi, row.GeneId);
            SetVo(vo, voi.TargetDescription.Voi, row.GeneDescription);
            SetVo(vo, voi.GeneFamily.Voi, row.GeneFamily);
            SetVo(vo, voi.GeneFamilyTargetSymbol.Voi, row.GeneFamilyTargetSymbol);

            SetVo(vo, voi.AssayType.Voi, row.AssayType);
            SetVo(vo, voi.AssayMode.Voi, row.AssayMode);

            if (Lex.IsNullOrEmpty(row.AssayLink))             // if no link info use simple string value
            {
                SetVo(vo, voi.AssayName.Voi, row.AssayName);
            }
            else
            {
                StringMx sx = new StringMx(row.AssayName);
                sx.Hyperlink = row.AssayLink;
                SetVo(vo, voi.AssayName.Voi, sx);
            }

            SetVo(vo, voi.AssayDesc.Voi, row.AssayDesc);
            SetVo(vo, voi.AssayDatabase.Voi, row.AssayDatabase);
            SetVo(vo, voi.AssayLocation.Voi, row.AssaySource);
            SetVo(vo, voi.AssayId2.Voi, row.AssayId2);
            SetVo(vo, voi.AssayIdNbr.Voi, row.AssayIdNbr);
            SetVo(vo, voi.AssayIdTxt.Voi, row.AssayIdTxt);
            SetVo(vo, voi.ResultTypeUnits.Voi, row.ResultTypeUnits);
            SetVo(vo, voi.ResultTypeConcUnits.Voi, row.ResultTypeConcUnits);

            SetVo(vo, voi.AssayMetaTableName.Voi, row.AssayMetaTableName);
            SetVo(vo, voi.AssayStatus.Voi, row.AssayStatus);
            SetVo(vo, voi.AssayGeneCount.Voi, row.GeneCount);

            SetVo(vo, voi.ResultTypeConcType.Voi, row.ResultTypeConcType);
            SetVo(vo, voi.ResultName.Voi, row.ResultName);
            SetVo(vo, voi.ResultTypeId2.Voi, row.ResultTypeId2);
            SetVo(vo, voi.ResultTypeIdNbr.Voi, row.ResultTypeIdNbr);
            SetVo(vo, voi.ResultTypeIdTxt.Voi, row.ResultTypeIdTxt);
            SetVo(vo, voi.TopLevelResult.Voi, row.TopLevelResult);

            SetVo(vo, voi.Remapped.Voi, row.Remapped);
            SetVo(vo, voi.Multiplexed.Voi, row.Multiplexed);
            SetVo(vo, voi.Reviewed.Voi, row.Reviewed);
            SetVo(vo, voi.ProfilingAssay.Voi, row.ProfilingAssay);
            SetVo(vo, voi.CompoundsAssayed.Voi, row.CompoundsAssayed);

            SetVo(vo, voi.ResultCount.Voi, row.ResultCount);
            SetVo(vo, voi.AssayUpdateDate.Voi, row.AssayUpdateDate);
            SetVo(vo, voi.AssociationSource.Voi, row.AssociationSource);
            SetVo(vo, voi.AssociationConflict.Voi, row.AssociationConflict);

            SetVo(vo, voi.TargetMapX.Voi, row.TargetMapX);
            SetVo(vo, voi.TargetMapY.Voi, row.TargetMapY);
            SetVo(vo, voi.TargetMapZ.Voi, row.TargetMapZ);
            return;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Convert a value objectarray into a TargetAssayAttributes
        /// </summary>
        /// <param name="vo"></param>
        /// <param name="voMap"></param>
        /// <returns></returns>

        public void FromValueObject(
            object[] vo,
            TargetAssayAttrsFieldPositionMap voMap)
        {
            string key;

            AssayAttributes row = this;

            row.Id = GetIntVo(vo, voMap.Id.Voi);

            row.GeneSymbol             = GetStringVo(vo, voMap.TargetSymbol.Voi);
            row.GeneId                 = GetIntVo(vo, voMap.TargetId.Voi);
            row.GeneDescription        = GetStringVo(vo, voMap.TargetDescription.Voi);
            row.GeneFamily             = GetStringVo(vo, voMap.GeneFamily.Voi);
            row.GeneFamilyTargetSymbol = GetStringVo(vo, voMap.GeneFamilyTargetSymbol.Voi);

            row.AssayType = GetStringVo(vo, voMap.AssayType.Voi);
            row.AssayMode = GetStringVo(vo, voMap.AssayMode.Voi);

            object obj = GetObjectVo(vo, voMap.AssayName.Voi);

            if (obj != null)
            {
                if (obj is string)
                {
                    row.AssayName = (string)obj;
                }
                else if (obj is StringMx)
                {
                    StringMx sx = obj as StringMx;
                    row.AssayName = sx.Value;

                    if (sx.DbLink.Contains(","))
                    {
                        string mtName = sx.DbLink.Replace(",", "_").ToUpper();
                        row.AssayMetaTableName = mtName;
                    }
                }
            }

            row.AssayDesc     = GetStringVo(vo, voMap.AssayDesc.Voi);
            row.AssayDatabase = GetStringVo(vo, voMap.AssayDatabase.Voi);
            row.AssaySource   = GetStringVo(vo, voMap.AssayLocation.Voi);
            row.AssayId2      = GetIntVo(vo, voMap.AssayId2.Voi);
            row.AssayIdNbr    = GetIntVo(vo, voMap.AssayIdNbr.Voi);
            row.AssayIdTxt    = GetStringVo(vo, voMap.AssayIdTxt.Voi);

            string txt = GetStringVo(vo, voMap.AssayMetaTableName.Voi);

            if (txt != null)
            {
                row.AssayMetaTableName = txt;
            }

            row.AssayStatus = GetStringVo(vo, voMap.AssayStatus.Voi);
            row.GeneCount   = GetIntVo(vo, voMap.AssayGeneCount.Voi);

            row.ResultName          = GetStringVo(vo, voMap.ResultName.Voi);
            row.ResultTypeId2       = GetIntVo(vo, voMap.ResultTypeId2.Voi);
            row.ResultTypeIdNbr     = GetIntVo(vo, voMap.ResultTypeIdNbr.Voi);
            row.ResultTypeIdTxt     = GetStringVo(vo, voMap.ResultTypeIdTxt.Voi);
            row.ResultTypeConcType  = GetStringVo(vo, voMap.ResultTypeConcType.Voi);
            row.ResultTypeUnits     = GetStringVo(vo, voMap.ResultTypeUnits.Voi);
            row.ResultTypeConcUnits = GetStringVo(vo, voMap.ResultTypeConcUnits.Voi);
            row.TopLevelResult      = GetStringVo(vo, voMap.TopLevelResult.Voi);

            row.Remapped         = GetStringVo(vo, voMap.Remapped.Voi);
            row.Multiplexed      = GetStringVo(vo, voMap.Multiplexed.Voi);
            row.Reviewed         = GetStringVo(vo, voMap.Reviewed.Voi);
            row.ProfilingAssay   = GetStringVo(vo, voMap.ProfilingAssay.Voi);
            row.CompoundsAssayed = GetIntVo(vo, voMap.CompoundsAssayed.Voi);

            row.ResultCount         = GetIntVo(vo, voMap.ResultCount.Voi);
            row.AssayUpdateDate     = GetDateVo(vo, voMap.AssayUpdateDate.Voi);
            row.AssociationSource   = GetStringVo(vo, voMap.AssociationSource.Voi);
            row.AssociationConflict = GetStringVo(vo, voMap.AssociationConflict.Voi);

            row.TargetMapX = GetDoubleVo(vo, voMap.TargetMapX.Voi);
            row.TargetMapY = GetDoubleVo(vo, voMap.TargetMapY.Voi);
            row.TargetMapZ = GetDoubleVo(vo, voMap.TargetMapZ.Voi);

            // Complete assignment any missing assay database and/or assay id information

            AssayDict tad = AssayDict.Instance;             // dict used for various lookups

            if (Lex.IsNullOrEmpty(row.AssayIdTxt) && row.AssayId2 == NullValue.NullNumber)
            {             // try to assign from assay name
                if (!Lex.IsNullOrEmpty(row.AssayName) && tad != null)
                {
                    key = row.AssayName.Trim().ToUpper();
                    if (tad.AssayNameMap.ContainsKey(key))
                    {
                        AssayAttributes taa = tad.AssayNameMap[key];
                        row.AssayDatabase = taa.AssayDatabase;
                        row.AssayId2      = taa.AssayId2;
                        row.AssayIdNbr    = taa.AssayIdNbr;
                        row.AssayIdTxt    = taa.AssayIdTxt;
                    }
                }
            }

            else if (Lex.IsNullOrEmpty(row.AssayIdTxt))
            {
                row.AssayIdTxt = row.AssayId2.ToString();
            }

            else if (row.AssayId2 == NullValue.NullNumber)
            {
                int.TryParse(row.AssayIdTxt, out row.AssayId2);
            }

            // Complete any missing target information if target dict is available

            if (tad != null)
            {
                if (Lex.IsNullOrEmpty(row.GeneSymbol) && row.GeneId == NullValue.NullNumber)                 // assign target from assay info
                {
                    if (!Lex.IsNullOrEmpty(row.AssayDatabase) && !Lex.IsNullOrEmpty(row.AssayIdTxt))
                    {
                        key = row.AssayDatabase.ToUpper() + "-" + row.AssayIdTxt.ToUpper();

                        if (tad.DatabaseAssayIdMap.ContainsKey(key))
                        {
                            row.GeneSymbol = tad.DatabaseAssayIdMap[key].GeneSymbol;
                            row.GeneId     = tad.DatabaseAssayIdMap[key].GeneId;
                        }
                    }
                }

                else if (Lex.IsNullOrEmpty(row.GeneSymbol))                 // assign symbol from targetid
                {
                    if (tad.TargetIdMap.ContainsKey(row.GeneId))
                    {
                        row.GeneSymbol = tad.TargetIdMap[row.GeneId].GeneSymbol;
                    }
                }

                else if (row.GeneId == NullValue.NullNumber)                 // assign targetId from symbol
                {
                    string geneSymbol = row.GeneSymbol.ToUpper();
                    if (tad.TargetSymbolMap.ContainsKey(geneSymbol))
                    {
                        //geneSymbol = "EPHB1"; // debug
                        //geneSymbol = "AKT3"; // debug
                        row.GeneId = tad.TargetSymbolMap[geneSymbol].GeneId;
                    }
                }
            }

            return;
        }
Exemplo n.º 13
0
/// <summary>
/// Deserialize a single value object
/// </summary>
/// <param name="ba"></param>
/// <returns></returns>

        public static object ReadBinaryItem(
            BinaryReader br)
        {
            object     vo     = null;
            VoDataType voType = (VoDataType)br.ReadByte();

            switch (voType)
            {
            case VoDataType.Null:
                return(null);

            case VoDataType.DbNull:
                return(DBNull.Value);

            case VoDataType.Byte:
                return(br.ReadByte());

            case VoDataType.Int16:
                return(br.ReadInt16());

            case VoDataType.Int32:
                return(br.ReadInt32());

            case VoDataType.Int64:
                return(br.ReadInt64());

            case VoDataType.Float:
                return(br.ReadSingle());

            case VoDataType.Double:
                return(br.ReadDouble());

            case VoDataType.Char:
                return(br.ReadChar());

            case VoDataType.String:
                return(br.ReadString());

            case VoDataType.DateTime:
                return(new DateTime(br.ReadInt64()));

            case VoDataType.CompoundId:
                return(CompoundId.DeserializeBinary(br));

            case VoDataType.NumberMx:
                return(NumberMx.DeserializeBinary(br));

            case VoDataType.QualifiedNo:
                return(QualifiedNumber.DeserializeBinary(br));

            case VoDataType.StringMx:
                return(StringMx.DeserializeBinary(br));

            case VoDataType.DateTimeMx:
                return(DateTimeMx.DeserializeBinary(br));

            case VoDataType.ImageMx:
                return(ImageMx.DeserializeBinary(br));

            case VoDataType.ChemicalStructure:
                return(MoleculeMx.DeserializeBinary(br));

            default:
                throw new Exception("Unrecognized type: " + voType);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Compare two values (IComparable.CompareTo)
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>

        public override int CompareTo(
            object o)
        {
// First convert o to a double value

            double compVal = NullNumber;

            if (o == null)
            {
                compVal = NullNumber;
            }

            else if (o is int)
            {
                compVal = (int)o;
            }

            else if (o is long)
            {
                compVal = (long)o;
            }

            else if (o is float)
            {
                compVal = (float)o;
            }

            else if (o is double)
            {
                compVal = (double)o;
            }

            else if (o is decimal)
            {
                compVal = decimal.ToDouble((decimal)o);
            }

            else if (o is double)
            {
                compVal = (double)o;
            }

            else if (o is string)
            {
                if (!NumberEx.DoubleTryParseEx((string)o, out compVal))
                {
                    compVal = NullNumber;
                }
            }

            else if (o is StringMx)
            {
                StringMx sx = o as StringMx;
                if (!NumberEx.DoubleTryParseEx(sx?.Value, out compVal))
                {
                    compVal = NullNumber;
                }
            }

            else if (o is MobiusDataType)
            {
                compVal = ((MobiusDataType)o).NumericValue;
            }

            else
            {
                throw new Exception("Can't compare a " + GetType().Name + " to a " + o.GetType());
            }

// Now compare compVal to this NumberMx value

            if (this.Value != NullNumber && compVal != NullNumber)             // both not null
            {
                return(this.Value.CompareTo(compVal));
            }

            else if (this.Value == NullNumber && compVal == NullNumber) // both null
            {
                return(0);                                              // say equal
            }
            else if (this.Value != NullNumber)                          // this not null, compValue is null
            {
                return(-1);                                             // indicate this is less (put non-null first)
            }
            else                                                        // compValue not null, this is null
            {
                return(1);                                              // indicate that this is greater (put non-null first)
            }
        }
Exemplo n.º 15
0
/// <summary>
/// Custom Compact deserialization
/// </summary>
/// <param name="sa"></param>
/// <param name="sai"></param>
/// <returns></returns>

        public static StringMx Deserialize(string[] sa, int sai)
        {
            StringMx sx = new StringMx(sa[sai]);

            return(sx);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Compare two values (IComparable.CompareTo)
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>

        public override int CompareTo(
            object o)
        {
            if (o == null)
            {
                return(1);
            }

            StringMx sx = this;

            if (o is StringMx)
            {
                StringMx sx2 = o as StringMx;

                if (sx.IsNull && sx2.IsNull)
                {
                    return(0);
                }
                else if (!sx.IsNull && sx2.IsNull)
                {
                    return(1);
                }
                else if (sx.IsNull && !sx2.IsNull)
                {
                    return(-1);
                }
                else
                {
                    return(string.Compare(sx.Value, sx2.Value, true));                 // compare ignoring case
                }
            }

            else if (o is QualifiedNumber)
            {
                QualifiedNumber qn = o as QualifiedNumber;
                if (sx.IsNull && qn.IsNull)
                {
                    return(0);
                }
                else if (!sx.IsNull && qn.IsNull)
                {
                    return(1);
                }
                else if (sx.IsNull && !qn.IsNull)
                {
                    return(-1);
                }
                return(string.Compare(this.Value, qn.TextValue, true));                // compare ignoring case
            }

            else if (o is string)
            {
                string s = (string)o;
                if (sx.IsNull)
                {
                    if (o == null)
                    {
                        return(0);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(string.Compare(sx.Value, s, true));
                }
            }

            else
            {
                throw new Exception("Can't compare a " + GetType().Name + " to a " + o.GetType());
            }
        }