Ejemplo n.º 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);
        }
Ejemplo n.º 2
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!
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Setup a new Person record.
        /// </summary>
        /// <param name="addr">Address.</param>
        /// <param name="mgr">Manager ID.</param>
        /// <param name="src">Source line.</param>
        /// <param name="r">Regex (to split src).</param>
        /// <param name="u">User ID.</param>
        public Person(Address addr, Manager mgr, string src, Regex r, long u)
        {
            ByteBuilder bb = new ByteBuilder(64);

            string[] p   = r.Split(src);
            string   s   = "";
            string   phn = null;

            if (p.Length == 11)
            {
                if (p[(int)Index.ECARDID].Length > 0)
                {
                    iEmail = p[(int)Index.ECARDID].ToLower();
                }
                else
                {
                    iEmail = "";
                }

                if ((iSurname = p[(int)Index.SURNAME].ToLower()).Length > 255)
                {
                    iSurname = iSurname.Substring(0, 255);
                }

                if ((iGivenname = p[(int)Index.GIVENNAME].ToLower()).Length > 255)
                {
                    iGivenname = iGivenname.Substring(0, 255);
                }

                if (((phn = p[(int)Index.PHONE]) == null) || (phn.Length == 0))
                {
                    phn = "";
                }
                else
                {
                    phn = p[(int)Index.PHONE];
                }

                cPhone = CleanReversePhone(phn);
                iPhone = CrunchPhone(bb, phn);

                if (((phn = p[(int)Index.MOBILE]) == null) || (phn.Length == 0))
                {
                    if (((phn = p[(int)Index.ALTPHONE]) == null) || (phn.Length == 0))
                    {
                        phn = "";
                    }
                }
                cMobile = CleanReversePhone(phn);
                iMobile = CrunchPhone(bb, phn);

                uid = u;

                if (p[(int)Index.LOCATION].Length > 0)
                {
                    s = p[(int)Index.STREET];
                }

                if (p[(int)Index.LOCATION].Length > 0)
                {
                    if (s.Length > 0)
                    {
                        s += "<br>" + p[(int)Index.LOCATION];
                    }
                    else
                    {
                        s = p[(int)Index.LOCATION];
                    }
                }

                if (s.Length < 1)
                {
                    s = "Unknown";
                }

                addrIdx = addr.Add(s);

                if (p[(int)Index.MANAGER].Length > 0)
                {
                    iManager = p[(int)Index.MANAGER].ToLower();
                    if (iManager.CompareTo(iEmail) == 0)
                    {
                        iManager = null;
                    }
                    else
                    {
                        mgr.Add(iManager);
                    }
                }
                else
                {
                    iManager = null;
                }

                valid = true;
            }
        }
Ejemplo n.º 4
0
        /// <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);
                }
            }
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
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);
            }
        }