コード例 #1
0
        public SearchResponse Search(SearchRequest request)
        {
            SearchResponse cacheRespoinse = GetFromCache(request.Query);
            if (cacheRespoinse != null)
            {
                return cacheRespoinse;
            }

            request.AppId = appID;
            using (ManualResetEvent signal = new ManualResetEvent(false))
            {
                MsnSyncContext context = new MsnSyncContext(signal);
                AsyncSearch(request, MsnSyncCallback, context);
                signal.WaitOne();
                if (context.error != null)
                {
                    throw context.error;
                }
                return context.data;
            }
        }
コード例 #2
0
        SearchRequest CreateSimpleRequest(string query)
        {
            SearchRequest searchRequest = new SearchRequest();
            searchRequest.AppId = appID;
            searchRequest.Version = "2.0";
            searchRequest.Market = cultureInfo;
            searchRequest.Query = XmlHelper.XmlEncoding(query);
            searchRequest.Sources = new SourceType[] { SourceType.Web };
            searchRequest.Web = new WebRequest();
            searchRequest.Web.Count = (uint)snippetCount;
            searchRequest.Web.CountSpecified = true;
            searchRequest.Web.Offset = 0;
            searchRequest.Web.OffsetSpecified = true;
            searchRequest.Web.Options = new WebSearchOption[]
                {
                    WebSearchOption.DisableHostCollapsing,
                    WebSearchOption.DisableQueryAlterations
                };            

            return searchRequest;
        }
コード例 #3
0
 /// <remarks/>
 public void SearchAsync(SearchRequest Request, object userState)
 {
     if ((this.SearchOperationCompleted == null))
     {
         this.SearchOperationCompleted = new System.Threading.SendOrPostCallback(this.OnSearchOperationCompleted);
     }
     this.InvokeAsync("Search", new object[] {
             Request}, this.SearchOperationCompleted, userState);
 }
コード例 #4
0
        public void AsyncSearch(SearchRequest request, WaitCallback callback, object userState)
        {
            SearchResponse cacheRespoinse = GetFromCache(request.Query);
            if (cacheRespoinse != null)
            {
                SnippetGatherState sgs = new SnippetGatherState();
                sgs.result = cacheRespoinse;
                sgs.userState = userState;

                ThreadPool.QueueUserWorkItem(callback, sgs);

                return;
            }

            request.AppId = appID;

            SnippetGatherState state = new SnippetGatherState();
            state.request = request;
            state.userState = userState;
            state.userCallback = callback;
            state.internalCallback = SnippetGatherCallback;

            jobQueue.EnqueueJob(state);
        }
コード例 #5
0
 /// <remarks/>
 public void SearchAsync(SearchRequest Request)
 {
     this.SearchAsync(Request, null);
 }
コード例 #6
0
 /// <remarks/>
 public System.IAsyncResult BeginSearch(SearchRequest Request, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("Search", new object[] {
             Request}, callback, asyncState);
 }
コード例 #7
0
 public SearchResponse Search(SearchRequest Request)
 {
     object[] results = this.Invoke("Search", new object[] {
             Request});
     return ((SearchResponse)(results[0]));
 }
コード例 #8
0
 /// <remarks/>
 public void SearchAsync(SearchRequest parameters)
 {
     this.SearchAsync(parameters, null);
 }
コード例 #9
0
 public SearchResponse Search(SearchRequest parameters)
 {
     object[] results = this.Invoke("Search", new object[] {
             parameters});
     return ((SearchResponse)(results[0]));
 }