public void OnDeserialized(StreamingContext context) { // Create W3ContactValueFields if (NickName != null) { W3ContactNickName = new W3ContactNickName(NickName); } if (BirthDay != null) { W3ContactBirthday = new W3ContactBirthday(BirthDay); } if (Notes != null) { W3ContactNotes = new W3ContactNotes(Notes); } }
private async Task <StoredContact> ToStoredContact(StoredContact contact) { if (contact == null) { ContactStore contactStore = await ContactStore.CreateOrOpenAsync( ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); contact = new StoredContact(contactStore); } IDictionary <string, object> properties = await contact.GetPropertiesAsync(); // Address if (Addresses != null && Addresses.Count > 0) { Addresses.ForEach(address => address.AsStoredContactProperties(ref properties)); } // Birthday if (W3ContactBirthday != null) { W3ContactBirthday.AsStoredContactProperties(ref properties); } // Emails if (Emails != null && Emails.Count > 0) { Emails.ForEach(email => email.AsStoredContactProperties(ref properties)); } // Name if (Name != null) { Name.AsStoredContactProperties(ref properties); } // NickName if (W3ContactNickName != null) { W3ContactNickName.AsStoredContactProperties(ref properties); } // Note if (W3ContactNotes != null) { W3ContactNotes.AsStoredContactProperties(ref properties); } // Organization if (Organization != null) { Organization.AsStoredContactProperties(ref properties); } // Phones if (Phones != null && Phones.Count > 0) { Phones.ForEach(phone => phone.AsStoredContactProperties(ref properties)); } // Photos if (Photos != null && Photos.Count > 0) { W3ContactPhoto firstPhoto = Photos.FirstOrDefault(); if (firstPhoto != null) { await firstPhoto.SetPictureOnStoredContactAsync(contact); } } // Urls if (Urls != null && Urls.Count > 0) { Urls.ForEach(url => url.AsStoredContactProperties(ref properties)); } return(contact); }
/// <summary> /// Constructor /// </summary> /// <param name="contact"> /// <see cref="Microsoft.Phone.UserData.Contact">Contact</see> object /// </param> /// <param name="properties">List of properties to read from native contact</param> public W3Contact(Contact contact, List <string> properties) { if (properties == null || properties.Count == 0) { // Default properties properties = Properties; } // id // Address if (properties.Any(KEY_ADDRESSES.Equals)) { if (contact.Addresses.Count() > 0) { Addresses = contact.Addresses.Select(address => new W3ContactAddress(address)) .ToList <W3ContactAddress>(); } } // Birthday if (properties.Any(KEY_BIRTHDAY.Equals)) { if (contact.Birthdays.Count() > 0) { W3ContactBirthday = new W3ContactBirthday(contact.Birthdays .Where(birthday => birthday != new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)) .Select(birthday => birthday.ToString()).FirstOrDefault()); } } // Emails if (properties.Any(KEY_EMAILS.Equals)) { if (contact.EmailAddresses.Count() > 0) { Emails = contact.EmailAddresses.Select(address => new W3ContactEmail(address)) .ToList <W3ContactEmail>(); } } // Impps - Not supported // Name if (properties.Any(KEY_NAME.Equals)) { Name = new W3ContactName(contact.CompleteName); } // Nickname if (properties.Any(KEY_NICK_NAME.Equals)) { W3ContactNickName = new W3ContactNickName(contact.CompleteName.Nickname); } // Note if (properties.Any(KEY_NOTE.Equals)) { if (contact.Notes.Count() > 0) { W3ContactNotes = new W3ContactNotes( contact.Notes.Aggregate((current, next) => current + Environment.NewLine + next)); } } // Organizations if (properties.Any(KEY_ORGANIZATION.Equals)) { if (contact.Companies.Count() > 0) { Organization = new W3ContactOrganization(contact.Companies.First()); } } // Phones if (properties.Any(KEY_PHONES.Equals)) { if (contact.PhoneNumbers.Count() > 0) { Phones = contact.PhoneNumbers.Select(phone => new W3ContactPhone(phone)) .ToList <W3ContactPhone>(); } } // Urls if (properties.Any(KEY_URLS.Equals)) { if (contact.Websites.Count() > 0) { Urls = contact.Websites.Select(website => new W3ContactUrl(W3ContactTypeValueField.KEY_HOME, website)) .ToList <W3ContactUrl>(); } } // Photos - Get the picture and write it to cache if (properties.Any(KEY_PHOTOS.Equals)) { Stream pictureStream = contact.GetPicture(); FilePath filePath = new FilePath { Path = "photo" + new Random().Next() + ".jpg", Level = FileLevel.App, StorageType = StorageType.Cache }; Photos = new List <W3ContactPhoto> { new W3ContactPhoto(W3ContactTypeValueField.KEY_HOME, filePath) }; Task.Run(() => { try { FileManager.WriteDataToFile( FileManager.GetAbsolutePath(filePath), pictureStream, false); } catch (Exception e) { Logger.Error("Error writing contact picture to tmp folder. Reason - " + e.Message); } }); } }