private static async Task AddContact(RemoteContact remoteContact) { try { ContactStore store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); var contact = new StoredContact(store); if (remoteContact.RemoteId == null) { return; } var remoteIdHelper = new RemoteIdHelper(); contact.RemoteId = await remoteIdHelper.GetTaggedRemoteId(store, remoteContact.RemoteId); IDictionary <string, object> props = await contact.GetPropertiesAsync(); if (remoteContact.Email != null) { props.Add(KnownContactProperties.Email, remoteContact.Email); } IDictionary <string, object> extprops = await contact.GetExtendedPropertiesAsync(); if (remoteContact.CodeName != null) { extprops.Add("Codename", remoteContact.CodeName); } if (remoteContact.DisplayName != null) { contact.DisplayName = remoteContact.DisplayName + " " + remoteContact.GivenName; } var prop = await contact.GetPropertiesAsync(); prop.Add(KnownContactProperties.MobileTelephone, "+1" + MdnGenerator(10)); prop.Add(KnownContactProperties.JobTitle, JobTitleGenerator()); prop.Add(KnownContactProperties.OfficeLocation, LocationGenerator()); prop.Add(KnownContactProperties.Notes, JobTitleGenerator()); Debug.WriteLine(contact.Store); await contact.SaveAsync(); Debug.WriteLine(String.Format("Adding:\n{0}", remoteContact.ToString())); } catch (Exception e) { Debug.WriteLine(e.Message); } }
async void SearchCompleted(object sender, ContactsSearchEventArgs e) { foreach (Contact c in e.Results) { StoredContact a = new StoredContact(contacts); var props = await a.GetPropertiesAsync(); var extprops =await a.GetExtendedPropertiesAsync(); props.Add(KnownContactProperties.DisplayName, c.DisplayName); props.Add(KnownContactProperties.Telephone, c.PhoneNumbers); extprops.Add("MoneyOwed", 0); extprops.Add("MoneyLent", 0); extprops.Add("DateAdded", 0); extprops.Add("Group", 0); await a.SaveAsync(); } }
/// <summary> /// Update Contact Information /// </summary> /// <param name="remoteId"></param> /// <param name="givenName"></param> /// <param name="familyName"></param> /// <param name="email"></param> /// <param name="codeName"></param> async private void UpdateContact(string remoteId, string givenName, string familyName, string email, string codeName) { store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); string taggedRemoteId = await GetTaggedRemoteId(store, remoteId); StoredContact contact = await store.FindContactByRemoteIdAsync(taggedRemoteId); if (contact != null) { contact.GivenName = givenName; contact.FamilyName = familyName; IDictionary <string, object> props = await contact.GetPropertiesAsync(); props[KnownContactProperties.Email] = email; IDictionary <string, object> extprops = await contact.GetExtendedPropertiesAsync(); extprops["Codename"] = codeName; await contact.SaveAsync(); } }
public async Task AddContact(RemoteContact remoteContact) { try { ContactStore store = await ContactStore.CreateOrOpenAsync(); StoredContact contact = new StoredContact(store); RemoteIdHelper remoteIDHelper = new RemoteIdHelper(); contact.RemoteId = await remoteIDHelper.GetTaggedRemoteId(store, remoteContact.RemoteId); contact.GivenName = remoteContact.GivenName; contact.FamilyName = remoteContact.FamilyName; IDictionary<string, object> props = await contact.GetPropertiesAsync(); props.Add(KnownContactProperties.Email, remoteContact.Email); IDictionary<string, object> extprops = await contact.GetExtendedPropertiesAsync(); extprops.Add("Codename", remoteContact.CodeName); if (remoteContact.DisplayName != null) contact.DisplayName = remoteContact.DisplayName; IInputStream I = remoteContact.photo.AsInputStream(); await contact.SetDisplayPictureAsync(I); Debug.WriteLine(contact.Store); await contact.SaveAsync(); Debug.WriteLine(String.Format("Adding:\n{0}", remoteContact.ToString())); } catch(Exception e) { Debug.WriteLine(e.Message); } }
public async void AddContact(string remoteId, string givenName, string familyName, string username, String avatar, String url) { ContactStore store = await ContactStore.CreateOrOpenAsync(); try { if (await store.FindContactByRemoteIdAsync(remoteId) == null) { StoredContact contact = new StoredContact(store); contact.RemoteId = remoteId; contact.GivenName = givenName; contact.FamilyName = familyName; contact.DisplayName = remoteId; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(avatar)); HttpWebResponse webResponse = await request.GetResponseAsync() as HttpWebResponse; MemoryStream memoryStream = new MemoryStream(); webResponse.GetResponseStream().CopyTo(memoryStream); IRandomAccessStream stream = await ConvertToRandomAccessStream(memoryStream); IDictionary <string, object> props = await contact.GetPropertiesAsync(); props.Add(KnownContactProperties.Nickname, username); props.Add(KnownContactProperties.Url, url); IDictionary <string, object> extprops = await contact.GetExtendedPropertiesAsync(); extprops.Add("Codename", username); extprops.Add("ProfilePic", avatar); await contact.SetDisplayPictureAsync(stream); await contact.SaveAsync(); } else { StoredContact contact = await store.FindContactByRemoteIdAsync(remoteId); IDictionary <string, object> extprops = await contact.GetExtendedPropertiesAsync(); if (!extprops.Values.Contains(avatar)) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(avatar)); HttpWebResponse webResponse = await request.GetResponseAsync() as HttpWebResponse; MemoryStream memoryStream = new MemoryStream(); webResponse.GetResponseStream().CopyTo(memoryStream); IRandomAccessStream stream = await ConvertToRandomAccessStream(memoryStream); await contact.SetDisplayPictureAsync(stream); extprops.Remove("ProfilePic"); extprops.Add("ProfilePic", avatar); await contact.SaveAsync(); } } } catch (WebException) { } }