private void TimerTickSearch(object sender, EventArgs e)
        {
            timerSearch.Stop();
            cancellationTokenSource.Cancel();
            cancellationTokenSource = new CancellationTokenSource();

            HideNoResults();
            ShowLoader();

            Action search = async() =>
            {
                try
                {
                    PlacesOfInterest.Clear();

                    IEnumerable <Entities.PlaceOfInterest> results;

                    if (locationIsAllowed && user.LastKnownGeneralLocation != null && user.LastKnownGeneralLocation.IsValid())
                    {
                        results = await BumbleApiService.PlacesOfInterest(cancellationTokenSource.Token, user, SearchText, null);
                    }
                    else
                    {
                        results = await BumbleApiService.PlacesOfInterest(cancellationTokenSource.Token, user, SearchText, null);
                    }

                    PlacesOfInterest.AddRange(results.Where(x => poiCategories.Where(z => z.IsChecked).Select(y => y.Category).Contains(x.PlaceOfInterestCategory.Category)));

                    HideLoader();
                    if (PlacesOfInterest.Count() == 0)
                    {
                        ShowNoResults();
                    }

                    base.AddFeatureUse(PageUseType.TextBox, string.Format("Searched for [{0}]", searchText));
                }
                catch (Exception ex)
                {
                    if (ex.Message != AppResources.ApiErrorTaskCancelled)
                    {
                        base.ShowPopup(CustomPopupMessageType.Error, ex.Message, AppResources.CustomPopupGenericOkMessage, null);

                        base.AddFeatureUse(PageUseType.Error, string.Format("Error while searching. Reason: {0}", ex.Message));

                        HideLoader();
                        ShowNoResults();
                        ClearSearchTextBox();
                    }
                }
            };

            DispatcherHelper.CheckBeginInvokeOnUI(search);
        }
예제 #2
0
        private void AddSearchResultsNearby()
        {
            ShowLoader();
            Stations.Clear();
            SearchResults.Clear();

            cancellationTokenSource.Cancel();
            cancellationTokenSource = new CancellationTokenSource();

            Action search = async() =>
            {
                try
                {
                    SearchResults.Clear();

                    string[] categories = UnitOfWork.PlaceOfInterestCategoryRepository.GetAll().Where(x => x.Category != "Unknown").Select(x => x.Category).ToArray();

                    // Only search if we have user location
                    if (locationIsAllowed && user.LastKnownGeneralLocation != null && user.LastKnownGeneralLocation.IsValid())
                    {
                        SearchResults.AddRange(await BumbleApiService.PlacesOfInterest(cancellationTokenSource.Token, user, String.Empty, categories));

                        timerMapMoved.Start();
                    }
                }
                catch (Exception ex)
                {
                    if (ex.Message != AppResources.ApiErrorTaskCancelled)
                    {
                        base.ShowPopup(CustomPopupMessageType.Error, ex.Message, AppResources.CustomPopupGenericOkMessage, null);
                    }
                }

                ShowSearchList();
                HideHeaderLoader();
            };

            DispatcherHelper.CheckBeginInvokeOnUI(search);
        }