Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private RunAsyncOptions GetRunAsycOptions(DispatchThreadServerRequest request)
        {
            RunAsyncOptions options = default(RunAsyncOptions);

            if (request.RunOnSequentialQueue)
            {
                options |= RunAsyncOptions.RunOnSequentialQueue;
            }
            return(options);
        }
Esempio n. 3
0
        private void OnRequestSuccess(DispatchThreadServerRequest request, TypedResponse response)
        {
            if (request.OnThreadPoolReceive != null)
            {
                Logger.WrapActionInvocation(request.OnThreadPoolReceive);
            }

            if (request.OnDispatchThreadSuccess != null)
            {
                _synchronizationContextProvider.DispatchThreadContext.Post(() =>
                                                                           request.OnDispatchThreadSuccess(response));
            }
        }
Esempio n. 4
0
        private void OnRequestError(DispatchThreadServerRequest request, ErrorResponse errorResponse)
        {
            if (request.OnThreadPoolReceive != null)
            {
                Logger.WrapActionInvocation(request.OnThreadPoolReceive);
            }

            if (request.OnDispatchThreadError != null)
            {
                _synchronizationContextProvider.DispatchThreadContext.Post(() => {
                    if (errorResponse.IsOperationCanceled())
                    {
                        // UIRequest are cancelable at any point.
                    }
                    else
                    {
                        request.OnDispatchThreadError(errorResponse);
                    }
                });
            }
        }