public async Task CreateWebDataListFromGoogleResultsAsync(CancellationToken cancellationToken) { foreach (GoogleSearchResult googleResult in GoogleSearchEngine.Instance.SearchResults) { bool isPageInList = PagesList.Any(page => googleResult.Url.Contains(page.Url)); cancellationToken.ThrowIfCancellationRequested(); if (!isPageInList) { IWebDataSource dataSource = WebDataSourceFactory.CreateWebDataSource(googleResult); if (dataSource != null) { IPage page = await m_PagesMemoryCache.GetOrCreate(googleResult.Url, async() => await dataSource.ParseDataAndGetPageAsync()); cancellationToken.ThrowIfCancellationRequested(); PagesList.Add(page); OnPageAdded(page); } } } m_TimeoutTimer.Stop(); }
//Load book ... pretty straightforward public void LoadBook(string FilePath, int p = 1) { Pages.Clear(); currentBook.CurrentPage = p; currentBook.Name = System.IO.Path.GetFileName(FilePath); currentBook.Type = Path.GetExtension(FilePath).ToLower(); currentBook.Path = FilePath; // use the apropriate function for compressed or pdf file if (currentBook.Type == ".pdf") { //Call the function to load the pdf (not the pages) //the function that load the page is called within the reader.cs //since on a pdf the page is loaded on demand for memory efficiency purpose Program.LoadPDF(FilePath); currentBook.TotalPages = Program.PDFBook.TotalPage; } else { ArchiveLoader(FilePath); } // Get The Reading direction from metadate and set it string ReadDirection = ReadMetadata(FilePath, "ReadDirection"); // MessageBox.Show(ReadMetadata(FilePath, "ReadDirection")); if (ReadDirection == "RtL") { SetDirection("RtL"); } else { SetDirection("LtR"); } // Get The View Mode from metadate and set it string v = ReadMetadata(FilePath, "Viewer"); // MessageBox.Show(ReadMetadata(FilePath, "ReadDirection")); if (v == "DPdc") { currentViewerOption = "dc"; } else { currentViewerOption = "sc"; } Viewer("Start"); GC.Collect(); ShowReader(); PagesList.Clear(); cPageMini2.ItemsSource = null; GenerateMiniPage(); cPageMini2.ItemsSource = PagesList; cPageMini2.UpdateLayout(); cPageMini2.SelectedIndex = 12; cPageMini2.ScrollToCenterOfView(cPageMini2.SelectedIndex); void GenerateMiniPage() { int i = 0; foreach (KeyValuePair <int, byte[]> entry in Pages) { // do something with entry.Value or entry.Key PagesList.Add(entry.Key, CreatePage(entry.Key, "Mini")); } } void ArchiveLoader(string Path) { int i = 0; var archive = ArchiveFactory.Open(Path); foreach (var entry in archive.Entries) { //Check if the entries in the File are : not a directoy AND contain in their name .jpg OR .png if (!entry.IsDirectory & (entry.Key.ToLower().Contains(".jpg") | entry.Key.ToLower().Contains(".png"))) { i++; //SortedOrder.FindIndex(s => s.Equals(entry.ToString())); using (MemoryStream MemStream = new MemoryStream()) { entry.WriteTo(MemStream); MemStream.Seek(0, SeekOrigin.Begin); byte[] bytes = MemStream.ToArray(); Pages.Add(i, bytes); bytes = null; } } } archive = null; currentBook.TotalPages = i; } }