示例#1
0
        public ArrayList GetContacts(uint offset, uint count)
        {
            // TODO regenerate file
            var contacts = new ArrayList();
            try
            {
                if (contactsPath == null || !File.Exists(contactsPath))
                {
                    Logger.Info("No contacts file");
                    return contacts;
                }

                using (var sr = new StreamReader(contactsPath))
                {
                    uint found = 0;
                    bool hasPhone = false;
                    PhoneContact contact = null;

                    string s;
                    while ((s = sr.ReadLine()) != null)
                    {
                        if (s == string.Empty)
                        {
                            continue;
                        }
                        switch (s)
                        {
                            case "BEGIN:VCARD":
                                Debug.GC(true); // Logger.Info("Free memory = " + Debug.GC(true), "MEM");
                                hasPhone = false;
                                if (found >= offset)
                                {
                                    contact = new PhoneContact();
                                }
                                break;
                            case "END:VCARD":
                                if (hasPhone)
                                {
                                    if (contact != null)
                                    {
                                        contacts.Add(contact);
                                        if (contacts.Count == count)
                                        {
                                            return contacts;
                                        }
                                    }
                                    found++;
                                }
                                break;
                            default:
                                if (s.Substring(0, 2) == "FN")
                                {
                                    if (contact != null)
                                    {
                                        contact.Name = s.Split(':')[1];
                                    }
                                }
                                else if (s.Substring(0, 3) == "TEL")
                                {
                                    if (contact != null)
                                    {
                                        contact.AddPhone(s.Split(':')[1]);
                                    }
                                    hasPhone = true;
                                }
                                break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "contacts loading");
            }
            return contacts;
        }
示例#2
0
        public ArrayList GetContacts(uint offset, uint count)
        {
            // TODO regenerate file
            var contacts = new ArrayList();
            try
            {
                if (contactsPath == null || !File.Exists(contactsPath))
                {
                    Logger.Info("No contacts file");
                    return contacts;
                }

                using (var sr = new StreamReader(contactsPath))
                {
                    uint found = 0;
                    bool hasPhone = false;
                    PhoneContact contact = null;

                    string s;
                    while ((s = sr.ReadLine()) != null)
                    {
                        if (s == string.Empty)
                        {
                            continue;
                        }
                        switch (s)
                        {
                            case "BEGIN:VCARD":
                                Debug.GC(true); // Logger.Info("Free memory = " + Debug.GC(true), "MEM");
                                hasPhone = false;
                                if (found >= offset)
                                {
                                    contact = new PhoneContact();
                                }
                                break;
                            case "END:VCARD":
                                if (hasPhone)
                                {
                                    if (contact != null)
                                    {
                                        contacts.Add(contact);
                                        if (contacts.Count == count)
                                        {
                                            return contacts;
                                        }
                                    }
                                    found++;
                                }
                                break;
                            default:
                                if (s.Substring(0, 2) == "FN")
                                {
                                    if (contact != null)
                                    {
                                        contact.Name = s.Split(':')[1];
                                    }
                                }
                                else if (s.Substring(0, 3) == "TEL")
                                {
                                    if (contact != null)
                                    {
                                        contact.AddPhone(s.Split(':')[1]);
                                    }
                                    hasPhone = true;
                                }
                                break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "contacts loading");
            }
            return contacts;
        }