Exemple #1
0
        private void GalleryWebBrowser_PreloadDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            SearchArg searchArg = webBrowser.Tag as SearchArg;

            if (searchArg == null)
            {
                return;
            }

            if (listBackgroundWorker.IsBusy)
            {
                return;
            }

            SearchDoArg searchDoArg = new SearchDoArg(searchArg, TagsModel, SearchHandler, GalleryBrowserSettings.SortType, GalleryBrowserSettings.SortOrder, MetadataKeywordLists);

            listBackgroundWorker.RunWorkerAsync(searchDoArg);
        }
Exemple #2
0
        private static void ListBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;
            SearchDoArg      searchDoArg      = e.Argument as SearchDoArg;

            if (searchDoArg == null)
            {
                return;
            }

            SearchArg         searchArg         = searchDoArg.SearchArg;
            SearchProgressArg searchProgressArg = null;
            int          currentPage            = searchArg.PageIndex;
            SearchResult searchResult           = null;

            /*
             * bool loadAll = false;   // TODO: read this from settings.Download.LoadAll
             *
             * do
             * {
             */
            try
            {
                if (searchArg.Target == SearchTarget.Query)
                {
                    searchResult = searchDoArg.SearchHandler.Search(searchArg.Query, currentPage);
                }
                else if (searchArg.Target == SearchTarget.Tagged)
                {
                    searchResult = searchDoArg.SearchHandler.TaggedSearch(searchArg.TagId, currentPage);
                }
                else if (searchArg.Target == SearchTarget.Recent)
                {
                    searchResult = searchDoArg.SearchHandler.RecentSearch(currentPage);
                }

                if (searchResult == null)
                {
                    e.Cancel = true;
                    return;
                }

                searchDoArg.TagsModel.CollectTags(searchResult);

                searchProgressArg = new SearchProgressArg(searchArg, searchResult, currentPage, searchDoArg.MetadataKeywordLists, searchDoArg.SortType, searchDoArg.SortOrder);

                backgroundWorker.ReportProgress(searchResult.NumPages > 0 ? (int)(currentPage / (float)searchResult.NumPages * 100) : 100, searchProgressArg);
            }
            catch (Exception ex)
            {
                SearchErrorArg errorArg = new SearchErrorArg(searchArg, currentPage, (ex.InnerException != null) ? string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", ex.Message, Environment.NewLine, ex.InnerException.Message) : ex.Message);

                backgroundWorker.ReportProgress(0, errorArg);
            }

            /*
             * } while (loadAll
             *      && searchResult != null
             *      && ++currentPage < searchResult.NumPages);
             */

            if (searchResult != null &&
                searchResult.Result != null)
            {
                /*if (searchDoArg.SortType != GallerySortType.None)
                 * {
                 *      searchResult = OrderByMetadata(searchResult, searchDoArg.SortType, searchDoArg.SortOrder);
                 * }*/

                e.Result = new SearchResultArg(searchArg, searchResult);
            }
        }