コード例 #1
0
        /// <summary>
        /// Build a PDB file.
        /// </summary>
        /// <param name="dstDir">Destination Directory.</param>
        /// <param name="key">Index key.</param>
        /// <param name="list">Index list.</param>
        /// <returns>Returns the full path to the file.</returns>
        public string BuildPDBFile(string dstDir, int key, ArrayList list)
        {
            string      prevSurname = null, pdbName = "index" + hexChars[((key >> 4) & 0xf)] + hexChars[(key & 0x0f)];
            ByteBuilder bb     = new ByteBuilder(8192);
            int         recIdx = 0;
            Person      p;
            PDB         pdb;

            wizard.cStatus.Text = "Creating PDB file: " + pdbName;
            wizard.cProgressBar.PerformStep();
            Application.DoEvents();

            pdb = new PDB(pdbName);
            for (int i = 0; i < list.Count; i++)
            {
                p = (Person)list[i];
                if (prevSurname == null)
                {
                    prevSurname = p.iSurname;
                    bb.Append(p.iSurname);
                    bb.Append(0);
                    AppendPerson(recIdx, key, bb, p);
                }
                else if (p.iSurname.CompareTo(prevSurname) == 0)
                {
                    AppendPerson(recIdx, key, bb, p);
                }
                else
                {
                    pdb.AddRecord(bb.ToBytes());
                    recIdx++;
                    bb.Reset();
                    prevSurname = p.iSurname;
                    bb.Append(p.iSurname);
                    bb.Append(0);
                    AppendPerson(recIdx, key, bb, p);
                }
            }

            if (bb.Count > 0)
            {
                pdb.AddRecord(bb.ToBytes());
            }

            pdb.Write(dstDir);
            return(pdb.fullPath);
        }
コード例 #2
0
ファイル: Person.cs プロジェクト: bschau/Portfolio
        /// <summary>
        /// Store a packed representation of the email address for this person into
        /// the bytebuilder.
        /// </summary>
        /// <param name="bb">ByteBuilder</param>
        public void GetCrunchedEmail(ByteBuilder bb)
        {
            bool   isHPDomain = false;
            int    mailboxNameType = 0, atPos;
            string gN, gNDash, sNDash, sN, mbName, dmName;

            if ((atPos = iEmail.IndexOf("@", 0)) == -1)
            {
                bb.Append(0);
                return;
            }

            mbName = iEmail.Substring(0, atPos).ToLower();
            dmName = iEmail.Substring(atPos + 1).ToLower();
            gN     = iGivenname.ToLower();
            sN     = iSurname.ToLower();
            gNDash = iGivenname.Replace(" ", "-");
            sNDash = iSurname.Replace(" ", "-");

            if (mbName.CompareTo(gN + "." + sN) == 0)
            {
                mailboxNameType = 2;
            }
            else if (mbName.CompareTo(gN + "_" + sN) == 0)
            {
                mailboxNameType = 3;
            }
            else if (mbName.CompareTo(gNDash + "." + sNDash) == 0)
            {
                mailboxNameType = 4;
            }
            else if (mbName.CompareTo(gNDash + "_" + sNDash) == 0)
            {
                mailboxNameType = 5;
            }
            else if (mbName.CompareTo(gN + sN) == 0)
            {
                mailboxNameType = 6;
            }
            else if (mbName.CompareTo(gNDash + sNDash) == 0)
            {
                mailboxNameType = 7;
            }
            else if (mbName.CompareTo(sN + "." + gN) == 0)
            {
                mailboxNameType = 8;
            }
            else if (mbName.CompareTo(sN + "_" + gN) == 0)
            {
                mailboxNameType = 9;
            }
            else if (mbName.CompareTo(sNDash + "." + gNDash) == 0)
            {
                mailboxNameType = 10;
            }
            else if (mbName.CompareTo(sNDash + "_" + gNDash) == 0)
            {
                mailboxNameType = 11;
            }
            else if (mbName.CompareTo(sN + gN) == 0)
            {
                mailboxNameType = 12;
            }
            else if (mbName.CompareTo(sNDash + gNDash) == 0)
            {
                mailboxNameType = 13;
            }

            if (dmName.CompareTo("hp.com") == 0)
            {
                isHPDomain = true;
            }

            if (mailboxNameType == 0)
            {
                if (isHPDomain == false)
                {
                    bb.Append(32);
                    bb.Append(iEmail);
                }
                else
                {
                    bb.Append(16);
                    bb.Append(mbName);
                }
            }
            else
            {
                if (isHPDomain == true)
                {
                    mailboxNameType |= 16;
                    bb.Append((byte)mailboxNameType);
                }
                else
                {
                    bb.Append((byte)mailboxNameType);
                    bb.Append(dmName);
                }
            }
        }
