/// <summary> /// Asynchronous method to execute the server response. /// </summary> /// <param name="result">Contains the DC_ServerResponse that the server sent.</param> private void getResponseResult(IAsyncResult result) { GetResponseDelegate del = result.AsyncState as GetResponseDelegate; ServerConnectorResponse server_response = del.EndInvoke(result); execServerResponse(server_response); }
public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state) { GetResponseDelegate d = new GetResponseDelegate(GetAsyncResponse); DelegateAsyncResult result = new DelegateAsyncResult(); AsyncContext userContext = new AsyncContext(d, result, callback, state); result.AsyncResult = d.BeginInvoke(new AsyncCallback(DelegateAsyncResult.Callback), userContext); return(result); }
/// <summary> /// Provides an asynchronous version of the GetResponse method. /// </summary> /// <param name="callback">The AsyncCallback delegate</param> /// <param name="state">An object containing state information for this asynchronous request</param> /// <returns>An IAsyncResult that references the asynchronous request</returns> public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state) { GetResponseDelegate getResponse = GetResponse; // The return call. Store in the hashtable. IAsyncResult asyncResult = getResponse.BeginInvoke(true, callback, state); this.delegateTable[asyncResult] = getResponse; // Begin the result. return(asyncResult); }
/// <summary> /// Asynchronously retrieve the response from the requested url to the specified response stream. /// </summary> public void GetResponseAsync(string url, Stream responseStream, string accept, HttpPostData postData, WebRequestAsyncState state) { m_asyncState = state; m_asyncState.Request = this; if (Dispatcher.IsMultiThreaded) { GetResponseDelegate caller = GetResponse; caller.BeginInvoke(url, responseStream, accept, postData, GetResponseAsyncCompleted, caller); } else { GetResponseAsyncCompletedCore(() => GetResponse(url, responseStream, accept, postData)); } }
public TResponse GetResponse <TResponse>(HttpWebRequest request, GetResponseDelegate <TResponse> getResponse) { if (Log.IsDebugEnabled) { Log.Debug(string.Format("Reading Response of {0} type, {1}, {2} method", typeof(TResponse), request.RequestUri, request.Method)); } try { // Invoke delegate to get the response. return(getResponse(request.GetResponse())); } catch (WebException e) { InvocationException exception; string errorDescription = GetResponse <string>(e.Response) ?? e.Status.ToString(); if (e.Response is HttpWebResponse) { exception = new HttpInvocationException(((HttpWebResponse)(e.Response)).StatusCode, errorDescription); } else { exception = new InvocationException(errorDescription, e); } if (Log.IsDebugEnabled) { Log.Debug(string.Format("WebException Response: {0}, {1} method. Error is '{2}'", request.RequestUri, request.Method, exception.Message)); } throw exception; } catch (Exception e) { if (Log.IsDebugEnabled) { Log.Debug(string.Format("Error reading Response: {0}, {1} method", request.RequestUri, request.Method), e); } throw new InvocationException("Service invocation exception", e); } }
/// <summary> /// Returns the NntpWebResponse /// </summary> /// <param name="asyncResult">An IAsyncResult that references a pending request for a response</param> /// <returns>the NNTP response</returns> public override WebResponse EndGetResponse(IAsyncResult asyncResult) { // Get the item from the hashtable. If it doesn't exist, then raise an // exception. GetResponseDelegate getResponse = (GetResponseDelegate)this.delegateTable[asyncResult]; if (getResponse == null) { throw new NntpWebException("GetRequestStreamDelegate for " + this.requestUri + "not found in delegates table of NntpWebRequest"); } // Remove the item from the hashtable. this.delegateTable.Remove(asyncResult); // Finish off the call. return(getResponse.EndInvoke(asyncResult)); }
/// <summary> /// Asynchronously execute a method on the server and have a callback executed on a completed query. /// </summary> /// <param name="method">Method name to execute on the server.</param> /// <param name="callback">Delegate to call when the server request has been sent and the response has been read.</param> /// <param name="arguments">Arguments to pass to the method on the server.</param> public void callServerMethod(string method, ServerConnectorMethodCallback callback, params object[] arguments) { // Determine if multiple arguments are being passed or just one array. if (arguments.GetType().Equals(typeof(object[])) == false) { arguments = new object[] { arguments }; } RequestQuery queue_query = new RequestQuery() { upload = false, method = method, callback = callback, arguments = arguments }; if (requestAlowed(queue_query) == false) { return; } Uri uri = buildUri(method); GetResponseDelegate get = new GetResponseDelegate(getResponse); if (callback == null) { get.BeginInvoke(uri, arguments, new AsyncCallback(getResponseResult), get); } else { get.BeginInvoke(uri, arguments, new AsyncCallback(delegate(IAsyncResult result) { GetResponseDelegate del = result.AsyncState as GetResponseDelegate; ServerConnectorResponse server_response = del.EndInvoke(result); callback(server_response); }), get); } }
/// <summary> /// Initializes a new instance of the MessageReader class using the /// specified delegate. /// </summary> /// <param name="Delegate">A delegate to the GetResponse method which /// the MessageReader object invokes when it needs to read a line of /// data from the server.</param> public MessageReader(GetResponseDelegate Delegate) { GetResponse = Delegate; }
/// <summary> /// Asynchronously execute a method on the server and have a callback executed on a completed query. /// </summary> /// <param name="method">Method name to execute on the server.</param> /// <param name="callback">Delegate to call when the server request has been sent and the response has been read.</param> /// <param name="arguments">Arguments to pass to the method on the server.</param> public void callServerMethod(string method, ServerConnectorMethodCallback callback, params object[] arguments) { // Determine if multiple arguments are being passed or just one array. if(arguments.GetType().Equals(typeof(object[])) == false) { arguments = new object[] { arguments }; } RequestQuery queue_query = new RequestQuery() { upload = false, method = method, callback = callback, arguments = arguments }; if(requestAlowed(queue_query) == false) return; Uri uri = buildUri(method); GetResponseDelegate get = new GetResponseDelegate(getResponse); if(callback == null) { get.BeginInvoke(uri, arguments, new AsyncCallback(getResponseResult), get); } else { get.BeginInvoke(uri, arguments, new AsyncCallback(delegate(IAsyncResult result) { GetResponseDelegate del = result.AsyncState as GetResponseDelegate; ServerConnectorResponse server_response = del.EndInvoke(result); callback(server_response); }), get); } }
public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state) { GetResponseDelegate d = new GetResponseDelegate (GetAsyncResponse); DelegateAsyncResult result = new DelegateAsyncResult (); AsyncContext userContext = new AsyncContext (d, result, callback, state); result.AsyncResult = d.BeginInvoke (new AsyncCallback (DelegateAsyncResult.Callback), userContext); return result; }
/// <summary> /// Callback method for asynchronous requests. /// </summary> private void GetResponseAsyncCompleted(IAsyncResult ar) { GetResponseDelegate caller = (GetResponseDelegate)ar.AsyncState; GetResponseAsyncCompletedCore(() => caller.EndInvoke(ar)); }