示例#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);
        }
示例#2
0
        public async Task <bool> CreateAgentAsync(AgentOptions options)
        {
#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 ProvisioningConfiguration
            {
                WalletConfiguration = options.WalletOptions.WalletConfiguration,
                WalletCredentials   = options.WalletOptions.WalletCredentials,
                AgentSeed           = options.Seed,
                EndpointUri         = options.EndpointUri != null ? new Uri($"{options.EndpointUri}") : null
            });

            await _keyValueStoreService.SetDataAsync(AgentOptionsKey, options);

            _options = options;

            return(true);
        }