internal override void DoAbortCurrentRequest()
		{
			if (webRequest != null)
			{
				webRequest.Executor.Abort();
				webRequest = null;
			}
		}
		public void CancelRequests()
		{
			if (webRequest != null)
			{
				webRequest.Executor.Abort();
				webRequest = null;
			}
		}
		public void RequestSuggestions(string textSoFar)
		{
			Dictionary parameters = new Dictionary();
			parameters["text"] = textSoFar;
			parameters["maxNumberOfItemsToGet"] = maxNumberOfItemsToGet;
			CancelRequests();
			webRequest = WebServiceProxy.Invoke(webServiceUrl, webServiceCommand, true, parameters, this.SuccessCallback, this.FailureCallback, textSoFar, -1);
		}
Example #4
0
		public void CallWebService(Dictionary parameters, WebServiceSuccessCallback successCallback, WebServiceFailureCallback failureCallback, object userContext)
		{
			this.successCallback = successCallback;
			this.failureCallback = failureCallback;

			if (this.webRequest != null)
			{
				Trace.Write("ABORT");
				this.webRequest.Executor.Abort();
			}

			this.webRequest = WebServiceProxy.Invoke(servicePath, serviceMethod, false, parameters, successCallback2, failureCallback2, userContext, timeOut);
		}
		protected override void MakeRequest(string text, Dictionary requestParameters, int maxNumberOfItemsToGet)
		{
			Dictionary parameters = new Dictionary();
			parameters["text"] = text;
			parameters["maxNumberOfItemsToGet"] = maxNumberOfItemsToGet;
			parameters["parameters"] = requestParameters;
			if (webRequest != null && webRequest.Executor.Started) webRequest.Executor.Abort();
			webRequest = WebServiceProxy.Invoke(
				url,
				this.MethodName,
				true,
				parameters, 
				this.SuccessCallback,
				Trace.WebServiceFailure, text, -1
			);
		}
Example #6
0
 public AjaxContext(WebRequest request, DOMElement updateTarget, DOMElement loadingElement, InsertionMode insertionMode) {
     _request = request;
     _updateTarget = updateTarget;
     _loadingElement = loadingElement;
     _insertionMode = insertionMode;
 }
Example #7
0
		private void failureCallback2(WebServiceError error, object userContext, string methodName)
		{
			this.webRequest = null;
			this.failureCallback(error, userContext, methodName);
		}
