Esempio n. 1
0
        private async Task UpdateList()
        {
            // Get list of currently-reading books

            var startTime  = DateTime.Now;
            var search     = "";
            var searchType = uiShowDownloaded.IsChecked.Value ? "Downloaded" : "Reading";
            var sortBy     = "title";
            var language   = "en";

            List <BookData> resultList = null;
            bool            andMore    = false;

            Books.Clear();

            var searchTask = Task.Run(() => {
                var bookdb = BookDataContext.Get();
                lock (bookdb)
                {
                    resultList = AllBookSearch.SearchInternal(bookdb, searchType, search, language, sortBy, out andMore);
                }
            });
            await searchTask;

            // Finally add to the output
            foreach (var book in resultList)
            {
                Books.Add(new HelperBookDataWithSelected(book));
            }
        }
Esempio n. 2
0
        private async Task DoSearchAsync()
        {
            Books.Clear();
            EnsureBooksLoaded();
            SetSearchRingVisible(true);

            uiSearchStatus.Text = "..searching...";
            try
            {
                var startTime     = DateTime.Now;
                var search        = uiSearchFor.Text.Trim();
                var sortBy        = (uiSort.SelectedItem as ComboBoxItem)?.Tag as string;
                var language      = UserRequiredLanguageMatch;
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                localSettings.Values[SEARCH_SORT] = sortBy;

                List <BookData> resultList = null;
                bool            andMore    = false;

                var searchTask = Task.Run(() => {
                    var bookdb = BookDataContext.Get();
                    lock (bookdb)
                    {
                        resultList = AllBookSearch.SearchInternal(bookdb, SearchType, search, language, sortBy, out andMore);
                    }
                });
                await searchTask;

                // Finally add to the output
                foreach (var book in resultList)
                {
                    Books.Add(book);
                }
                var nmatch = Books.Count;
                uiSearchStatus.Text = andMore ? $"Found more than {AllBookSearch.MaxMatch} books" : $"Found {nmatch} books";

                var endTime = DateTime.Now;
                var smTime  = Math.Round(endTime.Subtract(startTime).TotalSeconds, 2);
                uiSearchStatus.Text += $"\nin {smTime} seconds";
            }
            catch (Exception ex)
            {
                uiSearchStatus.Text = $"ERROR: search threw an exception :-( ({ex.Message})";
            }

            SetSearchRingVisible(false);
        }