internal void searchWith(ISearcher searcher, SearchCriteria searchCriteria) { XDocument resultsPageXDocument = null; IndefiniteProcessingForm.process( (cancellationRequestedChecker, log) => { log.WriteLine("Searching..."); resultsPageXDocument = new [] { searcher.search(searchCriteria.fileSystemInfos, cancellationRequestedChecker, log) }.toXDocument(); return(false); }, "Searching...", this ); if (null == resultsPageXDocument) { this.error("An error occured whilst searching."); return; } // note: resultsPage has to be constructed in this UI thread ResultsPage resultsPage = new ResultsPage(resultsPageXDocument); tabControl.appendControls(resultsPage); tabControl.SelectedTab = resultsPage; }
internal void downloadAllNotDownloadedWith(IDownloader downloader, String downloadsDirectoryPath) { IEnumerable <IDownloadableResourceFileCollection> available = null; IndefiniteProcessingForm.process( (cancellationRequestedChecker, log) => { log.WriteLine("Searching for new content..."); // TODO: consider re-writing enumerateResourceFileCollections to be lazily consumable, could perhaps avert the need for a cancellation checker? available = downloader.enumerateResourceFileCollections(cancellationRequestedChecker, log); return(false); }, "Searching...", this ); if (available.isNullOrEmpty()) { return; } IEnumerable <KeyValuePair <String, List <IDownloadableResourceFile> > > notDownloaded = available.map().enumerateNotDownloaded(downloadsDirectoryPath); if (!notDownloaded.Any()) { this.inform("All files checked are up-to-date.", "Downloads"); return; } IList <Tuple <IDownloadableResourceFile, String> > picks = DownloadPicker.pickDownloads(notDownloaded, this); if (picks.isNullOrEmpty()) { return; } long downloadedByteCount = 0; long totalByteCount = picks.Select(t => t.Item1.size).Sum(); BatchProcessingForm <Tuple <IDownloadableResourceFile, String> > .process( picks, (tuple, log) => { IDownloadableResourceFile downloadableResourceFile = tuple.Item1; String relativeFilePath = tuple.Item2; log.WriteLine("Downloading: \"{0}\"", downloadableResourceFile.name); FileInfo fileInfo = new FileInfo(Path.Combine(downloadsDirectoryPath, relativeFilePath)); fileInfo.Directory.Create(); if (!downloader.download(downloadableResourceFile, fileInfo.FullName)) { Console.Error.WriteLine("Downloading of uri: {0} failed", downloadableResourceFile); if (fileInfo.Exists) { Console.Error.WriteLine("Deleting partially downloaded file: {0}", fileInfo.FullName); fileInfo.Delete(); } return(-1); } downloadedByteCount += downloadableResourceFile.size; return((int)(Math.Ceiling((Double)(downloadedByteCount) / (Double)(totalByteCount) * 100d))); }, "Downloading...", "{0}% downloaded", this ); }