async private Task UpdateContact(string remoteId, string givenName, string familyName, string phone) { logger.debug("updating contact id={0} {1} {2} {3}", remoteId, givenName, familyName, phone); ContactStore store = await ContactStore.CreateOrOpenAsync(); string taggedRemoteId = remoteId; StoredContact contact = await store.FindContactByRemoteIdAsync(taggedRemoteId); if (contact != null) { logger.debug("contact id={0} exists in custom store, updating", remoteId); contact.GivenName = givenName; contact.FamilyName = familyName; IDictionary <string, object> props = await contact.GetPropertiesAsync(); props[KnownContactProperties.MobileTelephone] = phone; await contact.SaveAsync(); } else { await AddContact(remoteId, givenName, familyName, phone); } }
private async void bt_add_Click(object sender, RoutedEventArgs e) { //创建一个系统通信可以读写和其他程序制度的联系人存储 ContactStore conStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); //新增联系人 ContactInformation conInfo = new ContactInformation(); //获取ContacInformation类的属性map表 var properties = await conInfo.GetPropertiesAsync(); //添加电话属性 properties.Add(KnownContactProperties.FamilyName, "test"); properties.Add(KnownContactProperties.Telephone, "123456789"); //创建联系人对象 StoredContact storedContact = new StoredContact(conStore, conInfo); //获取安装包的一张图片文件用作联系人的头像 StorageFile imagefile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("Assets/1.jpeg"); ///设置头像,将图片数据转化成Stream对象,在转化成IInputStream对象。 //打开文件的可读数据流 Stream stream = await imagefile.OpenStreamForReadAsync(); //用Stream对象转化成为IIputStream对象 IInputStream inputStream = stream.AsInputStream(); //用IInputStream 对象设置为联系人头像 await storedContact.SetDisplayPictureAsync(inputStream); //保存联系人 await storedContact.SaveAsync(); ///获取头像,接收到的图片数据为IRandomAccessStream类型,如果要展示出来,需要创建一个BitmapImage对象, IRandomAccessStream raStream = await storedContact.GetDisplayPictureAsync(); BitmapImage bi = new BitmapImage(); bi.SetSource(raStream); image.Source = bi; }
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); } }
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(); }
public async void Save(StoredContactViewModel contactViewModel) { await CheckForContactStore(); var contact = new StoredContact(ContactStore) { RemoteId = await _remoteIdHelper.GetTaggedRemoteId(ContactStore, contactViewModel.EMail), DisplayName = contactViewModel.NickName, GivenName = contactViewModel.FirstName, FamilyName = contactViewModel.FamilyName }; await contact.SaveAsync(); }
public async void Save(StoredContactViewModel contactViewModel) { await CheckForContactStore(); var contact = new StoredContact(ContactStore) { RemoteId = await _remoteIdHelper.GetTaggedRemoteId(ContactStore, contactViewModel.EMail), DisplayName = contactViewModel.NickName, GivenName = contactViewModel.FirstName, FamilyName = contactViewModel.FamilyName }; 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(); } }
/// <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(); } }
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(); }
private async void Save_Click(object sender, RoutedEventArgs e) { if (name.Text != "" && telphone.Text != "") { storCon.GivenName = name.Text; properties[KnownContactProperties.Telephone] = telphone.Text; await storCon.SaveAsync(); (Window.Current.Content as Frame).GoBack(); } else { await new MessageDialog("名字或电话不能为空").ShowAsync(); } }
private async void Button_Click_1(object sender, RoutedEventArgs e) { ContactStore contactStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); ContactInformation contactInformation=new ContactInformation(); var properties = await contactInformation.GetPropertiesAsync(); properties.Add(KnownContactProperties.FamilyName, name.Text); properties.Add(KnownContactProperties.Telephone, tel.Text); StoredContact storedContact = new StoredContact(contactStore, contactInformation); if (stream != null) { await storedContact.SetDisplayPictureAsync(stream); } await storedContact.SaveAsync(); NavigationService.GoBack(); }
private async void Save_Click(object sender, EventArgs e) { if (contact == null) { contact = new StoredContact(store); } IDictionary <string, object> properties = await contact.GetPropertiesAsync(); contact.GivenName = firstNameInput.Text; contact.FamilyName = lastNameInput.Text; properties[KnownContactProperties.Email] = emailInput.Text; properties[KnownContactProperties.Telephone] = phoneInput.Text; await contact.SaveAsync(); NavigationService.GoBack(); }
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(); }
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(); } }
private async void bt_add_Click(object sender, RoutedEventArgs e) { //创建一个系统通信可以读写和其他程序制度的联系人存储 ContactStore conStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); //新增联系人 ContactInformation conInfo = new ContactInformation(); //获取ContacInformation类的属性map表 var properties = await conInfo.GetPropertiesAsync(); //添加电话属性 properties.Add(KnownContactProperties.FamilyName, "test"); properties.Add(KnownContactProperties.Telephone, "123456789"); //创建联系人对象 StoredContact storedContact = new StoredContact(conStore, conInfo); //获取安装包的一张图片文件用作联系人的头像 StorageFile imagefile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("Assets/1.jpeg"); ///设置头像,将图片数据转化成Stream对象,在转化成IInputStream对象。 //打开文件的可读数据流 Stream stream = await imagefile.OpenStreamForReadAsync(); //用Stream对象转化成为IIputStream对象 IInputStream inputStream = stream.AsInputStream(); //用IInputStream 对象设置为联系人头像 await storedContact.SetDisplayPictureAsync(inputStream); //保存联系人 await storedContact.SaveAsync(); ///获取头像,接收到的图片数据为IRandomAccessStream类型,如果要展示出来,需要创建一个BitmapImage对象, IRandomAccessStream raStream = await storedContact.GetDisplayPictureAsync(); BitmapImage bi = new BitmapImage(); bi.SetSource(raStream); image.Source = bi; }
private async Task EnsureProvisioned(ContactStore store) { if (AppGlobalStateManager.Current.LoggedInUserId != 0L) { bool flag = true; string text = ContactsManager.GetRemoteId(AppGlobalStateManager.Current.GlobalState.LoggedInUser); try { if (await store.FindContactByRemoteIdAsync(text) == null) { flag = false; } } catch (Exception) { flag = false; } if (!flag) { try { StoredContact arg_159_0 = await store.CreateMeContactAsync(text); arg_159_0.DisplayName = (AppGlobalStateManager.Current.GlobalState.LoggedInUser.Name); await arg_159_0.SaveAsync(); } catch { } try { await SocialManager.ProvisionAsync(); } catch { } } text = null; } }
private async Task EnsureProvisioned(ContactStore store) { if (AppGlobalStateManager.Current.LoggedInUserId == 0L) { return; } bool ok = true; string meRemoteId = ContactsManager.GetRemoteId(AppGlobalStateManager.Current.GlobalState.LoggedInUser); try { if (await store.FindContactByRemoteIdAsync(meRemoteId) == null) { ok = false; } } catch { ok = false; } if (!ok) { StoredContact meContactAsync = await store.CreateMeContactAsync(meRemoteId); string name = AppGlobalStateManager.Current.GlobalState.LoggedInUser.Name; meContactAsync.DisplayName = name; await meContactAsync.SaveAsync(); try { await SocialManager.ProvisionAsync(); } catch { } } meRemoteId = null; }
private async void Save_Click(object sender, RoutedEventArgs e) { string message = ""; if (name.Text != "" && telphone.Text != "") { try { //创建一个联系人的信息对象 ContactInformation conInfo = new ContactInformation(); //获取联系人的属性字典 var properties = await conInfo.GetPropertiesAsync(); //添加联系人的属性 properties.Add(KnownContactProperties.GivenName, name.Text); properties.Add(KnownContactProperties.Telephone, telphone.Text); //创建或者打开联系人存储 ContactStore conStore = await ContactStore.CreateOrOpenAsync(); StoredContact storedContact = new StoredContact(conStore, conInfo); //保存联系人 await storedContact.SaveAsync(); message = "保存成功"; } catch (Exception ex) { message = "保存失败,错误信息:" + ex.Message; } } else { message = "名字或电话不能为空"; } await new MessageDialog(message).ShowAsync(); (Window.Current.Content as Frame).Navigate(typeof(ContactsList)); }
/// <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 SyncContactsAsync(List <User> friendsList) { if (this._synching || this._deleting) { return; } this._synching = true; friendsList = friendsList.Take <User>(ContactsManager.MAX_FRIENDS_TO_SYNC).ToList <User>(); long initiallyLoggedInUser = AppGlobalStateManager.Current.LoggedInUserId; try { SavedContacts savedContacts = await this.GetSavedList(); List <User> savedList = savedContacts.SavedUsers; Func <User, string> getKey = (Func <User, string>)(u => u.uid.ToString()); List <Tuple <User, User> > updatedUsersTuples; List <User> createdUsers; List <User> deletedUsers; ListUtils.GetListChanges <User>(savedList, friendsList, getKey, (Func <User, User, bool>)((u1, u2) => { if (ContactsManager.AreStringsEqualOrNullEmpty(u1.first_name, u2.first_name) && ContactsManager.AreStringsEqualOrNullEmpty(u1.last_name, u2.last_name) && (ContactsManager.AreStringsEqualOrNullEmpty(u1.mobile_phone, u2.mobile_phone) && ContactsManager.AreStringsEqualOrNullEmpty(u1.home_phone, u2.home_phone)) && (ContactsManager.AreStringsEqualOrNullEmpty(u1.site, u2.site) && ContactsManager.AreStringsEqualOrNullEmpty(u1.bdate, u2.bdate))) { return(ContactsManager.AreStringsEqualOrNullEmpty(u1.photo_max, u2.photo_max)); } return(false); }), out updatedUsersTuples, out createdUsers, out deletedUsers); Logger.Instance.Info("ContactsManager got {0} updated users, {1} new users, {2} deleted users", updatedUsersTuples.Count, createdUsers.Count, deletedUsers.Count); int totalCountToSync = createdUsers.Count; int currentSyncing = 0; if (initiallyLoggedInUser != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts) { await this.DoDeleteAllContactsAsync(); } else { ContactStore contactStore = await ContactStore.CreateOrOpenAsync(); await this.EnsureProvisioned(contactStore); StoredContact meContact = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(AppGlobalStateManager.Current.GlobalState.LoggedInUser)); if (meContact != null) { await this.SetContactProperties(meContact, AppGlobalStateManager.Current.GlobalState.LoggedInUser, (User)null); await meContact.SaveAsync(); } contactStore.CreateContactQuery(); foreach (Tuple <User, User> tuple in updatedUsersTuples) { User updUser = tuple.Item2; User originalUser = tuple.Item1; if (initiallyLoggedInUser != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts) { await this.DoDeleteAllContactsAsync(); return; } try { StoredContact contact = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(updUser)); await this.SetContactProperties(contact, updUser, originalUser); if (contact != null) { await contact.SaveAsync(); } contact = null; } catch (Exception ex) { Logger.Instance.Error("Failed to update contact for user " + updUser.Name, ex); } updUser = (User)null; originalUser = (User)null; } //List<Tuple<User, User>>.Enumerator enumerator1 = new List<Tuple<User, User>>.Enumerator(); foreach (User user in createdUsers) { User newUser = user; ++currentSyncing; if (initiallyLoggedInUser != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts) { await this.DoDeleteAllContactsAsync(); return; } try { if (await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(newUser)) == null) { Stopwatch sw = Stopwatch.StartNew(); this.FireSyncStatusChanged(currentSyncing, totalCountToSync); Logger.Instance.Info("ContactsManager begin creating user"); StoredContact contact = new StoredContact(contactStore); await this.SetContactProperties(contact, newUser, null); await contact.SaveAsync(); Logger.Instance.Info("ContactsManager end creating user"); sw.Stop(); long num = 500L - sw.ElapsedMilliseconds; if (num > 0L) { await Task.Delay((int)num); } sw = null; contact = null; } savedList.Add(newUser); } catch (Exception ex) { Logger.Instance.Error("Failed to create contact for user " + newUser.Name, ex); } newUser = null; } //List<User>.Enumerator enumerator2 = new List<User>.Enumerator(); foreach (User user in deletedUsers) { User deletedUser = user; if (initiallyLoggedInUser != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts) { await this.DoDeleteAllContactsAsync(); return; } try { StoredContact contactByRemoteIdAsync = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(deletedUser)); if (contactByRemoteIdAsync != null) { await contactStore.DeleteContactAsync(contactByRemoteIdAsync.Id); } savedList.Remove(deletedUser); } catch (Exception ex) { Logger.Instance.Error("Failed to delete contact for user " + deletedUser.Name, ex); } deletedUser = null; } //enumerator2 = new List<User>.Enumerator(); savedContacts.SyncedDate = DateTime.UtcNow; await this.EnsurePersistSavedContactsAsync(); savedContacts = null; savedList = null; deletedUsers = null; createdUsers = null; updatedUsersTuples = null; contactStore = null; meContact = null; } } catch (Exception ex) { Logger.Instance.Error("Failed to sync contacts. ", ex); } finally { this._synching = false; this.FireSyncStatusChanged(0, 0); } }
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) { } }
/// <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(); } }
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 Task SyncContactsAsync(List <User> friendsList) { if (!this._synching && !this._deleting) { this._synching = true; friendsList = Enumerable.ToList <User>(Enumerable.Take <User>(friendsList, ContactsManager.MAX_FRIENDS_TO_SYNC)); long loggedInUserId = AppGlobalStateManager.Current.LoggedInUserId; try { SavedContacts savedContacts = await this.GetSavedList(); SavedContacts savedContacts2 = savedContacts; List <User> list = savedContacts2.SavedUsers; List <User> arg_1E7_0 = list; List <User> arg_1E7_1 = friendsList; Func <User, string> arg_1E7_2 = new Func <User, string>((u) => { return(u.uid.ToString()); }); Func <User, User, bool> arg_1E7_3 = new Func <User, User, bool>((u1, u2) => { return(ContactsManager.AreStringsEqualOrNullEmpty(u1.first_name, u2.first_name) && ContactsManager.AreStringsEqualOrNullEmpty(u1.last_name, u2.last_name) && ContactsManager.AreStringsEqualOrNullEmpty(u1.mobile_phone, u2.mobile_phone) && ContactsManager.AreStringsEqualOrNullEmpty(u1.home_phone, u2.home_phone) && ContactsManager.AreStringsEqualOrNullEmpty(u1.site, u2.site) && ContactsManager.AreStringsEqualOrNullEmpty(u1.bdate, u2.bdate) && ContactsManager.AreStringsEqualOrNullEmpty(u1.photo_max, u2.photo_max)); }); List <Tuple <User, User> > list2; List <User> list3; List <User> list4; ListUtils.GetListChanges <User>(arg_1E7_0, arg_1E7_1, arg_1E7_2, arg_1E7_3, out list2, out list3, out list4); Logger.Instance.Info("ContactsManager got {0} updated users, {1} new users, {2} deleted users", new object[] { list2.Count, list3.Count, list4.Count }); int count = list3.Count; int num = 0; if (loggedInUserId != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts) { await this.DoDeleteAllContactsAsync(); } else { ContactStore contactStore = await ContactStore.CreateOrOpenAsync(); await this.EnsureProvisioned(contactStore); StoredContact storedContact = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(AppGlobalStateManager.Current.GlobalState.LoggedInUser)); if (storedContact != null) { await this.SetContactProperties(storedContact, AppGlobalStateManager.Current.GlobalState.LoggedInUser, null); await storedContact.SaveAsync(); } contactStore.CreateContactQuery(); List <Tuple <User, User> > .Enumerator enumerator = list2.GetEnumerator(); //int num2; try { while (enumerator.MoveNext()) { Tuple <User, User> var_8_57F = enumerator.Current; User user = var_8_57F.Item2; User originalUser = var_8_57F.Item1; if (loggedInUserId != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts) { await this.DoDeleteAllContactsAsync(); return; } try { StoredContact storedContact2 = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(user)); await this.SetContactProperties(storedContact2, user, originalUser); if (storedContact2 != null) { await storedContact2.SaveAsync(); } storedContact2 = null; } catch (Exception var_9_7B5) { Logger.Instance.Error("Failed to update contact for user " + user.Name, var_9_7B5); } user = null; originalUser = null; } } finally { //if (num2 < 0) //{ enumerator.Dispose(); //} } enumerator = default(List <Tuple <User, User> > .Enumerator); List <User> .Enumerator enumerator2 = list3.GetEnumerator(); try { while (enumerator2.MoveNext()) { User user2 = enumerator2.Current; num++; if (loggedInUserId != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts) { await this.DoDeleteAllContactsAsync(); return; } try { if (await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(user2)) == null)//todo:bug? { Stopwatch stopwatch = Stopwatch.StartNew(); this.FireSyncStatusChanged(num, count); Logger.Instance.Info("ContactsManager begin creating user", new object[0]); StoredContact storedContact3 = new StoredContact(contactStore); await this.SetContactProperties(storedContact3, user2, null); await storedContact3.SaveAsync(); Logger.Instance.Info("ContactsManager end creating user", new object[0]); stopwatch.Stop(); long var_11_AF3 = 500L - stopwatch.ElapsedMilliseconds; if (var_11_AF3 > 0L) { await Task.Delay((int)var_11_AF3); } stopwatch = null; storedContact3 = null; } list.Add(user2); } catch (Exception var_12_B82) { Logger.Instance.Error("Failed to create contact for user " + user2.Name, var_12_B82); } user2 = null; } } finally { //if (num2 < 0) //{ enumerator2.Dispose(); //} } enumerator2 = default(List <User> .Enumerator); enumerator2 = list4.GetEnumerator(); try { while (enumerator2.MoveNext()) { User user3 = enumerator2.Current; if (loggedInUserId != AppGlobalStateManager.Current.LoggedInUserId || !AppGlobalStateManager.Current.GlobalState.SyncContacts) { await this.DoDeleteAllContactsAsync(); return; } try { StoredContact var_13_D35 = await contactStore.FindContactByRemoteIdAsync(ContactsManager.GetRemoteId(user3)); if (var_13_D35 != null) { await contactStore.DeleteContactAsync(var_13_D35.Id); } list.Remove(user3); } catch (Exception var_14_DBF) { Logger.Instance.Error("Failed to delete contact for user " + user3.Name, var_14_DBF); } user3 = null; } } finally { //if (num2 < 0) //{ enumerator2.Dispose(); //} } enumerator2 = default(List <User> .Enumerator); savedContacts2.SyncedDate = DateTime.UtcNow; await this.EnsurePersistSavedContactsAsync(); savedContacts2 = null; list = null; list4 = null; list3 = null; list2 = null; contactStore = null; storedContact = null; } } catch (Exception var_15_ECB) { Logger.Instance.Error("Failed to sync contacts. ", var_15_ECB); } finally { //int num2; //if (num2 < 0) //{ this._synching = false; this.FireSyncStatusChanged(0, 0); //} } } }