Example #1
0
        /// <summary>
        /// Get bing results.
        /// </summary>
        /// <param name="searchString"></param>
        /// <param name="moreResults"></param>
        /// <returns></returns>
        private int GetBingResults(string searchString, out bool moreResults)
        {
            var client = new SearchBingApi(BingApiKey);
            List <BingApiResult> results;

            try
            {
                results = client.Search(searchString);
            }
            catch
            {
                moreResults = false;
                return(0);
            }
            if (results.Count != 0)
            {
                OnSearcherLinkFoundEvent(new EventsThreads.ThreadListDataFoundEventArgs((List <object>)results.Cast <object>().ToList()));
            }
            moreResults = false;
            return(results.Count);
        }
Example #2
0
        private int GetBingAllLinks(string searchString, CancellationToken cancelToken)
        {
            int           totalResults = 0;
            bool          moreResults;
            SearchBingApi client     = new SearchBingApi(BingApiKey);
            int           pageNumber = 0;

            do
            {
                try
                {
                    List <Uri> results = client.Search(searchString, pageNumber, cancelToken, out moreResults);
                    totalResults += results.Count;

                    if (results.Count > 0)
                    {
                        OnSearcherLinkFoundEvent(new EventsThreads.CollectionFound <Uri>(results));
                    }
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch (InvalidOperationException)
                {
                    throw;
                }
                catch
                {
                    moreResults = false;
                }

                pageNumber++;
                cancelToken.ThrowIfCancellationRequested();
            } while (moreResults && totalResults < MaxResults);

            return(totalResults);
        }
Example #3
0
        /// <summary>
        /// Get bing results.
        /// </summary>
        /// <param name="searchString"></param>
        /// <param name="moreResults"></param>
        /// <returns></returns>
        private int GetBingResults(string searchString, out bool moreResults)
        {
            var        client = new SearchBingApi(BingApiKey);
            List <Uri> results;

            try
            {
                results = client.Search(searchString);
                if (results.Count > 0)
                {
                    OnSearcherLinkFoundEvent(new EventsThreads.CollectionFound <Uri>(results));
                }

                return(results.Count);
            }
            catch
            {
                return(0);
            }
            finally
            {
                moreResults = false;
            }
        }