public Task<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { Request = request; var tcs = new TaskCompletionSource<IServiceFilterResponse>(); tcs.SetResult (Response); return tcs.Task; }
public IAsyncOperation <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { TaskCompletionSource <IServiceFilterResponse> tcs = new TaskCompletionSource <IServiceFilterResponse>(); tcs.SetResult(new MyResponse(this.statusCode, this.statusDescription, this.contentType, this.content)); return(tcs.Task.AsAsyncOperation()); }
public async Task <IServiceFilterResponse> HandleRequest(IServiceFilterRequest request, IServiceFilterContinuation continuation) { IServiceFilterResponse response = null; try { for (int i = 0; i < this.NumberOfRequests; i++) { response = await continuation.Handle(request); test.AddLog("Sent the request number {0}", i + 1); test.AddLog("Response: {0} - {1}", response.StatusCode, response.StatusDescription); if (response.StatusCode >= 400) { test.AddLog("Invalid response. Content-Type: {0}", response.ContentType); test.AddLog("Response content: {0}", response.Content); throw new InvalidOperationException(); } } } catch (Exception ex) { test.AddLog("Exception while calling continuation: {0}", ex); this.TestFailed = true; throw; } return(response); }
private Task<IServiceFilterResponse> Log(IServiceFilterRequest request, IServiceFilterContinuation next) { //Test.Log(" >>> {0} {1} {2}", request.Method, request.Uri, request.Content); //IServiceFilterResponse response = await next.Handle(request).AsTask(); //Test.Log(" <<< {0} {1} {2}", response.StatusCode, response.StatusDescription, response.Content); return next.Handle (request);; }
public void HandleRequest(IServiceFilterRequest request, INextServiceFilterCallback nextServiceFilterCallback, IServiceFilterResponseCallback responseCallback) { mToDoActivity.RunOnUiThread(new MyRunnable(mToDoActivity.mProgressBar, ProgressBar.VISIBLE)); nextServiceFilterCallback.OnNext(request, new MyServiceFilterResponseCallback(mToDoActivity, responseCallback)); }
private static Exception CreateMobileServiceException(string errorMessage, IServiceFilterRequest request, IServiceFilterResponse response) { Debug.Assert(!string.IsNullOrEmpty(errorMessage), "errorMessage cannot be null or empty!"); Debug.Assert(request != null, "request cannot be null!"); Debug.Assert(response != null, "response cannot be null!"); return(new InvalidOperationException(errorMessage)); }
private static Exception CreateMobileServiceException(string errorMessage, IServiceFilterRequest request, IServiceFilterResponse response) { Debug.Assert(!string.IsNullOrEmpty(errorMessage), "errorMessage cannot be null or empty!"); Debug.Assert(request != null, "request cannot be null!"); Debug.Assert(response != null, "response cannot be null!"); return new InvalidOperationException(errorMessage); }
private Task <IServiceFilterResponse> Log(IServiceFilterRequest request, IServiceFilterContinuation next) { //Test.Log(" >>> {0} {1} {2}", request.Method, request.Uri, request.Content); //IServiceFilterResponse response = await next.Handle(request).AsTask(); //Test.Log(" <<< {0} {1} {2}", response.StatusCode, response.StatusDescription, response.Content); return(next.Handle(request));; }
public Task<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { Request = request; //return Task.FromResult<IServiceFilterResponse>(Response).AsAsyncOperation(); var tcs = new TaskCompletionSource<IServiceFilterResponse>(); tcs.SetResult(Response); return tcs.Task; }
/// <summary> /// Provide an implementation of the default next continuation which /// just returns the response corresponding to a request. /// </summary> /// <param name="request">The HTTP request.</param> /// <returns>The HTTP response.</returns> Task<IServiceFilterResponse> IServiceFilterContinuation.Handle(IServiceFilterRequest request) { if (request == null) { throw new ArgumentNullException("request"); } return request.GetResponse(); }
/// <summary> /// Provide an implementation of the default next continuation which /// just returns the response corresponding to a request. /// </summary> /// <param name="request">The HTTP request.</param> /// <returns>The HTTP response.</returns> Task <IServiceFilterResponse> IServiceFilterContinuation.Handle(IServiceFilterRequest request) { if (request == null) { throw new ArgumentNullException("request"); } return(request.GetResponse()); }
public Task <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { Request = request; var tcs = new TaskCompletionSource <IServiceFilterResponse>(); tcs.SetResult(Response); return(tcs.Task); }
/// <summary> /// Apply a chain of IServiceFilters to an HTTP request and get the /// corresponding HTTP response. /// </summary> /// <param name="request">The HTTP request.</param> /// <param name="filter"> /// The filter (or chain of filters composed together into a single /// filter) to apply to the request to obtain the response. /// </param> /// <returns>The HTTP response.</returns> public static Task<IServiceFilterResponse> ApplyAsync(IServiceFilterRequest request, IServiceFilter filter) { return (filter != null) ? // If we have a filter, create a new instance of this type to // provide the final default continuation filter.Handle(request, new ServiceFilter()) : // If we don't have a filter, just return the response directly request.GetResponse(); }
/// <summary> /// Apply a chain of IServiceFilters to an HTTP request and get the /// corresponding HTTP response. /// </summary> /// <param name="request">The HTTP request.</param> /// <param name="filter"> /// The filter (or chain of filters composed together into a single /// filter) to apply to the request to obtain the response. /// </param> /// <returns>The HTTP response.</returns> public static async Task <IServiceFilterResponse> ApplyAsync(IServiceFilterRequest request, IServiceFilter filter) { return((filter != null) ? // If we have a filter, create a new instance of this type to // provide the final default continuation await filter.Handle(request, new ServiceFilter()) : // If we don't have a filter, just return the response directly await request.GetResponse()); }
public Task <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { Request = request; //return Task.FromResult<IServiceFilterResponse>(Response).AsAsyncOperation(); var tcs = new TaskCompletionSource <IServiceFilterResponse>(); tcs.SetResult(Response); return(tcs.Task); }
/// <summary> /// Handle an HTTP request and its corresponding response. /// </summary> /// <param name="request">The HTTP request.</param> /// <returns>The HTTP response.</returns> public Task <IServiceFilterResponse> Handle(IServiceFilterRequest request) { if (request == null) { throw new ArgumentNullException("request"); } // Filter(next(request)) return(this.Filter.Handle(request, this.Next)); }
/// <summary> /// Throw an exception for an invalid response to a web request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> /// <param name="body">The body of the response as JSON.</param> private static void ThrowInvalidResponse(IServiceFilterRequest request, IServiceFilterResponse response, IJsonValue body) { Debug.Assert(request != null, "request cannot be null!"); Debug.Assert(response != null, "response cannot be null!"); Debug.Assert( response.ResponseStatus != ServiceFilterResponseStatus.Success || response.StatusCode >= 400, "response should be failing!"); // Create either an invalid response or connection failed message // (check the status code first because some status codes will // set a protocol ErrorStatus). string message = null; if (response.StatusCode >= 400) { if (body != null) { if (body.ValueType == JsonValueType.String) { // User scripts might return errors with just a plain string message as the // body content, so use it as the exception message message = body.GetString(); } else if (body.ValueType == JsonValueType.Object) { // Get the error message, but default to the status description // below if there's no error message present. message = body.Get("error").AsString() ?? body.Get("description").AsString(); } } if (string.IsNullOrWhiteSpace(message)) { message = string.Format( CultureInfo.InvariantCulture, Resources.MobileServiceClient_ErrorMessage, response.StatusDescription); } } else { message = string.Format( CultureInfo.InvariantCulture, Resources.MobileServiceClient_ErrorMessage, response.ResponseStatus); } // Combine the pieces and throw the exception throw CreateMobileServiceException(message, request, response); }
/// <summary> /// Handle an HTTP request and its corresponding response by applying /// the first filter and then the second filter. /// </summary> /// <param name="request">The HTTP request.</param> /// <param name="next"> /// The next operation in the HTTP pipeline to continue with. /// </param> /// <returns>The HTTP response.</returns> public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation next) { if (request == null) { throw new ArgumentNullException("request"); } else if (next == null) { throw new ArgumentNullException("next"); } // Second(First(next(request)) return this.Second.Handle(request, new ComposedContinuation(this.First, next)); }
/// <summary> /// Handle an HTTP request and its corresponding response by applying /// the first filter and then the second filter. /// </summary> /// <param name="request">The HTTP request.</param> /// <param name="next"> /// The next operation in the HTTP pipeline to continue with. /// </param> /// <returns>The HTTP response.</returns> public Task <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation next) { if (request == null) { throw new ArgumentNullException("request"); } else if (next == null) { throw new ArgumentNullException("next"); } // Second(First(next(request)) return(this.Second.Handle(request, new ComposedContinuation(this.First, next))); }
/// <summary> /// Throw an exception for an invalid response to a web request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> /// <param name="body">The body of the response as JSON.</param> private static void ThrowInvalidResponse(IServiceFilterRequest request, IServiceFilterResponse response, IJsonValue body) { Debug.Assert(request != null, "request cannot be null!"); Debug.Assert(response != null, "response cannot be null!"); Debug.Assert( response.ResponseStatus != ServiceFilterResponseStatus.Success || response.StatusCode >= 400, "response should be failing!"); // Create either an invalid response or connection failed message // (check the status code first because some status codes will // set a protocol ErrorStatus). string message = null; if (response.StatusCode >= 400) { // Get the error message, but default to the status message // if there's no error message present. string error = body.Get("error").AsString() ?? body.Get("description").AsString() ?? response.StatusDescription; // Get the status code, text int code = body.Get("code").AsInteger() ?? response.StatusCode; // Combine the pieces and throw the exception message = string.Format(CultureInfo.InvariantCulture, Resources.MobileServiceClient_ThrowInvalidResponse_ErrorMessage, code, (HttpStatusCode)code, error, response.Content); } else { message = string.Format( CultureInfo.InvariantCulture, Resources.MobileServiceClient_ThrowConnectionFailure_ErrorMessage, response.ResponseStatus); } // Combine the pieces and throw the exception throw CreateMobileServiceException(message, request, response); }
public IAsyncOperation <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { // Add master key to the request's header to have admin level control request.Headers["X-ZUMO-MASTER"] = this.masterKey; if (this.disableScripts) { // Get the request's query and append noScript=true as the first query parameter var uriBuilder = new UriBuilder(request.Uri); var oldQuery = (uriBuilder.Query ?? string.Empty).Trim('?'); uriBuilder.Query = ("noScript=true&" + oldQuery).Trim('&'); request.Uri = uriBuilder.Uri; } return(continuation.Handle(request)); }
public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { // Add master key to the request's header to have admin level control request.Headers["X-ZUMO-MASTER"] = this.masterKey; if (this.disableScripts) { // Get the request's query and append noScript=true as the first query parameter var uriBuilder = new UriBuilder(request.Uri); var oldQuery = (uriBuilder.Query ?? string.Empty).Trim('?'); uriBuilder.Query = ("noScript=true&" + oldQuery).Trim('&'); request.Uri = uriBuilder.Uri; } return continuation.Handle(request); }
private async Task <IServiceFilterResponse> HandleAsync(IServiceFilterRequest request, IServiceFilterContinuation continuation) { int ic = _callCount; bool invokeBusy = false; lock (_countLock) { if (_callCount == 0) { invokeBusy = true; } _callCount++; } if (invokeBusy) { _busyIndicator.Invoke(true); } IServiceFilterResponse response = await continuation.Handle(request).AsTask(); bool invokeIdle = false; lock (_countLock) { if (_callCount == 1) { invokeIdle = true; } _callCount--; } if (invokeIdle) { _busyIndicator.Invoke(false); } return(response); }
public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { // Get previous uri query var uriBuilder = new UriBuilder(request.Uri); var oldQuery = (uriBuilder.Query ?? string.Empty).Trim('?'); // Build new query starting with our custom parameters before old query var stringBuilder = new StringBuilder(); foreach (var parameter in parameters) { // Currently using ToString on the value, an improvement will be to serialize the object properly stringBuilder.AppendFormat("{0}={1}&", parameter.Key, parameter.Value); } stringBuilder.Append(oldQuery); // Apply new query to request uri uriBuilder.Query = stringBuilder.ToString().Trim('&'); request.Uri = uriBuilder.Uri; return continuation.Handle(request); }
private async Task<IServiceFilterResponse> HandleAsync(IServiceFilterRequest request, IServiceFilterContinuation continuation) { int ic = _callCount; bool invokeBusy = false; lock (_countLock) { if (_callCount == 0) { invokeBusy = true; } _callCount++; } if (invokeBusy) { _busyIndicator.Invoke(true); } IServiceFilterResponse response = await continuation.Handle(request).AsTask(); bool invokeIdle = false; lock (_countLock) { if (_callCount == 1) { invokeIdle = true; } _callCount--; } if (invokeIdle) { _busyIndicator.Invoke(false); } return response; }
public IAsyncOperation <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { this.RequestHeaders.Clear(); foreach (var reqHeader in request.Headers.Keys) { this.RequestHeaders.Add(reqHeader, request.Headers[reqHeader]); } return(continuation.Handle(request).AsTask().ContinueWith <IServiceFilterResponse>(t => { this.ResponseHeaders.Clear(); var response = t.Result; foreach (var respHeader in response.Headers.Keys) { this.ResponseHeaders.Add(respHeader, response.Headers[respHeader]); } this.ResponseBody = response.Content; return response; }).AsAsyncOperation()); }
public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { Request = request; return Task.FromResult<IServiceFilterResponse>(Response).AsAsyncOperation(); }
public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { request.Headers.Add("x-zumo-master", E2EZumoHelper.AppMasterKey); return continuation.Handle(request); }
public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { this.RequestHeaders.Clear(); foreach (var reqHeader in request.Headers.Keys) { this.RequestHeaders.Add(reqHeader, request.Headers[reqHeader]); } return continuation.Handle(request).AsTask().ContinueWith<IServiceFilterResponse>(t => { this.ResponseHeaders.Clear(); var response = t.Result; foreach (var respHeader in response.Headers.Keys) { this.ResponseHeaders.Add(respHeader, response.Headers[respHeader]); } this.ResponseBody = response.Content; return response; }).AsAsyncOperation(); }
/// <summary> /// Handle an HTTP request and its corresponding response. /// </summary> /// <param name="request">The HTTP request.</param> /// <returns>The HTTP response.</returns> public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request) { if (request == null) { throw new ArgumentNullException("request"); } // Filter(next(request)) return this.Filter.Handle(request, this.Next); }
public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { return this.HandleRequest(request, continuation).AsAsyncOperation(); }
public async Task<IServiceFilterResponse> HandleRequest(IServiceFilterRequest request, IServiceFilterContinuation continuation) { IServiceFilterResponse response = null; try { for (int i = 0; i < this.NumberOfRequests; i++) { response = await continuation.Handle(request); test.AddLog("Sent the request number {0}", i + 1); test.AddLog("Response: {0} - {1}", response.StatusCode, response.StatusDescription); if (response.StatusCode >= 400) { test.AddLog("Invalid response. Content-Type: {0}", response.ContentType); test.AddLog("Response content: {0}", response.Content); throw new InvalidOperationException(); } } } catch (Exception ex) { test.AddLog("Exception while calling continuation: {0}", ex); this.TestFailed = true; throw; } return response; }
public Task <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { return(Log(request, continuation)); }
public Windows.Foundation.IAsyncOperation <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { return(HandleAsync(request, continuation).AsAsyncOperation()); }
/// <summary> /// Initializes a new instance of the /// MobileServiceInvalidOperationException class. /// </summary> /// <param name="message">The exception message.</param> /// <param name="request">The originating service request.</param> /// <param name="response">The returned service response.</param> internal MobileServiceInvalidOperationException(string message, IServiceFilterRequest request, IServiceFilterResponse response) : base(message) { this.Request = request; this.Response = response; }
public IAsyncOperation <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { return(Log(request, continuation).AsAsyncOperation()); }
public Task<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { return Log(request, continuation); }
public IAsyncOperation <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { Request = request; return(Task.FromResult <IServiceFilterResponse>(Response).AsAsyncOperation()); }
public Windows.Foundation.IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { return HandleAsync(request, continuation).AsAsyncOperation(); }
public IAsyncOperation <IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { throw new NotImplementedException(); }
public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { TaskCompletionSource<IServiceFilterResponse> tcs = new TaskCompletionSource<IServiceFilterResponse>(); tcs.SetResult(new MyResponse(this.statusCode, this.statusDescription, this.contentType, this.content)); return tcs.Task.AsAsyncOperation(); }
public IAsyncOperation<IServiceFilterResponse> Handle(IServiceFilterRequest request, IServiceFilterContinuation continuation) { throw new NotImplementedException(); }