コード例 #1
0
        private async void FindMoreResults()
        {
            // Prevent any double task
            _previousTokenSource?.Cancel(true);
            //TODO : wait the canceled task.
            _currentTokenSource  = new CancellationTokenSource();
            _previousTokenSource = _currentTokenSource;

            try
            {
                _currentTokenSource.Token.ThrowIfCancellationRequested();
                IsProcesssing = true;

                var data = await Task.Factory.StartNew(() =>
                {
                    if (ManufacturerSelectionEnabled)
                    {
                        return(DatasheetDataSource.SearchForDatasheet(Query, _currentTokenSource.Token, _selectedManufacturers));
                    }
                    return(DatasheetDataSource.SearchForDatasheet(Query, _currentTokenSource.Token));
                }, _currentTokenSource.Token);

                _currentTokenSource.Token.ThrowIfCancellationRequested();

                _datasheets.Clear();
                Datasheets.UnionWith(data);
                NotifyOfPropertyChange(nameof(Datasheets));
                NotifyOfPropertyChange(nameof(DatasheetsCount));
                ViewDatasheets = new Common.IncrementalLoadingDatasheetList(Datasheets.ToList(), _ungroupedManufacters);
                IsMoreResult   = false;

                _currentTokenSource.Token.ThrowIfCancellationRequested();
                await ViewDatasheets.LoadMoreItemsAsync(120);

                _currentTokenSource.Token.ThrowIfCancellationRequested();

                IsProcesssing = false;
            }
            catch (OperationCanceledException) { }
        }
コード例 #2
0
        // TODO : quand on recherche avec tout les résultats, conserver seulement les manufacturers concernés
        /// <summary>
        /// Searches matching part datasheet in SQLite database.
        /// The criteria used to query the database are the selected manufacturers and the user query (from 'selectedManufacturers' and 'Query').
        /// </summary>
        private async void QueryForDatasheets()
        {
            // Cancel old datasheet queries and create a new CancellationTokenSource
            if (_previousTokenSource != null)
            {
                _previousTokenSource.Cancel(true);
            }
            // TODO : wait for the canceled task (task cancelling is not instantaneous !)
            _currentTokenSource  = new CancellationTokenSource();
            _previousTokenSource = _currentTokenSource;

            IsZeroManufacturerSelected = false;
            IsEmptyResult = false;
            // TODO : règler le problème d'affichage de "0 datasheet trouvées" pendant la recherche ! (cf TODO dans le XAML)
            IsMoreResult = false;

            try
            {
                if (IsAnyQuery)
                {
                    _currentTokenSource.Token.ThrowIfCancellationRequested();
                    IsProcesssing = true;

                    if (_datasheets.Count != 0)
                    {
                        _datasheets.Clear();
                        NotifyOfPropertyChange <HashSet <Part> >(() => Datasheets);
                        NotifyOfPropertyChange <int>(() => DatasheetsCount);
                    }

                    IList <Part> data = await Task.Factory.StartNew(() =>
                    {
                        if (ManufacturerSelectionEnabled)
                        {
                            return(DatasheetDataSource.SearchForDatasheet(Query, _currentTokenSource.Token, _selectedManufacturers, FIRST_SEARCH_RANGE));
                        }
                        return(DatasheetDataSource.SearchForDatasheet(Query, _currentTokenSource.Token, FIRST_SEARCH_RANGE));
                    }, _currentTokenSource.Token);

                    _currentTokenSource.Token.ThrowIfCancellationRequested();

                    Datasheets.UnionWith(data);
                    NotifyOfPropertyChange(nameof(Datasheets));
                    NotifyOfPropertyChange(nameof(DatasheetsCount));
                    // Preparation de l'incremental loading et affichage de la première page.
                    ViewDatasheets = new Common.IncrementalLoadingDatasheetList(Datasheets.ToList(), _ungroupedManufacters);
                    IsMoreResult   = Datasheets.Count == FIRST_SEARCH_RANGE;

                    _currentTokenSource.Token.ThrowIfCancellationRequested();
                    await ViewDatasheets.LoadMoreItemsAsync(FIRST_SEARCH_RANGE);

                    _currentTokenSource.Token.ThrowIfCancellationRequested();

                    IsProcesssing = false;
                }

                _currentTokenSource.Token.ThrowIfCancellationRequested();

                if (Datasheets.Count == 0)
                {
                    if (ManufacturerSelectionEnabled && _selectedManufacturers.Count == 0)
                    {
                        IsZeroManufacturerSelected = true;
                    }
                    else
                    {
                        IsEmptyResult = true;
                    }
                }
                else
                {
                    IsZeroManufacturerSelected = false;
                    IsEmptyResult = false;
                }
            }
            catch (OperationCanceledException) { }
        }