/// <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> /// 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); } }