Example #8
0
		private void successCallback2(object result, object userContext, string methodName)
		{
			this.webRequest = null;
			this.successCallback(result, userContext, methodName);
		}
        internal static void AsyncRequest(string url, string verb, string body, DOMElement triggerElement, AjaxOptions ajaxOptions) {
            // Run the confirm popup, if specified
            if (ajaxOptions.Confirm != null) {
                if (!Script.Confirm(ajaxOptions.Confirm)) {
                    return;
                }
            }

            // Override the url if specified in AjaxOptions
            if (ajaxOptions.Url != null) {
                url = ajaxOptions.Url;
            }

            // Override the verb if specified in AjaxOptions
            if (ajaxOptions.HttpMethod != null) {
                verb = ajaxOptions.HttpMethod;
            }

            // Add the hidden field to the body
            if (body.Length > 0 && !body.EndsWith('&')) {
                body += "&";
            }
            body += "X-Requested-With=XMLHttpRequest";

            // Determine where to place the body
            string requestBody = "";
            if (verb.ToUpperCase() == "GET" || verb.ToUpperCase() == "DELETE") {
                if (url.IndexOf('?') > -1) {
                    // Case 1: http://foo.bar/baz?abc=123
                    if (!url.EndsWith('&')) {
                        url += "&";
                    }
                    url += body;
                }
                else {
                    // Case 2: http://foo.bar/baz
                    url += "?";
                    url += body;
                }
            }
            else {
                requestBody = body;
            }

            // Create the request
            WebRequest request = new WebRequest();

            request.Url = url;
            request.HttpVerb = verb;
            request.Body = requestBody;
            if (verb.ToUpperCase() == "PUT") {
                request.Headers["Content-Type"] = "application/x-www-form-urlencoded;";
            }
            request.Headers["X-Requested-With"] = "XMLHttpRequest";

            DOMElement updateElement = null;
            if (ajaxOptions.UpdateTargetId != null) {
                updateElement = Document.GetElementById(ajaxOptions.UpdateTargetId);
            }

            DOMElement loadingElement = null;
            if (ajaxOptions.LoadingElementId != null) {
                loadingElement = Document.GetElementById(ajaxOptions.LoadingElementId);
            }

            // Create the AjaxContext for the request
            AjaxContext ajaxContext = new AjaxContext(request, updateElement, loadingElement, ajaxOptions.InsertionMode);

            // Run onBegin and check for cancellation
            bool continueRequest = true;
            if (ajaxOptions.OnBegin != null) {
                // Have to convert to objects to force the "!== false" to be emitted.
                // We want no return value to be treated as returning true, so we only want to cancel the request if the result is exactly "false"
                continueRequest = (object)ajaxOptions.OnBegin(ajaxContext) != (object)false;
            }

            // Display the loading element, if specified
            if (loadingElement != null) {
                Type.InvokeMethod(typeof(Sys.UI.DomElement), "setVisible", ajaxContext.LoadingElement, true);
            }

            if (continueRequest) {
                // Setup the callback
                request.Completed += delegate(WebRequestExecutor executor) {
                    MvcHelpers.OnComplete(request, ajaxOptions, ajaxContext);
                };

                request.Invoke();
            }
        }
        internal static void OnComplete(WebRequest request, AjaxOptions ajaxOptions, AjaxContext ajaxContext) {
            // Update the AjaxContext
            ajaxContext.Response = request.Executor;

            // Run onComplete and check for cancellation
            // Have to convert to objects to force the "=== false" to be emitted.
            // We want no return value to be treated as returning true, so we only want to cancel the request if the result is exactly "false"
            if (ajaxOptions.OnComplete != null && (object)ajaxOptions.OnComplete(ajaxContext) == (object)false) {
                return;
            }

            // If the status code was successful...
            int statusCode = ajaxContext.Response.StatusCode;
            if ((statusCode >= 200 && statusCode < 300) || statusCode == 304 || statusCode == 1223) {
                // If the status code is one of 204 (No Content), 304 (Not Modified), or 1223 (IE-specific code caused by 204), don't do the injection
                if (statusCode != 204 && statusCode != 304 && statusCode != 1223) {
                    string contentType = ajaxContext.Response.GetResponseHeader("Content-Type");
                    if ((contentType != null) && (contentType.IndexOf("application/x-javascript") != -1)) {
                        Script.Eval(ajaxContext.Data);
                    }
                    else {
                        UpdateDomElement(ajaxContext.UpdateTarget, ajaxContext.InsertionMode, ajaxContext.Data);
                    }
                }

                if (ajaxOptions.OnSuccess != null) {
                    ajaxOptions.OnSuccess(ajaxContext);
                }
            }
            else {
                if (ajaxOptions.OnFailure != null) {
                    ajaxOptions.OnFailure(ajaxContext);
                }
            }

            // Hide the loading panel, if there is one
            if (ajaxContext.LoadingElement != null) {
                Type.InvokeMethod(typeof(Sys.UI.DomElement), "setVisible", ajaxContext.LoadingElement, false);
            }
        }
 /// <summary>
 /// Sends Web requests to the default network executor.
 /// </summary>
 /// <param name="request">An instance of the <see cref="Sys.Net.WebRequest"/> class.</param>
 /// <remarks>
 /// The executeRequest method sends Web requests to the default executor. To execute a Web request, you must call the invoke method.
 /// </remarks>
 public static void ExecuteRequest(WebRequest request)
 {
 }