Пример #1
0
        public static IAsyncOperation <AppServiceResponseStatus> SendResponseAsync(this AppServiceRequest request, IResponseMessage message)
        {
            var rqmsg  = request.Message;
            var method = rqmsg["Method"].ToString();
            var rsType = MappingInfo.RequestToResponseMap[MappingInfo.MethodToRequestMap[method]];

            if (!(message is ErrorResponse || message.GetType() == rsType))
            {
                throw new ArgumentException($"类型错误,应为 {rsType} 或 {typeof(ErrorResponse)}。", nameof(message));
            }
            return(request.SendResponseAsync(message.ToValueSet()));
        }
Пример #2
0
        public async Task<SendResult> Send(IResponseMessage message)
        {
            if (message == null)
                throw new NullReferenceException(nameof(message));

            var aliyunMessage = message as AliyunMessage;

            if (aliyunMessage == null)
                throw new NotSupportedException($"当前发布者提供程序:{GetType().FullName},无法发送类型为:{message.GetType().FullName}的消息。");
            if (string.IsNullOrWhiteSpace(aliyunMessage.Topic))
                throw new ArgumentException("消息主题(Topic)不能为空!");
            if (string.IsNullOrWhiteSpace(aliyunMessage.Body))
                throw new ArgumentException("消息主体(Body)不能为空!");

            return await Task.Run(() =>
            {
                using (var result = _producer.send(aliyunMessage.Message))
                {
                    return new SendResult { MessageId = result.getMessageId() };
                }
            });
        }
Пример #3
0
        public async Task <SendResult> Send(IResponseMessage message)
        {
            if (message == null)
            {
                throw new NullReferenceException(nameof(message));
            }

            var aliyunMessage = message as AliyunMessage;

            if (aliyunMessage == null)
            {
                throw new NotSupportedException($"当前发布者提供程序:{GetType().FullName},无法发送类型为:{message.GetType().FullName}的消息。");
            }
            if (string.IsNullOrWhiteSpace(aliyunMessage.Topic))
            {
                throw new ArgumentException("消息主题(Topic)不能为空!");
            }
            if (string.IsNullOrWhiteSpace(aliyunMessage.Body))
            {
                throw new ArgumentException("消息主体(Body)不能为空!");
            }

            return(await Task.Run(() =>
            {
                using (var result = _producer.send(aliyunMessage.Message))
                {
                    return new SendResult {
                        MessageId = result.getMessageId()
                    };
                }
            }));
        }
        /// <summary>
        /// Called internally when a response is recieved. (setup using the subscription service)
        /// </summary>
        /// <param name="message">Incoming message.</param>
        /// <param name="parameters">Parameters the message was sent with (Null right now in this implementation).</param>
        protected override void OnReceiveResponse(IResponseMessage message, IMessageParameters parameters)
        {
            //As of right now the implementation for the web client cannot provide message parameters.
            //As such we should not check them, they're likely to be null until their implemented

            //So, just check payloads
            Throw <ArgumentNullException> .If
            .IsNull(message)?.Now(nameof(message), $"This indicates a critical error. The GladNet API has provided a null {nameof(IResponseMessage)} to the {nameof(AuthServiceClientPeer.OnReceiveResponse)} method.");

            if (!responseHandlerService.TryProcessMessage(message, parameters, this))
            {
                //TODO: When message parameters are implemented for GladNet.ASP.Client we should include them in the logging statement.
                Logger.Warn($"Failed to handle response message in {nameof(OnReceiveResponse)} for Type {nameof(AuthServiceClientPeer)} with PayloadType {message.GetType().Name}.");
            }
        }
Пример #5
0
        public void AddResponse(IResponseMessage message)
        {
            switch (message)
            {
            case Reply reply:
                _responseAwaiters[ResponseType.Reply].AddResponse(reply);
                break;

            case Confirmation confirmation:
                _responseAwaiters[ResponseType.Confirmation].AddResponse(confirmation);
                break;

            case null:
                throw new ArgumentNullException(nameof(message), $"Passed {nameof(IResponseMessage)} was null");

            default:
                throw new ArgumentOutOfRangeException(nameof(message), $"Passed {nameof(message)} type ({message.GetType()}) is unknown to this {nameof(ResponseAwaiterDispatch)} instance and cannot be handled.");
            }
        }