Ejemplo n.º 1
0
        public IAsyncResult BeginSearch(SearchOption option, AsyncCallback callBack, object UserState)
        {
            Uri uriRequest = this.RequestURL(option);
            byte[] uriBody = this.RequestBody(option);

            ApiResult asyncApi = new ApiResult();

            asyncApi.apiObject = new ApiObject();
            asyncApi.apiObject.callback = callBack;
            asyncApi.apiObject.option = option;
            asyncApi.apiObject.userState = UserState;

            asyncApi.apiObject.hwReq = WebRequest.Create(this.RequestURL(option)) as HttpWebRequest;
            asyncApi.apiObject.hwReq.Method = (uriBody != null) ? "POST" : "GET";
            if (uriBody != null)
            {
                asyncApi.apiObject.hwReq.ContentType = "application/x-www-form-urlencoded";
                asyncApi.apiObject.hwReq.GetRequestStream().Write(uriBody, 0, uriBody.Length);
            }

            asyncApi.apiObject.asyncHttp = asyncApi.apiObject.hwReq.BeginGetResponse(RequestCallback, asyncApi.apiObject);

            asyncApi.manualEvent = new ManualResetEvent(false);

            asyncApi.AsyncState = UserState;
            asyncApi.IsCompleted = false;
            asyncApi.CompletedSynchronously = false;

            asyncApi.apiObject.asyncApi = asyncApi;

            return asyncApi;
        }
Ejemplo n.º 2
0
 public IAsyncResult BeginSearch(SearchOption option, AsyncCallback callBack)
 {
     return this.BeginSearch(option, callBack, null);
 }
Ejemplo n.º 3
0
 internal abstract Uri RequestURL(SearchOption option);
Ejemplo n.º 4
0
 internal abstract byte[] RequestBody(SearchOption option);
Ejemplo n.º 5
0
 internal abstract IList<ImageInfo> ParseData(string body, SearchOption option);
Ejemplo n.º 6
0
        public IList<ImageInfo> Search(SearchOption option)
        {
            Uri uriRequest = this.RequestURL(option);
            byte[] uriBody = this.RequestBody(option);

            HttpWebRequest wReq = WebRequest.Create(this.RequestURL(option)) as HttpWebRequest;
            wReq.Method = (uriBody != null) ? "POST" : "GET";
            if (uriBody != null)
            {
                wReq.ContentType = "application/x-www-form-urlencoded";
                wReq.GetRequestStream().Write(uriBody, 0, uriBody.Length);
            }

            HttpWebResponse	wRes = wReq.GetResponse() as HttpWebResponse;

            string body = Helper.StringFromStream(wRes.GetResponseStream());

            wRes.Close();

            return this.ParseData(body, option);
        }