public IEnumerable <T> GetResourceProviders <T>()
     where T : IResourceProvider
 {
     return(Resources.OfType <T>());
 }
Exemplo n.º 2
0
        public static async Task <(ConnectionRecord firstParty, ConnectionRecord secondParty)> EstablishConnectionAsync(
            IConnectionService connectionService,
            IProducerConsumerCollection <AgentMessage> _messages,
            IAgentContext firstContext,
            IAgentContext secondContext,
            ConnectionInvitationMessage inviteMessage = null,
            string inviteeconnectionId = null)
        {
            // Create invitation by the issuer
            var connectionSecondId = Guid.NewGuid().ToString();

            var inviteConfig = new InviteConfiguration
            {
                ConnectionId = connectionSecondId,
                MyAlias      = new ConnectionAlias
                {
                    Name     = "Issuer",
                    ImageUrl = "www.issuerdomain.com/profilephoto"
                },
                TheirAlias = new ConnectionAlias
                {
                    Name     = "Holder",
                    ImageUrl = "www.holderdomain.com/profilephoto"
                }
            };

            if (inviteMessage == null)
            {
                (inviteMessage, _) = await connectionService.CreateInvitationAsync(firstContext, inviteConfig);
            }

            var connectionFirst = await connectionService.GetAsync(firstContext, inviteeconnectionId ?? inviteConfig.ConnectionId);

            Assert.Equal(ConnectionState.Invited, connectionFirst.State);

            // Holder accepts invitation and sends a message request
            (var request, var inviteeConnection) = await connectionService.CreateRequestAsync(secondContext, inviteMessage);

            var connectionSecond = inviteeConnection;

            _messages.TryAdd(request);

            Assert.Equal(ConnectionState.Negotiating, connectionSecond.State);

            // Issuer processes incoming message
            var issuerMessage = _messages.OfType <ConnectionRequestMessage>().FirstOrDefault();

            Assert.NotNull(issuerMessage);

            // Issuer processes the connection request by storing it and accepting it if auto connection flow is enabled
            connectionSecondId = await connectionService.ProcessRequestAsync(firstContext, issuerMessage, connectionFirst);

            connectionFirst = await connectionService.GetAsync(firstContext, connectionSecondId);

            Assert.Equal(ConnectionState.Negotiating, connectionFirst.State);

            // Issuer accepts the connection request
            (var response, var _) = await connectionService.CreateResponseAsync(firstContext, connectionSecondId);

            _messages.TryAdd(response);

            connectionFirst = await connectionService.GetAsync(firstContext, connectionSecondId);

            Assert.Equal(ConnectionState.Connected, connectionFirst.State);

            // Holder processes incoming message
            var holderMessage = _messages.OfType <ConnectionResponseMessage>().FirstOrDefault();

            Assert.NotNull(holderMessage);

            // Holder processes the response message by accepting it
            await connectionService.ProcessResponseAsync(secondContext, holderMessage, connectionSecond);

            // Retrieve updated connection state for both issuer and holder
            connectionFirst = await connectionService.GetAsync(firstContext, connectionFirst.Id);

            connectionSecond = await connectionService.GetAsync(secondContext, connectionSecond.Id);

            return(connectionFirst, connectionSecond);
        }
Exemplo n.º 3
0
        internal static async Task <(ConnectionRecord firstParty, ConnectionRecord secondParty)> EstablishConnectionAsync(
            IConnectionService connectionService,
            IProducerConsumerCollection <IEnvelopeMessage> _messages,
            Wallet firstWallet,
            Wallet secondWallet,
            bool autoConnectionFlow = false)
        {
            // Create invitation by the issuer
            var issuerConnectionId = Guid.NewGuid().ToString();

            var inviteConfig = new DefaultCreateInviteConfiguration()
            {
                ConnectionId         = issuerConnectionId,
                AutoAcceptConnection = autoConnectionFlow,
                MyAlias = new ConnectionAlias()
                {
                    Name     = "Issuer",
                    ImageUrl = "www.issuerdomain.com/profilephoto"
                },
                TheirAlias = new ConnectionAlias()
                {
                    Name     = "Holder",
                    ImageUrl = "www.holderdomain.com/profilephoto"
                }
            };

            // Issuer creates an invitation
            var invitation = await connectionService.CreateInvitationAsync(firstWallet, inviteConfig);

            var connectionIssuer = await connectionService.GetAsync(firstWallet, issuerConnectionId);

            Assert.Equal(ConnectionState.Invited, connectionIssuer.State);
            Assert.True(invitation.Name == inviteConfig.MyAlias.Name &&
                        invitation.ImageUrl == inviteConfig.MyAlias.ImageUrl);

            // Holder accepts invitation and sends a message request
            var holderConnectionId = await connectionService.AcceptInvitationAsync(secondWallet, invitation);

            var connectionHolder = await connectionService.GetAsync(secondWallet, holderConnectionId);

            Assert.Equal(ConnectionState.Negotiating, connectionHolder.State);

            // Issuer processes incoming message
            var issuerMessage = _messages.OfType <ForwardToKeyEnvelopeMessage>()
                                .First(x => x.Type.Contains(connectionIssuer.Tags.Single(item => item.Key == "connectionKey").Value));

            var requestMessage = GetContentMessage(issuerMessage) as ConnectionRequestMessage;

            Assert.NotNull(requestMessage);

            // Issuer processes the connection request by storing it and accepting it if auto connection flow is enabled
            await connectionService.ProcessRequestAsync(firstWallet, requestMessage);

            if (!autoConnectionFlow)
            {
                connectionIssuer = await connectionService.GetAsync(firstWallet, issuerConnectionId);

                Assert.Equal(ConnectionState.Negotiating, connectionIssuer.State);

                // Issuer accepts the connection request
                await connectionService.AcceptRequestAsync(firstWallet, issuerConnectionId);
            }

            connectionIssuer = await connectionService.GetAsync(firstWallet, issuerConnectionId);

            Assert.Equal(ConnectionState.Connected, connectionIssuer.State);

            // Holder processes incoming message
            var holderMessage = _messages.OfType <ForwardEnvelopeMessage>()
                                .First(x => x.Type.Contains(connectionHolder.MyDid));

            var responseMessage = GetContentMessage(holderMessage) as ConnectionResponseMessage;

            Assert.NotNull(responseMessage);

            // Holder processes the response message by accepting it
            await connectionService.ProcessResponseAsync(secondWallet, responseMessage);

            // Retrieve updated connection state for both issuer and holder
            connectionIssuer = await connectionService.GetAsync(firstWallet, issuerConnectionId);

            connectionHolder = await connectionService.GetAsync(secondWallet, holderConnectionId);

            Assert.True(connectionIssuer.Alias.Name == inviteConfig.TheirAlias.Name &&
                        connectionIssuer.Alias.ImageUrl == inviteConfig.TheirAlias.ImageUrl);
            Assert.True(connectionHolder.Alias.Name == inviteConfig.MyAlias.Name &&
                        connectionHolder.Alias.ImageUrl == inviteConfig.MyAlias.ImageUrl);

            return(connectionIssuer, connectionHolder);
        }