コード例 #1
0
        public void UpdateContacts()
        {
            List <Item> contacts = new List <Item> ();

            // set up the contacts query
            ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri(GUserId));

            query.NumberToRetrieve = MaxContacts;
            query.UseSSL           = true;

            try {
                ContactsFeed feed = service.Query(query);

                ContactItem buddy;
                foreach (ContactEntry entry in feed.Entries)
                {
                    if (String.IsNullOrEmpty(entry.Title.Text))
                    {
                        continue;
                    }

                    buddy = ContactItem.CreateWithName(entry.Title.Text);

                    AddDetails(buddy, entry.Emails);
                    AddDetails(buddy, entry.Phonenumbers);
//					AddDetails (buddy, entry.PostalAddresses);

                    contacts.Add(buddy);
                }

                Log.Debug("Retrieved {0} contacts", contacts.Count());
                Contacts = contacts;
            } catch (Exception e) {
                Log.Error("GMailContacts Error: {0}", e.Message);
                Log.Debug(e.StackTrace);
            }
        }
コード例 #2
0
        public override void UpdateItems()
        {
            items.Clear();

            // iterate over address book files
            foreach (string addressBook in AddressBookFiles)
            {
                try {
                    XmlDocument xmldoc = new XmlDocument();
                    // read adress book by StreamReader. Without: error:Encoding name '...' not supported
                    using (StreamReader reader = new StreamReader(addressBook)) {
                        xmldoc.Load(reader);
                    }

                    XmlNodeList people = xmldoc.SelectNodes("/address-book/person");
                    if (people == null)
                    {
                        continue;
                    }

                    foreach (XmlNode person in people)
                    {
                        // contact name from "cn" attribute
                        string personCn = person.Attributes ["cn"].InnerText;
                        if (string.IsNullOrEmpty(personCn))
                        {
                            continue;
                        }

                        // load emails
                        XmlNodeList addresses = person.SelectNodes("address-list/address");
                        if ((addresses == null) || (addresses.Count == 0))                           // no childs == no emails -> skip
                        {
                            continue;
                        }

                        ContactItem buddy        = ContactItem.CreateWithName(personCn);
                        int         emailCounter = 0;

                        foreach (XmlNode address in addresses)
                        {
                            string email = address.Attributes ["email"].InnerText;
                            if (!string.IsNullOrEmpty(email))
                            {
                                string remarks = address.Attributes ["remarks"].InnerText;
                                string id      = ClawsKeyPrefix + emailCounter + "." + remarks;
                                buddy [id] = email;
                                emailCounter++;
                            }
                        }

                        if (emailCounter > 0)
                        {
                            items.Add(buddy);
                        }
                    }
                } catch (Exception e) {
                    Log.Error("ClawsContactsItemSource: file:{0} error:{1}", addressBook, e.Message);
                    Log.Debug("ClawsContactsItemSource: file:{0}: {1}", addressBook, e.ToString());
                }
            }
        }