コード例 #3
0
ファイル: Person.cs プロジェクト: bschau/Portfolio
        /// <summary>
        /// Compact a string representation of a Phone number to packed bytes.
        /// </summary>
        /// <param name="bb">ByteBuilder.</param>
        /// <param name="src">Source (with phone no.#).</param>
        /// <returns>The bytearray with the packed number.</returns>
        private byte[] CrunchPhone(ByteBuilder bb, string src)
        {
            StringBuilder sb  = new StringBuilder();
            bool          ext = false;
            int           idx;
            char          c;
            byte          b;

            for (idx = 0; idx < src.Length; idx++)
            {
                c = src[idx];
                if (c >= '0' && c <= '9')
                {
                    sb.Append(c);
                }
                else if (c == ' ' || c == '+')
                {
                    continue;
                }
                else if (ext == false)
                {
                    sb.Append('e');
                    ext = true;
                }
            }

            src = sb.ToString();

            bb.Reset();

            idx = src.Length - 1;
            while (idx > -1)
            {
                c = src[idx];
                if (c >= '0' && c <= '9')
                {
                    b = (byte)((c - '0') << 4);
                }
                else
                {
                    b = 176;
                }

                idx--;
                if (idx < 0)
                {
                    b |= 12;
                    bb.Append(b);
                    break;
                }

                c = src[idx];
                if (c >= '0' && c <= '9')
                {
                    b |= (byte)(c - '0');
                }
                else
                {
                    b |= 11;
                }

                bb.Append(b);
                idx--;
            }

            if (bb.Count > 0)
            {
                return(bb.ToBytes(255));
            }

            return(null);
        }
コード例 #4
0
        /// <summary>
        /// Write the phone databases.
        /// <param name="dstDir">Destination directory.</param>
        /// </summary>
        public void WritePhoneDBs(string dstDir)
        {
            string      prevKey = "", curKey;
            ByteBuilder bb = new ByteBuilder(32);
            SortedList  sl;
            int         i, j, x;
            Person      p;
            string      phone;
            PDB         pdb;
            int         idx;
            byte        b;

            for (i = 0; i < 10; i++)
            {
                sl = slPhones[i];

                if (sl.Count == 0)
                {
                    continue;
                }

                wizard.cStatus.Text = "Writing Phone database " + (i + 1);
                wizard.cProgressBar.PerformStep();

                pdb = new PDB("phones" + (char)(i + '0'));
                bb.Reset();

                for (j = 0; j < sl.Count; j++)
                {
                    Application.DoEvents();
                    if (fWizard.appStopped)
                    {
                        return;
                    }

                    phone = (string)sl.GetKey(j);
                    p     = (Person)sl.GetByIndex(j);

                    curKey = phone.Substring(1, 2);
                    phone  = phone.Substring(3);

                    if ((curKey != prevKey) || (bb.Count > 64000))
                    {
                        if (bb.Count > 0)
                        {
                            pdb.AddRecord(bb.ToBytes());
                            bb.Reset();
                        }
                        prevKey = curKey;
                        bb.Append(curKey);
                    }

                    bb.Append((ushort)p.pRecIndex);
                    bb.Append((ushort)p.pOffset);
                    bb.Append((byte)p.pKey);

                    idx = phone.Length >> 1;
                    if ((phone.Length & 1) == 1)
                    {
                        idx++;
                    }
                    bb.Append((byte)idx);

                    for (idx = 0; idx < ((phone.Length >> 1) << 1);)
                    {
                        x  = (phone[idx++] - '0') << 4;
                        b  = (byte)x;
                        x  = (phone[idx++] - '0');
                        b |= (byte)x;
                        bb.Append(b);
                    }

                    if (idx < phone.Length)
                    {
                        bb.Append((byte)((phone[idx] - '0') << 4));
                    }
                }

                if (bb.Count > 0)
                {
                    pdb.AddRecord(bb.ToBytes());
                }

                pdb.Write(dstDir);
                InstallFile(wizard.config.palmProfile, pdb.fullPath);
            }
        }
コード例 #5
0
        /// <summary>
        /// Add a person to the record list.
        /// </summary>
        /// <param name="rIdx">Index.</param>
        /// <param name="key">Key.</param>
        /// <param name="bb">Byte Builder.</param>
        /// <param name="p">Person.</param>
        private void AppendPerson(int rIdx, int key, ByteBuilder bb, Person p)
        {
            int addrIdx = p.addrIdx;

            p.pKey      = key;
            p.pRecIndex = rIdx;
            p.pOffset   = bb.Count;

            mgr.RecordMgr(rIdx, bb.Count, key, p.iEmail);

            bb.Append((ushort)p.mgrIdx);

            bb.Append((byte)p.iGivenname.Length);
            bb.Append(p.iGivenname);

            if (p.iPhone != null)
            {
                bb.Append((byte)p.iPhone.Length);
                bb.Append(p.iPhone);
            }
            else
            {
                bb.Append(0);
            }

            if (p.iMobile != null)
            {
                bb.Append((byte)p.iMobile.Length);
                bb.Append(p.iMobile);
            }
            else
            {
                bb.Append(0);
            }

            bb.Append((ushort)addrIdx);

            p.GetCrunchedEmail(bb);
            bb.Append(0);                               // Must follow CrunchedEmail, must be last!
        }