public SearchResult GetResults(GetResultsRequest req) { object[] results = this.Invoke("GetResults", new object[] { req }); return((SearchResult)(results[0])); }
public static void DoQueryResponseHandler(IAsyncResult ar) { ReqContext rc = (ReqContext)ar.AsyncState; IQueryable iq = rc.GetQueryable; BeagleWebService wsp = rc.GetProxy; IQueryResult result = rc.GetResult; int count = 0; //bool hitRejectsLogged = false; try { SearchResult resp = wsp.EndBeagleQuery(ar); if ((resp != null) && (resp.numResults > 0)) { if (rc.SearchToken == null) { rc.SearchToken = resp.searchToken; } //NetContext nc = new NetContext(wsp, resp.searchToken); HitResult[] hres = resp.hitResults; ArrayList nwhits = new ArrayList(); for (int i = 0; i < hres.Length; i++) { try { HitResult hr = hres[i]; Hit hit = new NetworkHit(); //[Uri Format] netbeagle://164.99.153.134:8888/searchToken?http:///.... if (hr.uri.StartsWith(NetworkedBeagle.BeagleNetPrefix)) { hit.UriAsString = hr.uri; } else { string[] fragments = hr.uri.Split('/'); string hostNamePort = fragments[2]; hit.UriAsString = NetworkedBeagle.BeagleNetPrefix + hostNamePort + "/" + resp.searchToken + "?" + hr.uri; } hit.Type = hr.resourceType; hit.MimeType = hr.mimeType; hit.Source = "Network"; //hit.Source = hr.source; hit.Score = hr.score; if (hr.properties.Length > 0) { foreach (HitProperty hp in hr.properties) { Property p = Property.New(hp.PKey, hp.PVal); p.IsMutable = hp.IsMutable; p.IsSearched = hp.IsSearched; hit.AddProperty(p); } } //Add Snippet ((NetworkHit)hit).snippet = hr.snippet; //if (hr.snippet != null) //log.Debug("\nNBH: URI" + i + "=" + hr.uri + "\n Snippet=" + hr.snippet); ((NetworkHit)hit).context = new NetContext(hr.hashCode); //Add NetBeagleQueryable instance hit.SourceObject = iq; hit.SourceObjectName = ((NetworkedBeagle)iq).Name; nwhits.Add(hit); count++; } catch (Exception ex2) { log.Warn("Exception in NetBeagleHandler: DoQueryResponseHandler() while processing NetworkHit: {0} from {1}\n Reason: {2} ", hres[i].uri, wsp.Hostname + ":" + wsp.Port, ex2.Message); //log.Error ("Exception StackTrace: " + ex.StackTrace); } } //end for if (nwhits.Count > 0) { result.Add(nwhits); } /* * if ((! result.Add (nwhits)) && (! hitRejectsLogged)) * { * hitRejectsLogged = true; * log.Info("NetBeagleHandler: Network Hits rejected by HitRegulator. Too many Hits!"); * } */ log.Info("NetBeagleHandler: DoQueryResponseHandler() Got {0} result(s) from Index {1} from Networked Beagle at {2}", count, resp.firstResultIndex, wsp.Hostname + ":" + wsp.Port); int index = resp.firstResultIndex + resp.numResults; if (index < resp.totalResults) { log.Debug("NetBeagleHandler: DoQueryResponseHandler() invoking GetResults with index: " + index); string searchToken = resp.searchToken; GetResultsRequest req = new GetResultsRequest(); req.startIndex = index; req.searchToken = searchToken; IAsyncResult ar2; ar2 = wsp.BeginGetResults(req, NetBeagleHandler.DoQueryResponseHandler, rc); return; } } //end if else { if (resp == null) { log.Warn("NetBeagleHandler: DoQueryResponseHandler() got Null response from EndBeagleQuery() !"); } } } catch (Exception ex) { log.Error("Exception in NetBeagleHandler: DoQueryResponseHandler() - {0} - for {1} ", ex.Message, wsp.Hostname + ":" + wsp.Port); } //Signal completion of request handling rc.RequestProcessed = true; }
public System.IAsyncResult BeginGetResults(GetResultsRequest req, System.AsyncCallback callback, object asyncState) { return(this.BeginInvoke("GetResults", new object[] { req }, callback, asyncState)); }
public static void DoQueryResponseHandler(IAsyncResult ar) { ReqContext rc = (ReqContext)ar.AsyncState; IQueryable iq = rc.GetQueryable; BeagleWebService wsp = rc.GetProxy; IQueryResult result = rc.GetResult; int count = 0; //bool hitRejectsLogged = false; try { SearchResult resp = wsp.EndBeagleQuery(ar); if ((resp != null) && (resp.numResults > 0)) { if (rc.SearchToken == null) rc.SearchToken = resp.searchToken; //NetContext nc = new NetContext(wsp, resp.searchToken); HitResult[] hres = resp.hitResults; ArrayList nwhits = new ArrayList(); for (int i = 0; i < hres.Length; i++) { try { HitResult hr = hres[i]; Hit hit = new NetworkHit(); //[Uri Format] netbeagle://164.99.153.134:8888/searchToken?http:///.... if (hr.uri.StartsWith(NetworkedBeagle.BeagleNetPrefix)) hit.UriAsString = hr.uri; else { string[] fragments = hr.uri.Split ('/'); string hostNamePort = fragments[2]; hit.UriAsString = NetworkedBeagle.BeagleNetPrefix + hostNamePort + "/" + resp.searchToken + "?" + hr.uri; } hit.Type = hr.resourceType; hit.MimeType = hr.mimeType; hit.Source = "Network"; //hit.Source = hr.source; hit.Score = hr.score; if (hr.properties.Length > 0) foreach (HitProperty hp in hr.properties) { Property p = Property.New(hp.PKey, hp.PVal); p.IsMutable = hp.IsMutable; p.IsSearched = hp.IsSearched; hit.AddProperty(p); } //Add Snippet ((NetworkHit)hit).snippet = hr.snippet; //if (hr.snippet != null) //log.Debug("\nNBH: URI" + i + "=" + hr.uri + "\n Snippet=" + hr.snippet); ((NetworkHit)hit).context = new NetContext(hr.hashCode); //Add NetBeagleQueryable instance hit.SourceObject = iq; hit.SourceObjectName = ((NetworkedBeagle)iq).Name; nwhits.Add(hit); count++; } catch (Exception ex2) { log.Warn ("Exception in NetBeagleHandler: DoQueryResponseHandler() while processing NetworkHit: {0} from {1}\n Reason: {2} ", hres[i].uri, wsp.Hostname + ":" + wsp.Port, ex2.Message); //log.Error ("Exception StackTrace: " + ex.StackTrace); } } //end for if (nwhits.Count > 0) result.Add (nwhits); /* if ((! result.Add (nwhits)) && (! hitRejectsLogged)) { hitRejectsLogged = true; log.Info("NetBeagleHandler: Network Hits rejected by HitRegulator. Too many Hits!"); } */ log.Info("NetBeagleHandler: DoQueryResponseHandler() Got {0} result(s) from Index {1} from Networked Beagle at {2}", count, resp.firstResultIndex, wsp.Hostname + ":" + wsp.Port); int index = resp.firstResultIndex + resp.numResults; if (index < resp.totalResults) { log.Debug("NetBeagleHandler: DoQueryResponseHandler() invoking GetResults with index: " + index); string searchToken = resp.searchToken; GetResultsRequest req = new GetResultsRequest(); req.startIndex = index; req.searchToken = searchToken; IAsyncResult ar2; ar2 = wsp.BeginGetResults(req, NetBeagleHandler.DoQueryResponseHandler, rc); return; } } //end if else { if (resp == null) log.Warn("NetBeagleHandler: DoQueryResponseHandler() got Null response from EndBeagleQuery() !"); } } catch (Exception ex) { log.Error ("Exception in NetBeagleHandler: DoQueryResponseHandler() - {0} - for {1} ", ex.Message, wsp.Hostname + ":" + wsp.Port); } //Signal completion of request handling rc.RequestProcessed = true; }
public System.IAsyncResult BeginGetResults(GetResultsRequest req, System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("GetResults", new object[] { req}, callback, asyncState); }
public SearchResult GetResults(GetResultsRequest req) { object[] results = this.Invoke("GetResults", new object[] { req}); return ((SearchResult)(results[0])); }
public SearchResult getResults(GetResultsRequest req, bool isLocalReq) { int startIndex = req.startIndex; string searchToken = req.searchToken; SearchResult sr = new SearchResult(); sr.numResults = 0; if (!sessionTable.ContainsKey(searchToken)) { sr.statusCode = SC_INVALID_SEARCH_TOKEN; sr.statusMsg = "Error: Invalid Search Token"; Logger.Log.Warn("GetResults: Invalid Search Token received "); return sr; } ArrayList results = ((SessionData)sessionTable[searchToken]).results; if (results == null) { sr.statusCode = SC_INVALID_SEARCH_TOKEN; sr.statusMsg = "Error: Invalid Search Token"; Logger.Log.Warn("GetResults: Invalid Search Token received "); return sr; } lock (results.SyncRoot) { //Lock results ArrayList to prevent more Hits getting added till we've processed doQuery int i = 0; if (startIndex < results.Count) sr.numResults = (results.Count < startIndex + MAX_RESULTS_PER_CALL) ? (results.Count - startIndex): MAX_RESULTS_PER_CALL; sr.hitResults = new HitResult[sr.numResults]; string hitUri; for (int k = startIndex; (i < sr.numResults) && (k < results.Count); k++) { Hit h = (Hit) results[k]; sr.hitResults[i] = new HitResult(); // GetResults will NOT return Snippets by default. Client must make explicit GetSnippets request to get snippets for these hits. // Not initializing sr.hitResults[i].snippet implies there is no <snippets> element in HitResult XML response. hitUri = h.UriAsString; if (isLocalReq || hitUri.StartsWith(NetworkedBeagle.BeagleNetPrefix)) sr.hitResults[i].uri = hitUri; else sr.hitResults[i].uri = AccessFilter.TranslateHit(h); sr.hitResults[i].resourceType = h.Type; sr.hitResults[i].mimeType = h.MimeType; sr.hitResults[i].source = h.Source; sr.hitResults[i].score = h.Score; int plen = h.Properties.Count; sr.hitResults[i].properties = new HitProperty[plen]; for (int j = 0; j < plen; j++) { Property p = (Property) h.Properties[j]; sr.hitResults[i].properties[j] = new HitProperty(); sr.hitResults[i].properties[j].PKey = p.Key; sr.hitResults[i].properties[j].PVal = p.Value; sr.hitResults[i].properties[j].IsMutable = p.IsMutable; sr.hitResults[i].properties[j].IsSearched = p.IsSearched; } sr.hitResults[i].hashCode = h.GetHashCode (); i++; } } //end lock sr.totalResults = results.Count; sr.firstResultIndex = startIndex; sr.searchToken = ""; if (sr.totalResults > 0) sr.searchToken = searchToken; sr.statusCode = SC_QUERY_SUCCESS; sr.statusMsg = "Success"; //Console.WriteLine("WebServiceQuery: Total Results = " + sr.totalResults); return sr; }