// Private helpers
        private async Task PopulateArticles()
        {
            // 1. Clear existing data grid source
            Articles.Clear();

            List <Article> articles = new List <Article>();

            await Task.Run(() =>
            {
                // 2. Fetch artilces from database
                foreach (Article article in new ArticleRepo().LoadArticles(
                             Users[UserIndex],
                             FilterTitle,
                             FilterAuthors.ToList(),
                             FilterKeywords.ToList(),
                             FilterYear,
                             FilterPersonalComment,
                             _offset,
                             ItemsPerPage,
                             SelectedSection,
                             _currentSort))
                {
                    articles.Add(article);
                }
            });

            // 3. Populate article collection
            foreach (Article article in articles)
            {
                this.Articles.Add(article);
            }
        }
 public void Clear(object input = null)
 {
     FilterTitle = null;
     FilterAuthors.Clear();
     FilterKeywords.Clear();
     FilterYear            = null;
     FilterPersonalComment = null;
     Articles.Clear();
 }
        public async void LoadArticles(object input = null)
        {
            try
            {
                _workStatus(true);

                List <Article> articles = new List <Article>();
                await Task.Run(() =>
                {
                    // 2. Calculate total pages
                    int record_count = new ArticleRepo().GetRecordCount(
                        Users[UserIndex],
                        FilterTitle,
                        FilterAuthors.ToList(),
                        FilterKeywords.ToList(),
                        FilterYear,
                        FilterPersonalComment,
                        SelectedSection);
                    if ((record_count % ItemsPerPage) == 0)
                    {
                        TotalPages = record_count / ItemsPerPage;
                    }
                    else
                    {
                        TotalPages = (record_count / ItemsPerPage) + 1;
                    }

                    CurrentPage = 1;
                });

                await PopulateArticles();

                if (!string.IsNullOrEmpty(SelectedSection) && SelectedSection != "None")
                {
                    this.IsSectionSelected = true;
                }
                else
                {
                    this.IsSectionSelected = false;
                }

                _workStatus(false);
            }
            catch (Exception e)
            {
                new BugTracker().Track("Data View", "Load Articles", e.Message, e.StackTrace);
                _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error));
            }
            finally
            {
                _workStatus(false);
            }
        }
Beispiel #4
0
        private static Parser <string> ToKeyword(FilterKeywords keyword)
        {
            var keywordRegexp = keyword.GetDescription();

            return(Parse.Regex(keywordRegexp).Token());
        }