private void Initialize_Core() { //Generate collection of Notes Animate = true; Instructions = "Loading Contacts"; Task.Run(() => { var contacts = contactsManager.Get_Contacts_ByUserID <Contact>(Constants.InMemory_ContactID); if (contacts.Count != 0) { foreach (var contact in contacts) { contact.Contact_ID = contactsManager.Get_NewContactID(); CoreContactsCellViewModel obj = new CoreContactsCellViewModel(contact, dialogue, navigation); obj._DeleteContent += RemoveContact_FromCollection; obj._DisplayContact += DisplayContact_FromCollection; //Subscriptions this.Contacts.Add(obj); } } this.Contacts.CollectionChanged += Contacts_CollectionChanged; }).ContinueWith((e) => { Device.BeginInvokeOnMainThread(() => { Animate = false; ReloadData = true; }); }); }
public void OnRefresh() { //Start querying the Instructions = "Downloading Contacts"; Animate = true; Refreshing = true; //Diagnostics string Message = string.Empty;; string StackTrace = string.Empty; bool _AnyError = false; Task.Run(() => { //Query the user's data from the back end SSMS try { var contactsCollection = new ObservableCollection <CoreContactsCellViewModel>(); var curr = new List <Contact>(); var obj = new List <CoreContactsCellViewModel>(); this.Contacts.Clear(); contactsManager.ClearContacts_ForUserID(Constants.InMemory_ContactID); DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl)); var server_contacts = dataService._GetContacts_ByUserID(Constants.InMemory_ContactID); var contacts = contactStore.Get_ContactsFromStore <Contact>(); if (contacts != null) { contacts.ForEach(w => { //Add Contact to the contact store for the particular account w.Sys_Creation = DateTime.Now; w.Sys_Transaction = DateTime.Now; w.Contact_ID = contactsManager.Get_NewContactID(); w.User_ID = Constants.InMemory_ContactID; //Add to Local Collection var cObj = new CoreContactsCellViewModel(w, dialogue, navigation); cObj._DeleteContent += RemoveContact_FromCollection; if (!curr.Contains(w)) { curr.Add(w); } if (!obj.Contains(cObj)) { obj.Add(cObj); } }); } if (server_contacts._Contacts != null) { server_contacts._Contacts.ForEach(w => { //Add Contacts to Table var csObj = new CoreContactsCellViewModel(LocalMapper.MapContact_FromServer(w), dialogue, navigation); csObj._DeleteContent += RemoveContact_FromCollection; if (!curr.Contains(LocalMapper.MapContact_FromServer(w))) { curr.Add(LocalMapper.MapContact_FromServer(w)); } if (!obj.Contains(csObj)) { obj.Add(csObj); } }); } if (contactsManager != null && curr.Count != 0) { contactsManager.AddContacts_ByDetails(curr); } Initialize_Core(); // MessagingCenter.Send<ContactsViewModel>(this, _ContactsUpdate); } catch (Exception ex) { _AnyError = true; if (ex.InnerException != null) { Message = ex.InnerException.Message; StackTrace = ex.InnerException.StackTrace; } else { Message = ex.Message; StackTrace = ex.StackTrace; } var mEx = new Exceptions(logging, Message, StackTrace); if (mEx != null) { mEx.HandleException(mEx, logging); } } finally { //dispose of any memory here } }).ContinueWith((e) => { //Hide the animator when done //If any errors occur render them on the dialogue service Device.BeginInvokeOnMainThread(() => { Animate = false; Refreshing = false; if (dialogue != null && _AnyError) { dialogue.ShowAlert("mmm...Something went wrong", Message); } }); }); }