public void InitialConnectionRecordIsInvitedAndHasTag() { var record = new ConnectionRecord(); Assert.True(record.State == ConnectionState.Invited); Assert.True(record.GetTag(nameof(ConnectionRecord.State)) == ConnectionState.Invited.ToString("G")); }
private async Task AddDeviceInfoAsync(IAgentContext agentContext, ConnectionRecord connection, AddDeviceInfoMessage addDeviceInfoMessage) { var inboxId = connection.GetTag("InboxId"); if (inboxId == null) { throw new InvalidOperationException("Inbox was not found. Create an inbox first"); } var deviceRecord = new DeviceInfoRecord { InboxId = inboxId, DeviceId = addDeviceInfoMessage.DeviceId, DeviceVendor = addDeviceInfoMessage.DeviceVendor }; try { await recordService.AddAsync(agentContext.Wallet, deviceRecord); } catch (WalletItemAlreadyExistsException) { } catch (Exception e) { logger.LogError(e, "Unable to register device", addDeviceInfoMessage); } }
/// <summary> /// Sends the message and receives a response by adding return routing decorator /// according to the Routing RFC. /// </summary> /// <param name="service"></param> /// <param name="agentContext"></param> /// <param name="message"></param> /// <param name="connection"></param> /// <returns></returns> public static async Task <MessageContext> SendReceiveAsync(this IMessageService service, IAgentContext agentContext, AgentMessage message, ConnectionRecord connection) { var routingKeys = connection.Endpoint?.Verkey != null ? connection.Endpoint.Verkey : new string[0]; var recipientKey = connection.TheirVk ?? connection.GetTag("InvitationKey") ?? throw new InvalidOperationException("Cannot locate a recipient key"); if (connection.Endpoint?.Uri == null) { throw new AriesFrameworkException(ErrorCode.A2AMessageTransmissionError, "Cannot send to connection that does not have endpoint information specified"); } return(await service.SendReceiveAsync(agentContext, message, recipientKey, connection.Endpoint.Uri, routingKeys, connection.MyVk)); }
private async Task AddDeviceInfoAsync(IAgentContext agentContext, ConnectionRecord connection, AddDeviceInfoMessage addDeviceInfoMessage) { var inboxId = connection.GetTag("InboxId"); if (inboxId == null) { throw new InvalidOperationException("Inbox was not found. Create an inbox first"); } var deviceRecord = new DeviceInfoRecord { InboxId = inboxId, DeviceId = addDeviceInfoMessage.DeviceId, DeviceVendor = addDeviceInfoMessage.DeviceVendor }; await recordService.AddAsync(agentContext.Wallet, deviceRecord); }
private async Task <GetInboxItemsResponseMessage> GetInboxItemsAsync(IAgentContext agentContext, ConnectionRecord connection, GetInboxItemsMessage getInboxItemsMessage) { var inboxId = connection.GetTag("InboxId"); var inboxRecord = await recordService.GetAsync <InboxRecord>(agentContext.Wallet, inboxId); var edgeWallet = await walletService.GetWalletAsync(inboxRecord.WalletConfiguration, inboxRecord.WalletCredentials); var items = await recordService.SearchAsync <InboxItemRecord>(edgeWallet); return(new GetInboxItemsResponseMessage { Items = items .Select(x => new InboxItemMessage { Id = x.Id, Data = x.ItemData }) .ToList() }); }
private async Task DeleteInboxItemsAsync(IAgentContext agentContext, ConnectionRecord connection, DeleteInboxItemsMessage deleteInboxItemsMessage) { var inboxId = connection.GetTag("InboxId"); var inboxRecord = await recordService.GetAsync <InboxRecord>(agentContext.Wallet, inboxId); var edgeWallet = await walletService.GetWalletAsync(inboxRecord.WalletConfiguration, inboxRecord.WalletCredentials); foreach (var itemId in deleteInboxItemsMessage.InboxItemIds) { try { await recordService.DeleteAsync <InboxItemRecord>(edgeWallet, itemId); } catch (Exception e) { logger.LogError(e, "Couldn't delete inbox item {ItemId}", itemId); } } }
private async Task AddRouteAsync(IAgentContext _, ConnectionRecord connection, AddRouteMessage addRouteMessage) { var inboxId = connection.GetTag("InboxId"); await routingStore.AddRouteAsync(addRouteMessage.RouteDestination, inboxId); }