Beispiel #1
0
        public Task <TReply> InvokeAsync <TRequest, TReply>(TRequest request)
            where TRequest : IRequest <TReply>
        {
            var invokeMethod = new InvokeMessage <TRequest, TReply>(request);

            if (!Publish(invokeMethod))
            {
                invokeMethod.SetCanceled();
            }
            return(invokeMethod.Completion);
        }
Beispiel #2
0
        private bool Handle(InvokeMessage <TRequest, TReply> message)
        {
            if (!message.TryBeginHandle())
            {
                return(false);
            }

            try
            {
                _handler.Invoke(message.Request)
                .ContinueWith(OnCompleted, message, TaskContinuationOptions.ExecuteSynchronously);
            }
            catch (OperationCanceledException)
            {
                message.SetCanceled();
            }
            catch (Exception ex)
            {
                message.SetException(ex);
            }

            return(true);
        }
Beispiel #3
0
        private bool Handle(InvokeMessage <TRequest, TReply> message)
        {
            if (!message.TryBeginHandle())
            {
                return(false);
            }

            try
            {
                var result = _handler.Invoke(message.Request);
                message.SetResult(result);
            }
            catch (OperationCanceledException)
            {
                message.SetCanceled();
            }
            catch (Exception ex)
            {
                message.SetException(ex);
            }

            return(true);
        }