private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!e.Cancelled) { LibraryLoadCompletedArg completedArg = e.Result as LibraryLoadCompletedArg; SearchProgressArg searchProgressArg = new SearchProgressArg(completedArg.RunArg.SearchArg, completedArg.SearchResult, completedArg.RunArg.SearchArg.PageIndex, MetadataKeywordLists, completedArg.RunArg.SortType, completedArg.RunArg.SortOrder); //searchResult = completedArg.SearchResult; webBrowser.Tag = searchProgressArg; webBrowser.DocumentText = LibraryCovergridTemplate.GetFormattedText(searchProgressArg); } }
private static void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker backgroundWorker = sender as BackgroundWorker; LibraryLoadRunArg runArg = e.Argument as LibraryLoadRunArg; List <int> galleryIds = new List <int>(); SearchResult searchResult = new SearchResult(); searchResult.Result = new List <Metadata>(); searchResult.PerPage = runArg.NumItemsPerPage; if (Directory.Exists(runArg.LibraryPath)) { DirectoryInfo dirInfo = new DirectoryInfo(runArg.LibraryPath); IEnumerable <DirectoryInfo> dirInfos = runArg.PathFormatter.IsEnabled ? dirInfo.EnumerateDirectories("*", SearchOption.AllDirectories) : dirInfo.EnumerateDirectories(); dirInfos = dirInfos.OrderAllByTime(runArg.GlobalSortType, runArg.GlobalSortOrder); int skipCount = (runArg.SearchArg.PageIndex - 1) * searchResult.PerPage; int itemCount = 0; int totalItemCount = 0; foreach (DirectoryInfo subDirInfo in dirInfos) { int galleryId = ExtractGalleryIdFromFileName(subDirInfo.Name); if (galleryId == -1) { continue; } ++totalItemCount; if (skipCount > 0) { --skipCount; continue; } if (itemCount == searchResult.PerPage) { continue; } ++itemCount; galleryIds.Add(galleryId); } int loadCount = 0; foreach (int galleryId in galleryIds) { Metadata metadata = GetGalleryMetadata(galleryId, runArg.PathFormatter, runArg.SearchResultCache); ++loadCount; LibraryLoadProgressArg progressArg = new LibraryLoadProgressArg(runArg, loadCount, galleryIds.Count, metadata); backgroundWorker.ReportProgress((int)((loadCount / (float)galleryIds.Count) * 100), progressArg); if (metadata == null) { continue; } searchResult.Result.Add(metadata); } searchResult.NumPages = (int)Math.Ceiling(totalItemCount / (double)searchResult.PerPage); } SearchResult finalSearchResult; if (searchResult.Result != null && runArg.SortType != GallerySortType.None) { SearchResult customSearchResult = new SearchResult(); customSearchResult.NumPages = searchResult.NumPages; customSearchResult.PerPage = searchResult.PerPage; // NOTE: don't hide items in the library. //IEnumerable<Metadata> customResult = searchResult.Result.GetFilteredSearchResult(runArg.MetadataKeywordLists); IEnumerable <Metadata> customResult = searchResult.Result.GetSortedSearchResult(runArg.SortType, runArg.SortOrder); customSearchResult.Result = customResult.ToList(); finalSearchResult = customSearchResult; } else { finalSearchResult = searchResult; } LibraryLoadCompletedArg completedArg = new LibraryLoadCompletedArg(runArg, finalSearchResult); e.Result = completedArg; }