private async void ContactStore_ContactChanged(ContactStore sender, ContactChangedEventArgs args) { //while this function is open, we won't fire additional change events //this allows you to operate on the changes without worrying about simultaneos trackers being open //holding the defferal is necessary because of async'ness var defferal = args.GetDeferral(); ContactChangeReader reader = sender.ChangeTracker.GetChangeReader(); IReadOnlyList <ContactChange> changes = await reader.ReadBatchAsync(); while (changes.Count != 0) { foreach (ContactChange change in changes) { switch (change.ChangeType) { case ContactChangeType.Created: Debug.WriteLine("[created]" + change.Contact.Id + ": " + change.Contact.DisplayName); break; case ContactChangeType.Deleted: Debug.WriteLine("[deleted]" + change.Contact.Id + ": " + change.Contact.DisplayName); break; case ContactChangeType.Modified: Debug.WriteLine("[modified]" + change.Contact.Id + ": " + change.Contact.DisplayName); break; case ContactChangeType.ChangeTrackingLost: MessageDialog lostChangeTrackingWarning = new MessageDialog("The system has lost the change tracking information. " + "This shouldn't happen very often, but you should handle the case. " + "The expectation is that you'll re-read all of the contacts after this.", "Change tracking lost"); await lostChangeTrackingWarning.ShowAsync(); defferal.Complete(); //Returning since changes are no longer going to be valid after resetting //the change tracking return; default: //No-op on the default case for future proofing break; } } changes = await reader.ReadBatchAsync(); } //Let the system know that we have processed all the changes so the same changes aren't surfaced again reader.AcceptChanges(); defferal.Complete(); }
private void OnContactChanged(object sender, ContactChangedEventArgs e) { UberChatClient client = (UberChatClient) sender; ContactsNotificationService.JsContact contact = ContactsNotificationService.JsContact.Create(client, e.Contact); ContactsNotificationService.ApplyContactTransformations(contact); switch (e.ChangeType) { case ContactChangeType.Add: break; case ContactChangeType.Update: this.OnContactUpdated(client, contact); break; case ContactChangeType.Remove: this.OnContactRemoved(client, contact); break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Handle if contact changed. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void Store_ContactChanged(ContactStore sender, ContactChangedEventArgs args) { // throw new NotImplementedException(); }
private void _contactList_ContactChanged(ContactList sender, ContactChangedEventArgs args) { }
private void OnContactChanged(object sender, ContactChangedEventArgs args) { UberChatClient uberChatClient = (UberChatClient)sender; ContactsNotificationService.JsContact jsContact = ContactsNotificationService.JsContact.Create(uberChatClient, args.Contact); ContactsNotificationService.ApplyContactTransformations(jsContact); switch (args.ChangeType) { case ContactChangeType.Add: { return; } case ContactChangeType.Update: { this.OnContactUpdated(uberChatClient, jsContact); return; } case ContactChangeType.Remove: { this.OnContactRemoved(uberChatClient, jsContact); return; } } throw new ArgumentOutOfRangeException(); }