public async Task HandleAsync(SearchQuerySubmittedMessage message) { if (!NetworkInterface.GetIsNetworkAvailable()) { _statusService.SetNetworkUnavailable(); return; } _statusService.Message = "Loading Images for " + message.Query; _statusService.IsLoading = true; try { // Remove any existing searches for this query var searches = _settings.Searches; var existing = searches.FirstOrDefault(s => s.Query.Equals(message.Query, StringComparison.CurrentCultureIgnoreCase)); if (existing != null) { searches.Remove(existing); } // Search Bing var images = await _imageSearchService.Search(message.Query, _settings.Rating, _settings.ImageResultSize); if (!images.Any()) { _statusService.SetBingUnavailable(); return; } // Store results in app settings var instance = new SearchInstance() { Images = images, SearchedOn = DateTime.Today, Query = message.Query }; searches.Insert(0, instance); _settings.Searches = searches; _settings.SelectedInstance = instance; await _settings.SaveAsync(); // Navigate _navigationService.Navigate(typeof(SearchResultsPage)); } catch (InvalidOperationException ex) { var baseEx = ex.GetBaseException(); if (baseEx is WebException) { _statusService.SetBingUnavailable(); return; } throw; } finally { _statusService.IsLoading = false; } }
public async Task LoadMore(SearchInstance instance, Rating rating, ResultSize resultSize) { var imagesToAdd = await Search(instance.Query, rating, resultSize, instance.Images.Count + 1); foreach (var image in imagesToAdd) { instance.Images.Add(image); } }
public SearchInstance SampleSearchInstance( string query = "Sample Query", int imageCount = 10) { var instance = new SearchInstance() { Query = query, Images = new List <ImageResult>() }; for (int i = 0; i < imageCount; i++) { instance.Images.Add(new ImageResult() { Title = "Sample Image " + i, Thumbnail = new Thumbnail() { MediaUrl = "http://example.com/sample" + i + ".jpg" } }); } return(instance); }
public SearchResultsPageViewModelScenario() { var testInstance = new SearchInstance() { Query = "Search1", Images = new List <ImageResult>() { new ImageResult() { MediaUrl = "http://example.com" } } }; ApplicationSettings.Searches.Add(testInstance); ApplicationSettings.SelectedInstance = testInstance; _imageSearchService = new MockImageSearchService(); _accelerometer = new MockAccelerometer(); _sharePump = new MockShareDataRequestedPump(); ViewModel = new SearchResultsPageViewModel(ApplicationSettings, NavigationService, _imageSearchService, MessageHub, _accelerometer, new MockStatusService(), _sharePump); }
public bool SettingsSelectedInstanceIs(SearchInstance instance) { return(ApplicationSettings.SelectedInstance == instance); }
public void ChangingSelectedItemTo(SearchInstance instance) { ViewModel.SelectedItem = instance; }
public void Setup() { _instance = Given.SampleSearchInstance(); When.ChangingSelectedItemTo(_instance); }
public Task LoadMore(SearchInstance instance, Rating rating, ResultSize resultSize) { return(Task.Run(() => { })); }
public UpdateTileImageCollectionMessage(SearchInstance instance) { Instance = instance; }
public void UpdatingTileWith(SearchInstance ImageResult) { WhenHandling(() => new UpdateTileImageCollectionMessage(ImageResult)); }
public void Setup() { _instance = Given.SampleSearchInstance(); When.UpdatingTileWith(_instance); }