Пример #1
0
        /// <summary>
        ///     async method to send query to bing
        /// </summary>
        /// <param name="queryToSearch">pass query related info to bing</param>
        /// <returns></returns>
        private async Task QuerySearch(QueryToSearch queryToSearch)
        {
            await Task.Run(() =>
                {
                    //Fire event when search is about to start
                    FireQuerySearchStartingEventAsync(queryToSearch);

                    var searchedQuery = new SearchedQuery(queryToSearch.Query);
                    try
                    {
                        DataServiceQuery<ExpandableSearchResult> result = base.Composite("web", queryToSearch.Query,
                                                                                         null, null, null, null, null,
                                                                                         null, null, null, null, null,
                                                                                         null, null, null);
                        IEnumerable<ExpandableSearchResult> webResults = result.Execute();

                        foreach (ExpandableSearchResult r in webResults)
                        {
                            searchedQuery.Result.Add(new QueryResult {ID = r.ID, WebTotal = r.WebTotal});
                        }
                    }
                    catch (Exception ex)
                    {
                        searchedQuery.Exception = ex;
                        FireQuerySearchExceptionEventAsync(searchedQuery);
                    }

                    FireQuerySearchCompletedEventAsync(searchedQuery);
                });
        }
        public QuerySearchStartingArgs(QueryToSearch queryToSearch)
        {
            if (queryToSearch == null)
                throw new ArgumentNullException("queryToSearch");

            QueryToSearch = queryToSearch;
        }
Пример #3
0
 private void FireQuerySearchStartingEventAsync(QueryToSearch queryToSearch)
 {
     OnQuerySearchStartingAsync(new QuerySearchStartingArgs(queryToSearch));
 }