Ejemplo n.º 1
0
        /// <summary>
        /// Deserialize compound id list
        /// </summary>
        /// <returns></returns>

        public static CidList Deserialize(
            UserObject uo,
            MetaTable mt)
        {
            CidList cidList = new CidList();

            string[] sa = uo.Content.Split('\n');
            for (int i1 = 0; i1 < sa.Length; i1++)
            {
                string cid = sa[i1];
                if (cid.IndexOf("\r") >= 0)
                {
                    cid = cid.Replace("\r", "");
                }
                if (cid.IndexOf(" ") >= 0)
                {
                    cid = cid.Replace(" ", "");
                }
                if (cid == "")
                {
                    continue;
                }
                cid = CompoundId.Normalize(cid, mt);
                cidList.Add(cid, true);                 // add allowing duplicates
            }

            cidList.UserObject = uo;
            return(cidList);            // return the list
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Custom Compact deserialization
        /// </summary>
        /// <param name="sa"></param>
        /// <param name="sai"></param>
        /// <returns></returns>

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

            cid.Value = sa[sai];
            return(cid);
        }
Ejemplo n.º 3
0
/// <summary>
/// Read a compound id from a list file
/// </summary>
/// <param name="csf"></param>
/// <returns></returns>

        public static string ReadCidFromFile(
            StreamReader csf)
        {
            string cn;

            while (true)
            {
                cn = csf.ReadLine();
                if (cn == null)
                {
                    return(null);
                }
                if (cn.IndexOf("\r") >= 0)
                {
                    cn = cn.Replace("\r", "");
                }
                if (cn.IndexOf(" ") >= 0)
                {
                    cn = cn.Replace(" ", "");
                }
                if (cn == "")
                {
                    continue;
                }
                cn = CompoundId.Normalize(cn);
                return(cn);
            }
        }
