Exemple #1
0
        public async Task <bool> CreateAgentAsync(AgentOptions options)
        {
            var discovery = await _edgeClientService.DiscoverConfigurationAsync(options.EndpointUri);

            discovery.ServiceEndpoint            = options.EndpointUri;
            discovery.Invitation.ServiceEndpoint = options.EndpointUri;

#if __ANDROID__
            WalletConfiguration.WalletStorageConfiguration _storage = new WalletConfiguration.WalletStorageConfiguration {
                Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".indy_client")
            };
            options.WalletOptions.WalletConfiguration.StorageConfiguration = _storage;
#endif
            await _provisioningService.ProvisionAgentAsync(new AgentOptions
            {
                WalletConfiguration = options.WalletConfiguration,
                WalletCredentials   = options.WalletCredentials,
                AgentKeySeed        = options.AgentKeySeed,
                EndpointUri         = options.EndpointUri,
                AgentName           = options.AgentName == null ? "Default Agent" : options.AgentName
            });

            await _keyValueStoreService.SetDataAsync(AgentOptionsKey, options);

            _options = options;

            var agentContext = await GetContextAsync();

            var provisioning = await _provisioningService.GetProvisioningAsync(agentContext.Wallet);

            // Check if connection has been established with mediator agent
            if (provisioning.GetTag("MediatorConnectionId") == null)
            {
                var(request, record) = await _connectionService.CreateRequestAsync(agentContext, discovery.Invitation);

                //await _edgeClientService.AddRouteAsync(agentContext, record.MyVk);
                var response = await _messageService.SendReceiveAsync <ConnectionResponseMessage>(agentContext.Wallet, request, record);

                await _connectionService.ProcessResponseAsync(agentContext, response, record);

                // Remove the routing key explicitly as it won't ever be needed.
                // Messages will always be sent directly with return routing enabled
                record = await _connectionService.GetAsync(agentContext, record.Id);

                record.Endpoint = new AgentEndpoint(record.Endpoint.Uri, null, null);
                await _recordService.UpdateAsync(agentContext.Wallet, record);

                provisioning.SetTag("MediatorConnectionId", record.Id);
                await _recordService.UpdateAsync(agentContext.Wallet, provisioning);
            }

            await _edgeClientService.CreateInboxAsync(agentContext);

            //await _edgeClientService.AddRouteAsync(agentContext, record.MyVk);

            return(true);
        }
        public async Task ProvisionAsync(AgentOptions options, CancellationToken cancellationToken = default)
        {
            var discovery = await edgeClientService.DiscoverConfigurationAsync(options.EndpointUri);

            try
            {
                options.AgentKey    = discovery.RoutingKey;
                options.EndpointUri = discovery.ServiceEndpoint;

                await provisioningService.ProvisionAgentAsync(options);
            }
            catch (WalletStorageException)
            {
                // OK
            }
            catch (WalletExistsException)
            {
                // OK
            }
            var agentContext = await agentProvider.GetContextAsync();

            var provisioning = await provisioningService.GetProvisioningAsync(agentContext.Wallet);

            // Check if connection has been established with mediator agent
            if (provisioning.GetTag(MediatorConnectionIdTagName) == null)
            {
                var(request, record) = await connectionService.CreateRequestAsync(agentContext, discovery.Invitation);

                var response = await messageService.SendReceiveAsync <ConnectionResponseMessage>(agentContext, request, record);

                await connectionService.ProcessResponseAsync(agentContext, response, record);

                // Remove the routing key explicitly as it won't ever be needed.
                // Messages will always be sent directly with return routing enabled
                record = await connectionService.GetAsync(agentContext, record.Id);

                record.Endpoint = new AgentEndpoint(record.Endpoint.Uri, null, null);
                await recordService.UpdateAsync(agentContext.Wallet, record);

                provisioning.SetTag(MediatorConnectionIdTagName, record.Id);
                await recordService.UpdateAsync(agentContext.Wallet, provisioning);
            }

            await edgeClientService.CreateInboxAsync(agentContext, options.MetaData);
        }