Exemple #1
0
        private static Contact GetContact(Microsoft.Phone.UserData.Contact contact)
        {
            var c = new Contact
            {
                Tag = contact
            };

            c.DisplayName = contact.DisplayName;

            if (contact.CompleteName != null)
            {
                c.Prefix     = contact.CompleteName.Title;
                c.FirstName  = contact.CompleteName.FirstName;
                c.MiddleName = contact.CompleteName.MiddleName;
                c.LastName   = contact.CompleteName.LastName;
                c.Suffix     = contact.CompleteName.Suffix;
            }

            foreach (ContactAddress address in contact.Addresses)
            {
                c.Addresses.Add(GetAddress(address));
            }

            foreach (ContactEmailAddress email in contact.EmailAddresses)
            {
                c.Emails.Add(GetEmail(email));
            }

            foreach (ContactPhoneNumber phone in contact.PhoneNumbers)
            {
                c.Phones.Add(GetPhone(phone));
            }

            foreach (ContactCompanyInformation company in contact.Companies)
            {
                c.Organizations.Add(GetOrganization(company));
            }

            foreach (string name in contact.Children)
            {
                c.Relationships.Add(new Relationship {
                    Name = name, Type = RelationshipType.Child
                });
            }

            foreach (string name in contact.SignificantOthers)
            {
                c.Relationships.Add(new Relationship {
                    Name = name, Type = RelationshipType.SignificantOther
                });
            }

            foreach (string url in contact.Websites)
            {
                c.Websites.Add(new Website {
                    Address = url
                });
            }

            foreach (string note in contact.Notes)
            {
                c.Notes.Add(new Note {
                    Contents = note
                });
            }

            return(c);
        }
