Пример #1
0
        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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
 /// <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));
     }
 }
Пример #4
0
        /// <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);
            }
        }
Пример #5
0
        /// <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);
            }
        }
Пример #6
0
		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;
		}