Ejemplo n.º 1
0
        //private BrowserDialog window;

        /// <summary>
        ///
        /// </summary>
        /// <param name="searchTerm"></param>
        /// <param name="searchEngineType"></param>
        /// <returns></returns>
        public async Task <List <SearchItem> > GetSearchLinks(string searchTerm,
                                                              SearchEngineTypes searchEngineType = SearchEngineTypes.DuckDuckGo)
        {
            var list = new List <SearchItem>();
            var url  = "https://{0}.com?q={1}";

            url = string.Format(url, searchEngineType, searchTerm);

            var window = new BrowserDialog();

            window.Width      = 0;
            window.Height     = 0;
            window.Top        = -50000; // offsreen but visible
            window.Visibility = Visibility.Visible;

            if (!window.NavigateAndWaitForCompletion(url))
            {
                return(null);
            }



            await window.Dispatcher.DelayAsync(1000, (p) =>
            {
                dynamic document = window.Browser.Document;
                var html         = document.Body.InnerHtml as string;
                window?.Close();

                if (string.IsNullOrEmpty((html)))
                {
                    return;
                }

                var doc = new HtmlDocument();
                doc.LoadHtml(html);
                var links = doc.DocumentNode.SelectNodes("//*/h2/a[1]");

                if (links == null)
                {
                    return;
                }

                foreach (var link in links)
                {
                    var searchItem = new SearchItem();
                    url            = link.Attributes["href"]?.Value;
                    if (url.Contains("?uddg="))
                    {
                        url = StringUtils.ExtractString(url, "?uddg=", "x",
                                                        allowMissingEndDelimiter: true);
                    }
                    searchItem.Url   = StringUtils.UrlDecode(url);
                    searchItem.Title = link.InnerText;
                    list.Add(searchItem);
                }
            }, DispatcherPriority.ApplicationIdle);


            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens a browser with the search term provided in the
        /// </summary>
        /// <param name="searchTerm"></param>
        /// <param name="searchEngineType">duckduckgo,google,bing (any other domain name that can be postfixed with .com)</param>
        public void OpenSearchEngine(string searchTerm, SearchEngineTypes searchEngineType = SearchEngineTypes.DuckDuckGo)
        {
            var url = "https://{0}.com?q={1}";

            url = string.Format(url, searchEngineType, searchTerm);

            ShellUtils.OpenUrl(url);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get the SearchEngine depending on the searchEngineName given
        /// </summary>
        /// <param name="searchEngineName"></param>
        /// <returns>SearchEngine type</returns>
        public static SearchEngine GetSearchEngine(string searchEngineName)
        {
            SearchEngineTypes searchEngineValue = (SearchEngineTypes)Enum.Parse(typeof(SearchEngineTypes), searchEngineName, true);

            switch (searchEngineValue)
            {
            case SearchEngineTypes.Google:
                return(new SearchEngineGoogle());

            case SearchEngineTypes.Bing:
                return(new SearchEngineBing());

            default:
                return(null);
            }
        }
 public SearchEngineManager(SearchEngineTypes type = SearchEngineTypes.Google)
 {
     CurrentEngine = engines[type];
 }
 public SearchEngineManager(SearchEngineTypes type = SearchEngineTypes.Google)
 {
     CurrentEngine = engines[type];
 }
Ejemplo n.º 6
0
 public SettingsManager(SearchEngineTypes type = SearchEngineTypes.Google, bool generalSearch = false, bool internalBrowser = false)
 {
     CurrentEngine = engines[type];
     GeneralSearch = generalSearch;
     InternalBrowser = internalBrowser;
 }