/// <summary>
        /// Processes the agent message
        /// </summary>
        /// <param name="agentContext"></param>
        /// <param name="messagePayload">The agent message.</param>
        /// <returns></returns>
        /// <exception cref="AgentFrameworkException">Unsupported message type {messageType}</exception>
        public async Task ProcessAsync(IAgentContext agentContext, MessagePayload messagePayload)
        {
            switch (messagePayload.GetMessageType())
            {
            case MessageTypes.CredentialOffer:
                var offer        = messagePayload.GetMessage <CredentialOfferMessage>();
                var credentialId = await _credentialService.ProcessOfferAsync(
                    agentContext, offer, agentContext.Connection);

                await _credentialService.AcceptOfferAsync(agentContext, credentialId);

                return;

            case MessageTypes.CredentialRequest:
                var request = messagePayload.GetMessage <CredentialRequestMessage>();
                await _credentialService.ProcessCredentialRequestAsync(
                    agentContext, request, agentContext.Connection);

                return;

            case MessageTypes.Credential:
                var credential = messagePayload.GetMessage <CredentialMessage>();
                await _credentialService.ProcessCredentialAsync(
                    agentContext, credential, agentContext.Connection);

                return;

            default:
                throw new AgentFrameworkException(ErrorCode.InvalidMessage,
                                                  $"Unsupported message type {messagePayload.GetMessageType()}");
            }
        }
        /// <summary>
        /// Processes the agent message
        /// </summary>
        /// <param name="agentContext"></param>
        /// <param name="messagePayload">The agent message agentContext.</param>
        public async Task <AgentMessage> ProcessAsync(IAgentContext agentContext, MessagePayload messagePayload)
        {
            switch (messagePayload.GetMessageType())
            {
            case CustomMessageTypes.TrustPingMessageType:
            {
                var pingMessage = messagePayload.GetMessage <TrustPingMessage>();

                // if (pingMessage.ResponseRequested)
                // {
                return(pingMessage.CreateThreadedReply <TrustPingResponseMessage>());
                // }
            }

            case CustomMessageTypes.TrustPingResponseMessageType:
            {
                _eventAggregator.Publish(new ServiceMessageProcessingEvent
                    {
                        MessageType = CustomMessageTypes.TrustPingResponseMessageType
                    });
                break;
            }
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Processes the agent message
        /// </summary>
        /// <param name="agentContext"></param>
        /// <param name="messagePayload">The agent message agentContext.</param>
        /// <returns></returns>
        /// <exception cref="AgentFrameworkException">Unsupported message type {message.Type}</exception>
        public async Task ProcessAsync(IAgentContext agentContext, MessagePayload messagePayload)
        {
            switch (messagePayload.GetMessageType())
            {
            case MessageTypes.ConnectionInvitation:
                var invitation = messagePayload.GetMessage <ConnectionInvitationMessage>();
                await _connectionService.AcceptInvitationAsync(agentContext, invitation);

                return;

            case MessageTypes.ConnectionRequest:
                var request      = messagePayload.GetMessage <ConnectionRequestMessage>();
                var connectionId = await _connectionService.ProcessRequestAsync(agentContext, request);

                // Auto accept connection if set during invitation
                if (agentContext.Connection.GetTag(TagConstants.AutoAcceptConnection) == "true")
                {
                    // Add a response message to be processed by the handler pipeline
                    if (agentContext is AgentContext context)
                    {
                        context.AddNext(new OutgoingMessage
                        {
                            Message = (await _connectionService.AcceptRequestAsync(agentContext, connectionId))
                                      .ToJson()
                        }
                                        .AsMessagePayload());
                    }
                }

                return;

            case MessageTypes.ConnectionResponse:
                var response = messagePayload.GetMessage <ConnectionResponseMessage>();
                await _connectionService.ProcessResponseAsync(agentContext, response);

                return;

            default:
                throw new AgentFrameworkException(ErrorCode.InvalidMessage,
                                                  $"Unsupported message type {messagePayload.GetMessageType()}");
            }
        }
        /// <summary>
        /// Processes the agent message
        /// </summary>
        /// <param name="agentContext"></param>
        /// <param name="messagePayload">The agent message agentContext.</param>
        /// <returns></returns>
        /// <exception cref="AgentFrameworkException">Unsupported message type {messageType}</exception>
        public async Task ProcessAsync(IAgentContext agentContext, MessagePayload messagePayload)
        {
            switch (messagePayload.GetMessageType())
            {
            case MessageTypes.ProofRequest:
                var request = messagePayload.GetMessage <ProofRequestMessage>();
                await _proofService.ProcessProofRequestAsync(agentContext, request);

                break;

            case MessageTypes.DisclosedProof:
                var proof = messagePayload.GetMessage <ProofMessage>();
                await _proofService.ProcessProofAsync(agentContext, proof);

                break;

            default:
                throw new AgentFrameworkException(ErrorCode.InvalidMessage,
                                                  $"Unsupported message type {messagePayload.GetMessageType()}");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Processes the agent message
        /// </summary>
        /// <param name="agentContext"></param>
        /// <param name="messagePayload">The agent message agentContext.</param>
        /// <returns></returns>
        /// <exception cref="AgentFrameworkException">Unsupported message type {message.Type}</exception>
        public async Task <AgentMessage> ProcessAsync(IAgentContext agentContext, MessagePayload messagePayload)
        {
            switch (messagePayload.GetMessageType())
            {
            case MessageTypes.ConnectionInvitation:
                var invitation = messagePayload.GetMessage <ConnectionInvitationMessage>();
                await _connectionService.AcceptInvitationAsync(agentContext, invitation);

                return(null);

            case MessageTypes.ConnectionRequest:
            {
                var request      = messagePayload.GetMessage <ConnectionRequestMessage>();
                var connectionId = await _connectionService.ProcessRequestAsync(agentContext, request);

                // Auto accept connection if set during invitation
                if (agentContext.Connection.GetTag(TagConstants.AutoAcceptConnection) == "true")
                {
                    var message = await _connectionService.AcceptRequestAsync(agentContext, connectionId);

                    await _messageService.SendToConnectionAsync(agentContext.Wallet, message, agentContext.Connection);
                }
                return(null);
            }

            case MessageTypes.ConnectionResponse:
            {
                var response = messagePayload.GetMessage <ConnectionResponseMessage>();
                await _connectionService.ProcessResponseAsync(agentContext, response);

                return(null);
            }

            default:
                throw new AgentFrameworkException(ErrorCode.InvalidMessage,
                                                  $"Unsupported message type {messagePayload.GetMessageType()}");
            }
        }