/// <inheritdoc />
        public async Task OnMessageAsync(IAgentContext agentContext, UnpackedMessageContext messageContext)
        {
            // TrustPingMessage event aggregator event doesn't include the connection so we can't verify whether the
            // received trust ping comes from the connection we send the connection response to.
            // For this reason we handle this specific case through a middleware where we do have the
            // connection from which the trust ping message came
            if (messageContext.GetMessageType() == MessageTypes.TrustPingMessageType)
            {
                var message = messageContext.GetMessage <TrustPingMessage>();

                var THConnection = _cache.Get <TestHarnessConnection>(messageContext.Connection.Id);

                if (THConnection != null && THConnection.State == TestHarnessConnectionState.Responded)
                {
                    THConnection.State = TestHarnessConnectionState.Complete;
                }
            }
            // When we receive a request presentation message we need to create a TestHarnessPresentationExchange and
            // store it in the cache for future use. This allow us to keep track of the current state of the presentation exchange
            else if (messageContext.GetMessageType() == MessageTypes.PresentProofNames.RequestPresentation)
            {
                var message = messageContext.GetMessage <RequestPresentationMessage>();

                var proofRecord = await _proofService.GetByThreadIdAsync(agentContext, message.GetThreadId());

                var THPresentationExchange = new TestHarnessPresentationExchange
                {
                    ThreadId = message.GetThreadId(),
                    RecordId = proofRecord.Id,
                    State    = TestHarnessPresentationExchangeState.RequestReceived,
                };

                _cache.Set(THPresentationExchange.ThreadId, THPresentationExchange);
            }
        }
示例#2
0
        public async Task <IActionResult> GetProofRecordByThreadIdAsync([FromRoute] string threadId)
        {
            var context = await _agentContextProvider.GetContextAsync();

            try
            {
                var proofRecord = await _proofService.GetByThreadIdAsync(context, threadId);

                var THProofExchange = _proofCache.Get <TestHarnessPresentationExchange>(threadId);
                if (THProofExchange == null)
                {
                    return(NotFound());
                }

                return(Ok(THProofExchange));
            }
            catch
            {
                // Can't find the proof record
                return(NotFound());
            }
        }