public async void LoadDataFromSmartStore(bool includeEdit) { if (!_store.HasSoup(NotesSoup)) { NotifyNotesSynced(); return; } QuerySpec querySpec = QuerySpec.BuildAllQuerySpec(NotesSoup, NoteObject.TitleField, QuerySpec.SqlOrder.ASC, Limit); CoreDispatcher core = CoreApplication.MainView.CoreWindow.Dispatcher; JArray results = _store.Query(querySpec, 0); if (results == null) { NotifyNotesSynced(); return; } NoteObject[] notes; if (includeEdit) { notes = (from note in results let model = new NoteObject(note.Value <JObject>()) select model).ToArray(); } else { notes = (from note in results let model = new NoteObject(note.Value <JObject>()) where !model.ObjectId.Contains("local") orderby model.Title select model).ToArray(); } string[] references = (from note in notes let title = note.Title[0].ToString().ToLower() group note by title into g orderby g.Key select g.Key).ToArray(); await core.RunAsync(CoreDispatcherPriority.Normal, () => IndexReference.Clear()); await core.RunAsync(CoreDispatcherPriority.Normal, () => IndexReference.Add("all")); for (int i = 0, max = references.Length; i < max; i++) { int closure = i; await core.RunAsync(CoreDispatcherPriority.Normal, () => IndexReference.Add(references[closure])); } for (int i = 0, max = notes.Length; i < max; i++) { NoteObject t = notes[i]; await UpdateNote(t); } NotifyNotesSynced(); await core.RunAsync(CoreDispatcherPriority.Normal, () => MainPage.MainPageReference.UpdateTable()); }
public async void LoadDataFromSmartStore(bool includeEdit) { if (!_store.HasSoup(ContactSoup)) { NotifyContactsSynced(); return; } QuerySpec querySpec = QuerySpec.BuildAllQuerySpec(ContactSoup, ContactObject.LastNameField, QuerySpec.SqlOrder.ASC, Limit); CoreDispatcher core = CoreApplication.MainView.CoreWindow.Dispatcher; JArray results = _store.Query(querySpec, 0); if (results == null) { NotifyContactsSynced(); return; } ContactObject[] contacts; if (includeEdit) { contacts = (from contact in results let model = new ContactObject(contact.Value <JObject>()) select model).ToArray(); } else { contacts = (from contact in results let model = new ContactObject(contact.Value <JObject>()) where !model.ObjectId.Contains("local") orderby model.ContactName select model).ToArray(); } var references = (from contact in contacts let first = contact.ContactName[0].ToString().ToLower() group contact by first into g orderby g.Key select g.Key).ToArray(); await core.RunAsync(CoreDispatcherPriority.Normal, () => IndexReference.Clear()); await core.RunAsync(CoreDispatcherPriority.Normal, () => IndexReference.Add("all")); for (int i = 0, max = references.Length; i < max; i++) { var closure = i; await core.RunAsync(CoreDispatcherPriority.Normal, () => IndexReference.Add(references[closure])); } for (int i = 0, max = contacts.Length; i < max; i++) { ContactObject t = contacts[i]; await UpdateContact(t); } NotifyContactsSynced(); await core.RunAsync(CoreDispatcherPriority.Normal, () => MainPage.MainPageReference.UpdateTable()); }