Ejemplo n.º 4
0
/// <summary>
/// Get string with one list element per row
/// </summary>
/// <param name="removeLeadingZerosFromCids"></param>
/// <returns></returns>

        public string ToMultilineString(
            bool removeLeadingZerosFromCids)
        {
            string        cid;
            int           cncnt = 0, intCid;
            StringBuilder sb = new StringBuilder();

            foreach (CidListElement e in List)
            {
                if (e.Cid != "")
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("\r\n");
                    }
                    cid = e.Cid;
                    if (removeLeadingZerosFromCids && int.TryParse(cid, out intCid))
                    {
                        cid = intCid.ToString();
                    }
                    else
                    {
                        cid = CompoundId.Normalize(cid);
                    }
                    sb.Append(cid);
                    cncnt++;
                }
            }

            //string csvForm = ToListString(removeLeadingZerosFromCids, false); // debug
            return(sb.ToString());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Binary Deserialize
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>

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

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

        public new CompoundId Clone()
        {
            CompoundId cid = (CompoundId)this.MemberwiseClone();

            if (cid.MdtExAttr != null)
            {
                cid.MdtExAttr = MdtExAttr.Clone();
            }
            return(cid);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Build a csv string of formatted compound ids
        /// </summary>
        /// <param name="qc"></param>
        /// <param name="list"></param>
        /// <returns></returns>

        public static string BuildListCsvStringOfFormattedCids(
            QueryColumn qc,
            List <string> list)
        {
            int li, rem;

            List <string> fList = new List <string>();

            for (li = 0; li < list.Count; li++)
            {
                string cid = list[li];
                if (qc != null && qc.QueryTable != null && qc.QueryTable.MetaTable != null)
                {
                    string fCid = CompoundId.Format(cid, qc.QueryTable.MetaTable);
                    fList.Add(fCid);
                    list[li] = fCid;                     // also store back in supplied List<string>
                }

                else
                {
                    fList.Add(cid);
                }
            }

            string csvString = Csv.JoinCsvString(fList);

            if (DebugMx.False)             // debug - create a list of sublists for testing
            {
                StringBuilder sb = new StringBuilder();
                for (li = 0; li < list.Count; li++)
                {
                    string cid = list[li];
                    Math.DivRem(li, 100, out rem);
                    if (rem == 0)
                    {
                        sb.Append("\r\n");
                    }
                    else
                    {
                        sb.Append(",");
                    }
                    sb.Append(cid);
                }

                string s = sb.ToString();
            }

            return(csvString);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Match a CompoundId value (not currently used)
        /// </summary>
        /// <param name="rules"></param>
        /// <param name="dtValue"></param>
        /// <returns></returns>

        public static CondFormatRule Match(
            CondFormat condFormat,
            CompoundId cid)
        {
            CondFormatRules rules = condFormat.Rules;
            CondFormatRule  rule  = null;
            CidList         cidList;
            int             ri, objId;

            for (ri = 0; ri < rules.Count; ri++)
            {
                rule = rules[ri];
                if (rule.ValueDict == null)                             // read in cid list if not done yet
                {
                    rule.ValueDict = new Dictionary <string, object>(); // set empty dict so if fails we won't try again
                    if (!int.TryParse(rule.Value2, out objId))
                    {
                        continue;
                    }
                    if (CidList.ICidListDao == null)
                    {
                        continue;
                    }
                    cidList = CidList.ICidListDao.VirtualRead(objId, null);
                    rule.ValueDict["CidList"] = cidList;
                }

                cidList = rule.ValueDict["CidList"] as CidList;
                if (cidList.Contains(cid.Value))
                {
                    break;
                }
            }

            if (ri < rules.Count)
            {
                return(rule);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Compare two values (IComparable.CompareTo)
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>

        public override int CompareTo(
            object o)
        {
            CompoundId s = this;

            if (o == null)
            {
                return(1);
            }

            else if (o is CompoundId)
            {
                CompoundId s2 = o as CompoundId;

                if (s.IsNull && s2.IsNull)
                {
                    return(0);
                }
                else if (!s.IsNull && s2.IsNull)
                {
                    return(1);
                }
                else if (s.IsNull && !s2.IsNull)
                {
                    return(-1);
                }
                else
                {
                    return(s.Value.CompareTo(s2.Value));
                }
            }

            else
            {
                return(s.Value.CompareTo(o.ToString()));             // convert object to string & compare to Cid
            }
            //throw new Exception("Can't compare a " + GetType().Name + " to a " + o.GetType());
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
/// <summary>
/// Convert list to comma separated form
/// </summary>
/// <param name="removeLeadingZerosFromCids"></param>
/// <param name="quoteItems"></param>
/// <returns></returns>

        public string ToListString(
            bool removeLeadingZerosFromCids,
            bool quoteItems)
        {
            string        cid;
            int           cncnt = 0, intCid;
            StringBuilder sb = new StringBuilder();

            foreach (CidListElement e in List)
            {
                if (e.Cid != "")
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(",");
                    }
                    cid = e.Cid;
                    if (removeLeadingZerosFromCids && int.TryParse(cid, out intCid))
                    {
                        cid = intCid.ToString();
                    }
                    else
                    {
                        cid = CompoundId.Normalize(cid);
                    }
                    if (quoteItems)
                    {
                        cid = Lex.AddSingleQuotes(cid);
                    }
                    sb.Append(cid);
                    cncnt++;
                }
            }

            return(sb.ToString());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Sort a compound number list
        /// </summary>
        /// <param name="sortDirection"></param>

        public void Sort(
            SortOrder sortDirection)
        {
            IComparer <CidListElement> comparer;
            CidListElement             e;
            int i1;

            for (i1 = 0; i1 < List.Count; i1++)
            {             // convert numbers to sortable form and store in StringTag
                e           = (CidListElement)List[i1];
                e.StringTag = CompoundId.Normalize(e.Cid);
            }

            if (sortDirection == SortOrder.Ascending)
            {
                comparer = new CnComparer();
            }
            else
            {
                comparer = new CnReverseComparer();
            }

            List.Sort(comparer);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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);
            }
        }