/// <summary> /// Asynchronously loads the next page of data results into the <see cref="T:System.Data.Services.Client.DataServiceCollection`1"/>. /// </summary> /// <typeparam name="T">Entity type of the <see cref="T:System.Data.Services.Client.DataServiceCollection`1"/> instance.</typeparam> /// <param name="bindingCollection">The <see cref="T:System.Data.Services.Client.DataServiceCollection`1"/> instance on which this extension method is enabled.</param> /// <returns>A <see cref="T:System.Threading.Tasks.Task`1"/> that, when completed, returns a <see cref="T:System.Data.Services.Client.LoadCompletedEventArgs"/>.</returns> public static async Task <LoadCompletedEventArgs> LoadNextPartialSetAsync <T>(this DataServiceCollection <T> bindingCollection) { var tcs = new TaskCompletionSource <LoadCompletedEventArgs>(); EventHandler <LoadCompletedEventArgs> handler = delegate(object o, LoadCompletedEventArgs e) { if (e.Error != null) { tcs.TrySetException(e.Error); } else if (e.Cancelled) { tcs.TrySetCanceled(); } else { tcs.TrySetResult(e); } }; bindingCollection.LoadCompleted += handler; bindingCollection.LoadNextPartialSetAsync(); LoadCompletedEventArgs eventArgs = await tcs.Task; bindingCollection.LoadCompleted -= handler; return(eventArgs); }
// Handles the LoadCompleted event. private void Photos_LoadCompleted(object sender, LoadCompletedEventArgs e) { if (e.Error == null) { // Make sure that we load all pages of the Customers feed. if (_photos.Continuation != null) { // Request the next page from the data service. _photos.LoadNextPartialSetAsync(); } else { // All pages are loaded. IsDataLoaded = true; } } else { if (MessageBox.Show(e.Error.Message, "Retry request?", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { this.LoadData(); } } }
//This is akin to ServiceConnected in Android Map2DOnline private static void buildings_LoadCompleted(object sender, LoadCompletedEventArgs e) { if (e.Error == null) { // Handling for a paged data feed. if (buildings.Continuation != null) { // Automatically load the next page. buildings.LoadNextPartialSetAsync(); } else { //The data is ready foreach (Building b in buildings) { CurrentBuilding = b; //TODO: Currently, LoadEdges just loops through the edges and does nothing LoadEdges(CurrentBuilding); break; } } } else { CurrentBuilding = null; } //Now notify the observers //we just let the observers know that something has happened. //They can then check if CurrentBuilding != null //TODO: MAYBE just replace this with WifiStatusChanged, where the Status is RADIOMAP_DOWNLOADED if (OnBuildingDownload != null) //any observers? OnBuildingDownload(null, null); }
public void LoadAsyncTest() { var context = this.CreateWrappedContext <DefaultContainer>().Context; var query = context.Customer; var dataServiceCollection = new DataServiceCollection <Customer>(); dataServiceCollection.LoadCompleted += (sender, e) => { if (e.Error == null) { if (dataServiceCollection.Continuation != null) { dataServiceCollection.LoadNextPartialSetAsync(); } else { this.EnqueueTestComplete(); Assert.Equal(10, dataServiceCollection.Count); } } }; dataServiceCollection.LoadAsync(query); this.WaitForTestToComplete(); }
/// <summary> /// Invoked when a filter is selected using the ComboBox in snapped view state. /// </summary> /// <param name="sender">The ComboBox instance.</param> /// <param name="e">Event data describing how the selected filter was changed.</param> void Filter_SelectionChanged(object sender, SelectionChangedEventArgs e) { // Determine what filter was selected var selectedFilter = e.AddedItems.FirstOrDefault() as Filter; if (selectedFilter != null) { // Mirror the results into the corresponding Filter object to allow the // RadioButton representation used when not snapped to reflect the change selectedFilter.Active = true; // TODO: Respond to the change in active filter by setting this.DefaultViewModel["Results"] // to a collection of items with bindable Image, Title, Subtitle, and Description properties DefaultViewModel["Results"] = null; // clear previous result DefaultViewModel["Results"] = new ObservableCollection <SearchResult>(); var searchText = DefaultViewModel["QueryText"] as string; if (!String.IsNullOrEmpty(searchText)) { NetflixCatalog catalog = new NetflixCatalog(netflixServiceUri); var query = catalog.Titles.Where(t => t.Name.Contains(searchText)).Select(t => t); var queryResults = new DataServiceCollection <Title>(); queryResults.LoadCompleted += (o, args) => { if (queryResults.Continuation != null) { queryResults.LoadNextPartialSetAsync(); } else { DefaultViewModel["Results"] = queryResults.Select(t => new { Title = t.Name, Subtitle = t.ShortName, Description = t.ShortSynopsis, Image = t.BoxArt.MediumUrl }).ToList(); // ensure that results are found object results; ICollection resultsCollection; if (this.DefaultViewModel.TryGetValue("Results", out results) && (resultsCollection = results as ICollection) != null && resultsCollection.Count != 0) { VisualStateManager.GoToState(this, "ResultsFound", true); } } }; queryResults.LoadAsync(query); } } // Display informational text when there are no search results. VisualStateManager.GoToState(this, "NoResultsFound", true); }
private void OnTitlesLoaded(object sender, LoadCompletedEventArgs e) { if (e.Error == null) { // Get the binding collection, which is the sender. DataServiceCollection <Title> loadedTitles = sender as DataServiceCollection <Title>; if (loadedTitles != null) { // Make sure that we load all pages of the Customers feed. if (loadedTitles.Continuation != null) { loadedTitles.LoadNextPartialSetAsync(); } // Set the total page count, if we requested one. if (e.QueryOperationResponse.Query .RequestUri.Query.Contains("$inlinecount=allpages")) { this.TotalCount = (int)e.QueryOperationResponse.TotalCount; } try { localDb.Titles.InsertAllOnSubmit <Title>(loadedTitles); // We want to try and add all the entities even if they already exist. localDb.SubmitChanges(ConflictMode.ContinueOnConflict); } catch (Exception) { // We don't care about general exceptions, which inculude SQL CE constraint // violations when we try to store the same entity twice, // so we just eat the error. } // Unregister the event handler. loadedTitles.LoadCompleted -= OnTitlesLoaded; // Set the binding collection to the loaded titles. this.Titles = loadedTitles; IsDataLoaded = true; } } else { // Display the error message in the binding. this.Message = e.Error.Message; } if (LoadCompleted != null) { LoadCompleted(this, new SourcesLoadCompletedEventArgs(e.Error)); } }
async void Collection_LoadCompleted(object sender, LoadCompletedEventArgs e) { if (e.Error == null) { if (_collection.Continuation != null) { _collection.LoadNextPartialSetAsync(); } TitleGrid.UpdateLayout(); } else { var dialog = new MessageDialog(e.Error.Message); await dialog.ShowAsync(); } }
private void complete(object sender, LoadCompletedEventArgs e) { if (e.Error == null) { if (inventories.Continuation != null) { inventories.LoadNextPartialSetAsync(); } else { foreach (var inv in inventories) { if (inv.id == 1000) { break; } } } } }
private void goods_complete(object sender, LoadCompletedEventArgs e) { if (e.Error == null) { if (goodses.Continuation != null) { goodses.LoadNextPartialSetAsync(); } else { foreach (var goods in goodses) { if (goods.id == 9999) { break; } } } } }
void products_LoadCompleted(object sender, LoadCompletedEventArgs e) { if (e.Error == null) { // Handling for a paged data feed. if (products.Continuation != null) { // Automatically load the next page. products.LoadNextPartialSetAsync(); } else { // Set the data context of the list box control to the sample data. //this.MainLongListSelector.DataContext = products; this.MainLongListSelector.ItemsSource = products; } } else { MessageBox.Show(string.Format("An error has occurred: {0}", e.Error.Message)); } }
protected override void LoadState(Object navigationParameter, Dictionary <String, Object> pageState) { // Initialize. oDataContext = new DataServiceContext(new Uri("http://apressodataservice.cloudapp.net/ApressOData.svc")); bookListFromService = new DataServiceCollection <ApressODataService.ApressBook>(oDataContext); // Fetch all the entities. Uri query = new Uri("/ApressBooks", UriKind.Relative); // Custom queries. //var bookCatalog = new ApressBookDBEntities(new Uri("http://apressodataservice.cloudapp.net/ApressOData.svc")); //var customQuery = (from Book in bookCatalog.ApressBooks // where Book.ApressBookTechnology == "Windows Phone" // select Book).Take(5); // Asynchronously load the fresh data from Service. bookListFromService.LoadAsync(query); // bookListFromService.LoadAsync(customQuery); // Completion event handler. bookListFromService.LoadCompleted += (sender, args) => { if (args.Error != null) { // Do appropriate error handling. } else { // Success. Bind to UI. this.odataBookListView.ItemsSource = bookListFromService; } }; if (bookListFromService.Continuation != null) { bookListFromService.LoadNextPartialSetAsync(); } }
public void LoadAsyncTest() { var context = this.CreateWrappedContext<DefaultContainer>().Context; var query = context.Customer; var dataServiceCollection = new DataServiceCollection<Customer>(); dataServiceCollection.LoadCompleted += (sender, e) => { if (e.Error == null) { if (dataServiceCollection.Continuation != null) { dataServiceCollection.LoadNextPartialSetAsync(); } else { this.EnqueueTestComplete(); Assert.AreEqual(10, dataServiceCollection.Count); } } }; dataServiceCollection.LoadAsync(query); this.WaitForTestToComplete(); }