public async Task <AlfredResponse> SearchAsync(IAlfredInput i_Input) { m_TimeoutTimer.Enabled = true; PagesList.Clear(); GoogleSearchEngine.Instance.ClearResults(); m_CancellationTokenSource?.Dispose(); m_CancellationTokenSource = new CancellationTokenSource(); try { if (i_Input.ProjectType != null) { await GoogleSearchEngine.Instance.AddSearchResultsFromQueryAsync(String.Format("site: {0} {1} {2}", r_WebSitesUrls[eWebSite.Stackoverflow], i_Input.Description, i_Input.ProjectType)); } await GoogleSearchEngine.Instance.AddSearchResultsFromQueryAsync(String.Format("site: {0} {1}", r_WebSitesUrls[eWebSite.Stackoverflow], i_Input.Description)); await GoogleSearchEngine.Instance.AddSearchResultsFromQueryAsync(String.Format("site: {0} \"{1}\"", r_WebSitesUrls[eWebSite.Microsoft], i_Input.ErrorCode)); await Task.Run(() => CreateWebDataListFromGoogleResultsAsync(m_CancellationTokenSource.Token), m_CancellationTokenSource.Token); } catch (WebException) { StopSearch(); throw new WebException("No internet connection"); } catch (OperationCanceledException) { StopSearch(); throw new OperationCanceledException("Operation canceled - timeout expired"); } catch (Exception) { StopSearch(); throw new WebException("Uunexpected error"); } return(Response); }
//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; } }