Exemplo n.º 1
0
        public void Handle(Agent agent, Action <object> responseWriter)
        {
            object result = null;

            Task.Factory.StartNew(
                async() => {
                try {
                    result = await HandleAsync(agent);
                    if (result == null && !CanReturnNull)
                    {
                        throw new Exception($"{GetType ()}.Handle(Agent) returned null");
                    }
                } catch (Exception e) {
                    result = new XipErrorMessage {
                        Message   = $"{GetType ()}.Handle(Agent) threw an exception",
                        Exception = ExceptionNode.Create(e)
                    };
                }
            },
                CancellationToken.None,
                TaskCreationOptions.DenyChildAttach,
                MainThread.TaskScheduler).Unwrap().Wait();

            responseWriter(result);
        }
Exemplo n.º 2
0
        async Task <TResult> SendAsync <TResult> (
            IXipRequestMessage message,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            TResult         result      = default(TResult);
            XipErrorMessage errorResult = null;

            await SendAsync(message, response => {
                errorResult = response as XipErrorMessage;
                if (errorResult == null)
                {
                    result = (TResult)response;
                }
            }, cancellationToken);

            if (errorResult != null)
            {
                Log.Error(TAG, $"SendAsync ({message.GetType ()}) -> " +
                          $"{typeof (TResult)}: {errorResult}");
                errorResult.Throw();
            }

            return(result);
        }