protected static Func <T> SendRequest <T>(ITypedRequestProcessProxy server, TypedRequest request, TimeSpan timeout) where T : TypedResponse { var sw = new Stopwatch(); var waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset); T response = null; ErrorResponse error = null; sw.Start(); server.RunAsync(request, typedResponse => { Assert.IsInstanceOfType(typedResponse, typeof(T)); sw.Stop(); Logger.LogInfo("Request {0} took {1} msec to complete.", request.ClassName, sw.ElapsedMilliseconds); response = (T)typedResponse; waitHandle.Set(); }, errorResponse => { error = errorResponse; }); return(() => { if (!waitHandle.WaitOne(timeout)) { return null; } if (error != null) { throw ErrorResponseHelper.CreateException(error); } return response; }); }
public void Post(UIRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.Id == null) { throw new ArgumentException(@"Request must have an Id.", "request"); } if (request.TypedRequest == null) { throw new ArgumentException(@"Request must have a typed request.", "request"); } var operation = new DelayedOperation { Id = request.Id, Delay = request.Delay, Action = () => { if (request.OnBeforeRun != null) { Logger.WrapActionInvocation(request.OnBeforeRun); } _typedRequestProcessProxy.RunAsync(request.TypedRequest, response => OnRequestSuccess(request, response), errorResponse => OnRequestError(request, errorResponse)); } }; _delayedOperationProcessor.Post(operation); }
public void Post(DispatchThreadServerRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.Id == null) { throw new ArgumentException(@"Request must have an Id.", "request"); } if (request.Request == null) { throw new ArgumentException(@"Request must have a typed request.", "request"); } var operation = new DelayedOperation { Id = request.Id, Delay = request.Delay, // Action executed on a background thread when delay has expired. Action = () => { if (request.OnThreadPoolSend != null) { Logger.WrapActionInvocation(request.OnThreadPoolSend); } _typedRequestProcessProxy.RunAsync(request.Request, GetRunAsycOptions(request), response => OnRequestSuccess(request, response), errorResponse => OnRequestError(request, errorResponse)); }, }; _delayedOperationExecutor.Post(operation); }
private void FetchFileSystemTree() { _proxy.RunAsync( new GetFileSystemRequest(), typedResponse => { var response = (GetFileSystemResponse)typedResponse; OnTreeReceived(response.Tree); }, OnErrorReceived); }