Exemple #2
0
        public Abstractions.Contact Convert(Contact winContact)
        {
            Abstractions.Contact contact = new Abstractions.Contact(winContact.Id, winContact.IsAggregate);
            try
            {
                contact.FirstName   = winContact.FirstName;
                contact.MiddleName  = winContact.MiddleName;
                contact.LastName    = winContact.LastName;
                contact.DisplayName = winContact.DisplayName;
                contact.Nickname    = winContact.Nickname;
                contact.Prefix      = winContact.HonorificNamePrefix;
                contact.Suffix      = winContact.HonorificNameSuffix;
                contact.Phones      = new List <Abstractions.Phone>();
                foreach (var phone in winContact.Phones)
                {
                    contact.Phones.Add(Convert(phone));
                }
                contact.Addresses = new List <Abstractions.Address>();
                foreach (var contactAddress in winContact.Addresses)
                {
                    contact.Addresses.Add(Convert(contactAddress));
                }
                contact.Emails = new List <Abstractions.Email>();
                foreach (var contactEmail in winContact.Emails)
                {
                    contact.Emails.Add(Convert(contactEmail));
                }
                contact.InstantMessagingAccounts = new List <Abstractions.InstantMessagingAccount>();
                foreach (var contactIM in winContact.ConnectedServiceAccounts)
                {
                    contact.InstantMessagingAccounts.Add(Convert(contactIM));
                }
                contact.Notes = new List <Abstractions.Note>()
                {
                    new Abstractions.Note {
                        Contents = winContact.Notes
                    }
                };
                contact.Organizations = new List <Abstractions.Organization>();
                foreach (var jobInfo in winContact.JobInfo)
                {
                    contact.Organizations.Add(Convert(jobInfo));
                }
                contact.Websites = new List <Abstractions.Website>();
                foreach (var contactWebsite in winContact.Websites)
                {
                    contact.Websites.Add(Convert(contactWebsite));
                }
                contact.Relationships = new List <Abstractions.Relationship>();
                foreach (var relationship in winContact.SignificantOthers)
                {
                    contact.Relationships.Add(Convert(relationship));
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                Debug.WriteLine(ex.Message);
#endif
            }

            return(contact);
        }
    private static void FillContactWithRow(Resources resources, Contact contact, ICursor c)
    {
      string dataType = c.GetString(c.GetColumnIndex(ContactsContract.DataColumns.Mimetype));
      switch (dataType)
      {
        case ContactsContract.CommonDataKinds.Nickname.ContentItemType:
          contact.Nickname = c.GetString(c.GetColumnIndex(ContactsContract.CommonDataKinds.Nickname.Name));
          break;

        case StructuredName.ContentItemType:
          contact.Prefix = c.GetString(StructuredName.Prefix);
          contact.FirstName = c.GetString(StructuredName.GivenName);
          contact.MiddleName = c.GetString(StructuredName.MiddleName);
          contact.LastName = c.GetString(StructuredName.FamilyName);
          contact.Suffix = c.GetString(StructuredName.Suffix);
          break;

        case ContactsContract.CommonDataKinds.Phone.ContentItemType:
          contact.Phones.Add(GetPhone(c, resources));
          break;

        case ContactsContract.CommonDataKinds.Email.ContentItemType:
          contact.Emails.Add(GetEmail(c, resources));
          break;

        case ContactsContract.CommonDataKinds.Note.ContentItemType:
          contact.Notes.Add(GetNote(c, resources));
          break;

        case ContactsContract.CommonDataKinds.Organization.ContentItemType:
          contact.Organizations.Add(GetOrganization(c, resources));
          break;

        case StructuredPostal.ContentItemType:
          contact.Addresses.Add(GetAddress(c, resources));
          break;

        case InstantMessaging.ContentItemType:
          contact.InstantMessagingAccounts.Add(GetImAccount(c, resources));
          break;

        case WebsiteData.ContentItemType:
          contact.Websites.Add(GetWebsite(c, resources));
          break;

        case Relation.ContentItemType:
          contact.Relationships.Add(GetRelationship(c, resources));
          break;
      }
    }
    internal static void FillContactExtras(bool rawContact, ContentResolver content, Resources resources, string recordId, Contact contact)
    {
      ICursor c = null;

      string column = (rawContact)
                ? ContactsContract.RawContactsColumns.ContactId
                : ContactsContract.ContactsColumns.LookupKey;

      try
      {
		if (string.IsNullOrWhiteSpace(recordId))
			return;

        c = content.Query(ContactsContract.Data.ContentUri, null, column + " = ?", new[] { recordId }, null);
        if (c == null)
          return;

        while (c.MoveToNext())
          FillContactWithRow(resources, contact, c);
      }
      finally
      {
        if (c != null)
          c.Close();
      }
    }
    internal static Contact GetContact(bool rawContact, ContentResolver content, Resources resources, ICursor cursor)
    {
      string id = (rawContact)
              ? cursor.GetString(cursor.GetColumnIndex(ContactsContract.RawContactsColumns.ContactId))
              : cursor.GetString(cursor.GetColumnIndex(ContactsContract.ContactsColumns.LookupKey));

      var contact = new Contact(id, !rawContact)
      {
        Tag = content
      };
      contact.DisplayName = GetString(cursor, ContactsContract.ContactsColumns.DisplayName);

      FillContactExtras(rawContact, content, resources, id, contact);

      return contact;
    }
    internal static IEnumerable<Contact> GetContacts(bool rawContacts, ContentResolver content, Resources resources, string[] ids)
    {
      ICursor c = null;

      string column = (rawContacts)
                ? ContactsContract.RawContactsColumns.ContactId
                : ContactsContract.ContactsColumns.LookupKey;

      StringBuilder whereb = new StringBuilder();
      for (int i = 0; i < ids.Length; i++)
      {
        if (i > 0)
          whereb.Append(" OR ");

        whereb.Append(column);
        whereb.Append("=?");
      }

      int x = 0;
      var map = new Dictionary<string, Contact>(ids.Length);

      try
      {
        Contact currentContact = null;

        c = content.Query(ContactsContract.Data.ContentUri, null, whereb.ToString(), ids, ContactsContract.ContactsColumns.LookupKey);
        if (c == null)
          yield break;

        int idIndex = c.GetColumnIndex(column);
        int dnIndex = c.GetColumnIndex(ContactsContract.ContactsColumns.DisplayName);
        while (c.MoveToNext())
        {
          string id = c.GetString(idIndex);
          if (currentContact == null || currentContact.Id != id)
          {
            // We need to yield these in the original ID order
            if (currentContact != null)
            {
              if (currentContact.Id == ids[x])
              {
                yield return currentContact;
                x++;
              }
              else
                map.Add(currentContact.Id, currentContact);
            }

            currentContact = new Contact(id, !rawContacts)
            {
              Tag = content
            };
            currentContact.DisplayName = c.GetString(dnIndex);
          }

          FillContactWithRow(resources, currentContact, c);
        }

        if (currentContact != null)
          map.Add(currentContact.Id, currentContact);

        for (; x < ids.Length; x++)
        {
            Contact tContact = null;
            if(map.TryGetValue(ids[x], out tContact))
                yield return tContact;
        }
      }
      finally
      {
        if (c != null)
          c.Close();
      }
    }
        public ContactPage(Contact contact)
        {
            var stack = new StackLayout { Padding = 10, Spacing = 10 };

            stack.Children.Add(new Label
                {
                    Text = "DisplayName: " + contact.DisplayName
                });


            stack.Children.Add(new Label
                {
                    Text = "FirstName: " + contact.FirstName
                });

            stack.Children.Add(new Label
                {
                    Text = "MiddleName: " + contact.MiddleName
                });

            stack.Children.Add(new Label
                {
                    Text = "LastName: " + contact.LastName
                });


            stack.Children.Add(new Label
                {
                    Text = "Id: " + contact.Id
                });

            stack.Children.Add(new Label
                {
                    Text = "Nickname: " + contact.Nickname
                });

            stack.Children.Add(new Label
                {
                    Text = "Emails: "
                });

            foreach (var email in contact.Emails)
            {
                stack.Children.Add(new Label
                    {
                        Text = "Address: " + email.Address
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Label: " + email.Label
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Type: " + email.Type.ToString()
                    });
            }

            stack.Children.Add(new Label
                {
                    Text = "Addresses: "
                });

            foreach (var address in contact.Addresses)
            {
                stack.Children.Add(new Label
                    {
                        Text = "City: " + address.City
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Country: " + address.Country
                    });


                stack.Children.Add(new Label
                    {
                        Text = "label: " + address.Label
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Post: " + address.PostalCode
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Region: " + address.Region
                    });


                stack.Children.Add(new Label
                    {
                        Text = "StreetAddress: " + address.StreetAddress
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Type: " + address.Type
                    });

            }

            stack.Children.Add(new Label
                {
                    Text = "Prefix: " + contact.Prefix
                });


            stack.Children.Add(new Label
                {
                    Text = "Suffix: " + contact.Suffix
                });

      
            stack.Children.Add(new Label
                {
                    Text = "Notes: "
                });

            foreach (var note in contact.Notes)
            {
                stack.Children.Add(new Label
                    {
                        Text = "note: " + note.Contents
                    });
            }

            stack.Children.Add(new Label
                {
                    Text = "Organizations: "
                });

            foreach (var org in contact.Organizations)
            {
                stack.Children.Add(new Label
                    {
                        Text = "ContactTitle: " + org.ContactTitle
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Label: " + org.Label
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Name: " + org.Name
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Type: " + org.Type
                    });
            }


            stack.Children.Add(new Label
                {
                    Text = "Phones: "
                });

            foreach (var phone in contact.Phones)
            {
                stack.Children.Add(new Label
                    {
                        Text = "Label: " + phone.Label
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Number: " + phone.Number
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Type: " + phone.Type
                    });
            }

            stack.Children.Add(new Label
                {
                    Text = "Relationships: "
                });

            foreach (var relation in contact.Relationships)
            {
                stack.Children.Add(new Label
                    {
                        Text = "Name: " + relation.Name
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Type: " + relation.Type
                    });
            }

            stack.Children.Add(new Label
                {
                    Text = "Websites: "
                });

            foreach (var site in contact.Websites)
            {
                stack.Children.Add(new Label
                    {
                        Text = "Address: " + site.Address
                    });
            }


            Content = new ScrollView
            {
                Content = stack
            };
        }