/// <summary> /// Starts an asynchronous operation to get include info. /// </summary> /// <param name="domainName"></param> /// <param name="callback"></param> /// <param name="userState"></param> /// <returns></returns> public static IAsyncResult BeginGetIncludeInfo(string domainName, AsyncCallback callback, object userState) { HttpWebRequest request = CreateNormalRequest(GetIncludeInfoQueryUri(domainName)); AsyncResult <ISougouIncludeInfo> result = new AsyncResult <ISougouIncludeInfo>(callback, userState); NetworkRequestAsyncTimeout.RegisterRequest(request.BeginGetResponse((ar) => { ISougouIncludeInfo info = null; Exception error = null; byte[] buffer = g_bufferManager.TakeBuffer(BUFFER_SIZE); try { string content = null; using (HttpWebResponse response = (HttpWebResponse)((HttpWebRequest)ar.AsyncState).EndGetResponse(ar)) { content = response.GetResponseString(buffer); } info = ParseIncludeInfo(content); } catch (Exception ex) { error = ex; } finally { g_bufferManager.ReturnBuffer(buffer); } result.MarkCompleted(error, false, info); }, request), request, TIMEOUT); return(result); }
public void GetIncludeInfoTest() { ISougouIncludeInfo info1 = SougouUtility.GetIncludeInfo("www.beianm.com"); ISougouIncludeInfo info2 = SougouUtility.GetIncludeInfo("www.xphter.com"); ISougouIncludeInfo info3 = SougouUtility.GetIncludeInfo("news.qq.com"); Assert.IsTrue(info1.IndexCount > 0); Assert.IsTrue(info1.IncludeCount > 0); Assert.IsTrue(info2.IndexCount > 0); Assert.IsTrue(info2.IncludeCount > 0); Assert.IsTrue(info3.IndexCount > 0); Assert.IsTrue(info3.IncludeCount > 0); }
public void BeginGetIncludeInfoTest() { ISougouIncludeInfo info1 = null, info2 = null, info3 = null; using (CountdownEvent ce = new CountdownEvent(3)) { SougouUtility.BeginGetIncludeInfo("www.beianm.com", (ar) => { try { info1 = SougouUtility.EndGetIncludeInfo(ar); } finally { ce.Signal(); } }, null); SougouUtility.BeginGetIncludeInfo("www.xphter.com", (ar) => { try { info2 = SougouUtility.EndGetIncludeInfo(ar); } finally { ce.Signal(); } }, null); SougouUtility.BeginGetIncludeInfo("news.qq.com", (ar) => { try { info3 = SougouUtility.EndGetIncludeInfo(ar); } finally { ce.Signal(); } }, null); ce.Wait(); } Assert.IsTrue(info1.IndexCount > 0); Assert.IsTrue(info1.IncludeCount > 0); Assert.IsTrue(info2.IndexCount > 0); Assert.IsTrue(info2.IncludeCount > 0); Assert.IsTrue(info3.IndexCount > 0); Assert.IsTrue(info3.IncludeCount > 0); }