public static async void Save(string givenName, string familyName, string mobile) { ContactStore store = await ContactStore.CreateOrOpenAsync(); StoredContact contact = new StoredContact(store); contact.GivenName = givenName; contact.FamilyName = familyName; IDictionary<string, object> props = await contact.GetPropertiesAsync(); props.Add(KnownContactProperties.MobileTelephone, mobile); await contact.SaveAsync(); }
/// <summary> /// Creates a contact store and add contacts. /// </summary> public static async void CreateContactStore() { ContactStore contactStore = await ContactStore.CreateOrOpenAsync( ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); foreach (SampleContact sampleContact in SampleContact.CreateSampleContacts()) { StoredContact contact = new StoredContact(contactStore); IDictionary<string, object> props = await contact.GetPropertiesAsync(); if (!string.IsNullOrEmpty(sampleContact.FirstName)) { props.Add(KnownContactProperties.GivenName, sampleContact.FirstName); } if (!string.IsNullOrEmpty(sampleContact.LastName)) { props.Add(KnownContactProperties.FamilyName, sampleContact.LastName); } if (!string.IsNullOrEmpty(sampleContact.HomeEmail)) { props.Add(KnownContactProperties.Email, sampleContact.HomeEmail); } if (!string.IsNullOrEmpty(sampleContact.WorkEmail)) { props.Add(KnownContactProperties.WorkEmail, sampleContact.WorkEmail); } if (!string.IsNullOrEmpty(sampleContact.HomePhone)) { props.Add(KnownContactProperties.Telephone, sampleContact.HomePhone); } if (!string.IsNullOrEmpty(sampleContact.WorkPhone)) { props.Add(KnownContactProperties.CompanyTelephone, sampleContact.WorkPhone); } if (!string.IsNullOrEmpty(sampleContact.MobilePhone)) { props.Add(KnownContactProperties.MobileTelephone, sampleContact.MobilePhone); } await contact.SaveAsync(); } }
private async void GetContact(string id) { //通过联系人的Id获取联系人的信息 //创建联系人存储 conStore = await ContactStore.CreateOrOpenAsync(); //查找联系人 storCon = await conStore.FindContactByIdAsync(id); //获取联系人信息 properties = await storCon.GetPropertiesAsync(); name.Text = storCon.GivenName; telphone.Text = properties[KnownContactProperties.Telephone ].ToString(); }
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(); } }
public async void GenerateContacts() { var contactsStore = await ContactManager.RequestStoreAsync(Windows.ApplicationModel.Contacts.ContactStoreAccessType.AllContactsReadOnly); var allContacts = await contactsStore.FindContactsAsync(); var contactAsList = allContacts.ToList(); if (contactAsList.Count == 0) { for (int i = 0; i < 10; i++) { var contactStore = await Windows.Phone.PersonalInformation.ContactStore.CreateOrOpenAsync( ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); var contact = new StoredContact(contactStore); var contactDetails = await contact.GetPropertiesAsync(); var newContact = new Helpers.Contact(Generator.GenerateRandomName(3, 10), Generator.GenerateRandomTelephoneNumber().ToString(), string.Format("iamhappy{0}@happy.com", i)); if (!string.IsNullOrEmpty(newContact.Name)) { contactDetails.Add(KnownContactProperties.GivenName, newContact.Name); } if (!string.IsNullOrEmpty(newContact.PhoneNumber)) { contactDetails.Add(KnownContactProperties.WorkTelephone, newContact.PhoneNumber); } if (!string.IsNullOrEmpty(newContact.PhoneNumber)) { contactDetails.Add(KnownContactProperties.Email, newContact.Email); } await contact.SaveAsync(); } contactsStore = await ContactManager.RequestStoreAsync(Windows.ApplicationModel.Contacts.ContactStoreAccessType.AllContactsReadOnly); allContacts = await contactsStore.FindContactsAsync(); contactAsList = allContacts.ToList(); } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { if (NavigationContext.QueryString.Keys.Contains("id")) { id = NavigationContext.QueryString["id"]; } contactStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); storedContact = await contactStore.FindContactByIdAsync(id); if (storedContact != null) { var properties = await storedContact.GetPropertiesAsync(); if (properties.Keys.Contains(KnownContactProperties.FamilyName)) { name.Text = properties[KnownContactProperties.FamilyName].ToString(); } if (properties.Keys.Contains(KnownContactProperties.Telephone)) { tel.Text = properties[KnownContactProperties.Telephone].ToString(); } } base.OnNavigatedTo(e); }
/// <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(); } }
private async Task SetContactProperties(StoredContact contact, User user, User originalUser = null) { if (contact != null) { contact.RemoteId = ContactsManager.GetRemoteId(user); contact.GivenName = user.first_name; contact.FamilyName = user.last_name; if (!string.IsNullOrWhiteSpace(user.photo_max) && !user.photo_max.EndsWith(".gif")) { Stream responseStreamAsync = await HttpExtensions.TryGetResponseStreamAsync(user.photo_max); if (responseStreamAsync == null) { throw new Exception("failed to download contact pic " + user.photo_max); } await contact.SetDisplayPictureAsync(responseStreamAsync.AsInputStream()); } IDictionary <string, object> propertiesAsync = await contact.GetPropertiesAsync(); if (!string.IsNullOrWhiteSpace(user.site)) { propertiesAsync[KnownContactProperties.Url] = (object)user.site; } if (!string.IsNullOrWhiteSpace(user.mobile_phone) && this.IsPhoneNumber(user.mobile_phone)) { List <string> phoneNumbers = BaseFormatterHelper.ParsePhoneNumbers(user.mobile_phone); if (phoneNumbers.Count >= 1) { propertiesAsync[KnownContactProperties.MobileTelephone] = (object)phoneNumbers[0]; } if (phoneNumbers.Count >= 2) { propertiesAsync[KnownContactProperties.AlternateMobileTelephone] = (object)phoneNumbers[1]; } } if (!string.IsNullOrWhiteSpace(user.home_phone) && this.IsPhoneNumber(user.home_phone)) { List <string> phoneNumbers = BaseFormatterHelper.ParsePhoneNumbers(user.home_phone); if (phoneNumbers.Count >= 1) { propertiesAsync[KnownContactProperties.Telephone] = (object)phoneNumbers[0]; } if (phoneNumbers.Count >= 2) { propertiesAsync[KnownContactProperties.AlternateTelephone] = (object)phoneNumbers[1]; } } DateTime dateTime; if (!string.IsNullOrWhiteSpace(user.bdate) && ContactsManager.TryParseDateTimeFromString(user.bdate, out dateTime)) { TimeSpan timeSpan = DateTime.Now - DateTime.UtcNow; dateTime = dateTime.Add(timeSpan); DateTimeOffset dateTimeOffset = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0, TimeSpan.Zero); propertiesAsync[KnownContactProperties.Birthdate] = (object)new DateTimeOffset(dateTime); } } if (originalUser == null) { return; } originalUser.first_name = user.first_name; originalUser.last_name = user.last_name; originalUser.site = user.site; originalUser.mobile_phone = user.mobile_phone; originalUser.home_phone = user.home_phone; originalUser.photo_max = user.photo_max; originalUser.bdate = user.bdate; }
public async Task <StoredContact> ToStoredContact() { StoredContact contact = new StoredContact(App.ContactStore); contact.RemoteId = this.GenerateLocalId(); contact.RemoteId = await App.RemoteIdHelper.GetTaggedRemoteId(App.ContactStore, contact.RemoteId); if (String.IsNullOrEmpty(this.GivenName) == false) { contact.GivenName = this.GivenName; } if (String.IsNullOrEmpty(this.FamilyName) == false) { contact.FamilyName = this.FamilyName; } #region Set Picture ; Test = not yet if (this.Thumbnail != null) { using (IInputStream inStream = await this.Thumbnail.OpenSequentialReadAsync()) { await contact.SetDisplayPictureAsync(inStream); } } #endregion var props = await contact.GetPropertiesAsync(); if (String.IsNullOrEmpty(this.Nickname) == false) { props.Add(KnownContactProperties.Nickname, this.Nickname); } if (String.IsNullOrEmpty(this.Mobilephone) == false) { props.Add(KnownContactProperties.MobileTelephone, this.Mobilephone); } if (String.IsNullOrEmpty(this.AlternateMobilePhone) == false) { props.Add(KnownContactProperties.AlternateMobileTelephone, this.AlternateMobilePhone); } if (String.IsNullOrEmpty(this.Telephone) == false) { props.Add(KnownContactProperties.Telephone, this.Telephone); } if (string.IsNullOrEmpty(this.Email) == false) { props.Add(KnownContactProperties.Email, this.Email); } if (String.IsNullOrEmpty(this.Address) == false) { props.Add(KnownContactProperties.Address, new ContactAddress() { Locality = this.Address, StreetAddress = (this.Street == null) ? "":this.Street, Region = (this.Region == null) ? "" : this.Region, Country = (this.Country == null) ? "" : this.Country } ); } if (this.Birthday != null) { props.Add( KnownContactProperties.Birthdate, new DateTimeOffset( new DateTime(this.Birthday.Year, this.Birthday.Month, this.Birthday.Day), new TimeSpan(1, 0, 0))); } return(contact); }
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); } }
/// <summary> /// Adds a contact to the contact store using data supplied in the MyRemoteContact helper object. /// </summary> /// <param name="remoteContact">The MyRemoteContact helper object representing the contact to be added.</param> /// <returns></returns> public async Task AddContact(XElement el, uint id) { try { StoredContact contact = new StoredContact(contactStore); contact.RemoteId = await remoteIdHelper.GetTaggedRemoteId(contactStore, id.ToString()); contact.GivenName = el.Element("GivenName").Value; contact.FamilyName = el.Element("FamilyName").Value; contact.DisplayName = el.Element("DisplayName").Value; IDictionary <string, object> props = await contact.GetPropertiesAsync(); if (el.Element("AdditionalName") != null) { props.Add(KnownContactProperties.AdditionalName, el.Element("AdditionalName").Value); } if (el.Element("Address") != null) { props.Add(KnownContactProperties.Address, el.Element("Address").Value); } if (el.Element("AlternateMobileTelephone") != null) { props.Add(KnownContactProperties.AlternateMobileTelephone, el.Element("AlternateMobileTelephone").Value); } if (el.Element("Anniversary") != null) { props.Add(KnownContactProperties.Anniversary, el.Element("Anniversary").Value); } if (el.Element("Birthdate") != null) { props.Add(KnownContactProperties.Birthdate, el.Element("Birthdate").Value); } if (el.Element("Children") != null) { props.Add(KnownContactProperties.Children, el.Element("Children").Value); } if (el.Element("CompanyName") != null) { props.Add(KnownContactProperties.CompanyName, el.Element("CompanyName").Value); } if (el.Element("CompanyTelephone") != null) { props.Add(KnownContactProperties.CompanyTelephone, el.Element("CompanyTelephone").Value); } // if (el.Element("DisplayName") != null) props.Add(KnownContactProperties.DisplayName, el.Element("DisplayName").Value); if (el.Element("Email") != null) { props.Add(KnownContactProperties.Email, el.Element("Email").Value); } // if (el.Element("FamilyName") != null) props.Add(KnownContactProperties.FamilyName, el.Element("FamilyName").Value); // if (el.Element("GivenName") != null) props.Add(KnownContactProperties.GivenName, el.Element("GivenName").Value); if (el.Element("HomeFax") != null) { props.Add(KnownContactProperties.HomeFax, el.Element("HomeFax").Value); } if (el.Element("HonorificPrefix") != null) { props.Add(KnownContactProperties.HonorificPrefix, el.Element("HonorificPrefix").Value); } if (el.Element("HonorificSuffix") != null) { props.Add(KnownContactProperties.HonorificSuffix, el.Element("HonorificSuffix").Value); } if (el.Element("JobTitle") != null) { props.Add(KnownContactProperties.JobTitle, el.Element("JobTitle").Value); } if (el.Element("Manager") != null) { props.Add(KnownContactProperties.Manager, el.Element("Manager").Value); } if (el.Element("MobileTelephone") != null) { props.Add(KnownContactProperties.MobileTelephone, el.Element("MobileTelephone").Value); } if (el.Element("Nickname") != null) { props.Add(KnownContactProperties.Nickname, el.Element("Nickname").Value); } if (el.Element("Notes") != null) { props.Add(KnownContactProperties.Notes, el.Element("Notes").Value); } if (el.Element("OfficeLocation") != null) { props.Add(KnownContactProperties.OfficeLocation, el.Element("OfficeLocation").Value); } if (el.Element("OtherAddress") != null) { props.Add(KnownContactProperties.OtherAddress, el.Element("OtherAddress").Value); } if (el.Element("OtherEmail") != null) { props.Add(KnownContactProperties.OtherEmail, el.Element("OtherEmail").Value); } if (el.Element("SignificantOther") != null) { props.Add(KnownContactProperties.SignificantOther, el.Element("SignificantOther").Value); } if (el.Element("Telephone") != null) { props.Add(KnownContactProperties.Telephone, el.Element("Telephone").Value); } if (el.Element("Url") != null) { props.Add(KnownContactProperties.Url, el.Element("Url").Value); } if (el.Element("WorkAddress") != null) { props.Add(KnownContactProperties.WorkAddress, el.Element("WorkAddress").Value); } if (el.Element("WorkEmail") != null) { props.Add(KnownContactProperties.WorkEmail, el.Element("WorkEmail").Value); } if (el.Element("WorkFax") != null) { props.Add(KnownContactProperties.WorkFax, el.Element("WorkFax").Value); } if (el.Element("WorkTelephone") != null) { props.Add(KnownContactProperties.WorkTelephone, el.Element("WorkTelephone").Value); } if (el.Element("YomiCompanyName") != null) { props.Add(KnownContactProperties.YomiCompanyName, el.Element("YomiCompanyName").Value); } if (el.Element("YomiFamilyName") != null) { props.Add(KnownContactProperties.YomiFamilyName, el.Element("YomiFamilyName").Value); } if (el.Element("YomiGivenName") != null) { props.Add(KnownContactProperties.YomiGivenName, el.Element("YomiGivenName").Value); } await contact.SaveAsync(); } catch (Exception e) { Debug.WriteLine(e.ToString()); StatusTextBlock.Text = e.ToString(); } }
private async Task SetContactProperties(StoredContact contact, User user, User originalUser = null) { if (contact != null) { contact.RemoteId = (ContactsManager.GetRemoteId(user)); contact.GivenName = (user.first_name); contact.FamilyName = (user.last_name); if (!string.IsNullOrWhiteSpace(user.photo_max) && !user.photo_max.EndsWith(".gif")) { Stream stream = await HttpExtensions.TryGetResponseStreamAsync(user.photo_max); if (stream == null) { throw new Exception("failed to download contact pic " + user.photo_max); } await contact.SetDisplayPictureAsync(stream.AsInputStream()); } IDictionary <string, object> dictionary = await contact.GetPropertiesAsync(); if (!string.IsNullOrWhiteSpace(user.site)) { dictionary[KnownContactProperties.Url] = user.site; } if (!string.IsNullOrWhiteSpace(user.mobile_phone) && this.IsPhoneNumber(user.mobile_phone)) { List <string> var_6_262 = BaseFormatterHelper.ParsePhoneNumbers(user.mobile_phone); if (var_6_262.Count >= 1) { dictionary[KnownContactProperties.MobileTelephone] = var_6_262[0]; } if (var_6_262.Count >= 2) { dictionary[KnownContactProperties.AlternateMobileTelephone] = var_6_262[1]; } } if (!string.IsNullOrWhiteSpace(user.home_phone) && this.IsPhoneNumber(user.home_phone)) { List <string> var_7_2D8 = BaseFormatterHelper.ParsePhoneNumbers(user.home_phone); if (var_7_2D8.Count >= 1) { dictionary[KnownContactProperties.Telephone] = var_7_2D8[0]; } if (var_7_2D8.Count >= 2) { dictionary[KnownContactProperties.AlternateTelephone] = var_7_2D8[1]; } } DateTime var_8; if (!string.IsNullOrWhiteSpace(user.bdate) && ContactsManager.TryParseDateTimeFromString(user.bdate, out var_8)) { var_8 = var_8.Add(DateTime.Now - DateTime.UtcNow); new DateTimeOffset(var_8.Year, var_8.Month, var_8.Day, 0, 0, 0, 0, TimeSpan.Zero); dictionary[KnownContactProperties.Birthdate] = new DateTimeOffset(var_8); } } if (originalUser != null) { originalUser.first_name = user.first_name; originalUser.last_name = user.last_name; originalUser.site = user.site; originalUser.mobile_phone = user.mobile_phone; originalUser.home_phone = user.home_phone; originalUser.photo_max = user.photo_max; originalUser.bdate = user.bdate; } }
public async Task AddContact(string remoteId, string givenName, string familyName, string phone) { logger.debug("adding contact id={0} {1} {2} {3}", remoteId, givenName, familyName, phone); ContactStore store = await ContactStore.CreateOrOpenAsync(); StoredContact contact = new StoredContact(store); contact.RemoteId = remoteId; contact.GivenName = givenName; contact.FamilyName = familyName; // TODO: picture sync IDictionary<string, object> props = await contact.GetPropertiesAsync(); props.Add(KnownContactProperties.MobileTelephone, phone); await contact.SaveAsync(); }
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) { } }