Ejemplo n.º 1
0
        public void ProcessTokenStatusEvent(Session session, Message message, Action <Session, Message, Exception> onFailure)
        {
            AsyncPattern <string> asyncPattern;

            if (!AsyncHandlers.TryGetValue(message.CorrelationID, out asyncPattern))
            {
                onFailure(session, message, new Exception("Failed to find correlation id: " + message.CorrelationID));
            }
            else
            {
                AsyncHandlers.Remove(message.CorrelationID);

                if (MessageTypeNames.TokenGenerationFailure.Equals(message.MessageType))
                {
                    var reasonElement = message.GetElement(ElementNames.Reason);

                    var error = new ResponseError(
                        reasonElement.GetElementAsString(ElementNames.Source),
                        reasonElement.GetElementAsString(ElementNames.Category),
                        reasonElement.GetElementAsString(ElementNames.SubCategory),
                        reasonElement.GetElementAsInt32(ElementNames.ErrorCode),
                        reasonElement.GetElementAsString(ElementNames.Description));

                    asyncPattern.OnFailure(new ContentException <ResponseError>(error));
                }
                else if (MessageTypeNames.TokenGenerationSuccess.Equals(message.MessageType))
                {
                    asyncPattern.OnSuccess(message.GetElementAsString(ElementNames.Token));
                }
                else
                {
                    onFailure(session, message, new Exception("Unknown message type: " + message.MessageType));
                }
            }
        }
Ejemplo n.º 2
0
        public void Process(Session session, Message message, Action <Session, Message, Exception> onFailure)
        {
            AsyncPattern <Service> asyncHandler;

            if (!AsyncHandlers.TryGetValue(message.CorrelationID, out asyncHandler))
            {
                onFailure(session, message, new Exception("Failed to find handler for service status event with correlation id: " + message.CorrelationID));
                return;
            }

            AsyncHandlers.Remove(message.CorrelationID);

            if (MessageTypeNames.ServiceOpenFailure.Equals(message.MessageType))
            {
                asyncHandler.OnFailure(new ContentException <ServiceOpenFailureEventArgs>(new ServiceOpenFailureEventArgs()));
            }
            else if (MessageTypeNames.ServiceOpened.Equals(message.MessageType))
            {
                asyncHandler.OnSuccess(session.GetService(message.GetElementAsString(ElementNames.ServiceName)));
            }
            else
            {
                onFailure(session, message, new Exception("Unknown service status event message: " + message));
            }
        }