コード例 #1
0
        public Contact Load(string id)
        {
            if (String.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException("id");
            }

            CheckStatus();

            int rowId;

            if (!Int32.TryParse(id, out rowId))
            {
                throw new ArgumentException("Not a valid contact ID", "id");
            }

            ABPerson person = this.addressBook.GetPerson(rowId);

            if (person == null)
            {
                return(null);
            }

            return(ContactHelper.GetContact(person));
        }
コード例 #2
0
        /// <summary>
        /// Attempts to load a contact for the specified <paramref name="id" />.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>The <see cref="Contact" /> if found, <c>null</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="id" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="id" /> is empty.</exception>
        public IContact Load(String id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (id.Trim() == String.Empty)
            {
                throw new ArgumentException("Invalid ID", "id");
            }

            Uri    curi;
            String column;

            if (PreferContactAggregation)
            {
                curi   = ContactsContract.Contacts.ContentUri;
                column = ContactsContract.ContactsColumns.LookupKey;
            }
            else
            {
                curi   = ContactsContract.RawContacts.ContentUri;
                column = ContactsContract.RawContactsColumns.ContactId;
            }

            ICursor c = null;

            try
            {
                c = content.Query(curi, null, column + " = ?", new[] { id }, null);
                return(c.MoveToNext() ? ContactHelper.GetContact(!PreferContactAggregation, content, resources, c) : null);
            }
            finally
            {
                if (c != null)
                {
                    c.Deactivate();
                }
            }
        }