Beispiel #1
0
        private async Task SaveCertificateAsync(X509Certificate2 cert, CancellationToken cancellationToken)
        {
            _selector.Add(cert);

            var saveTasks = new List <Task>
            {
                Task.Delay(TimeSpan.FromMinutes(5), cancellationToken)
            };

            var errors = new List <Exception>();

            foreach (var repo in _certificateRepositories)
            {
                try
                {
                    saveTasks.Add(repo.SaveAsync(cert, cancellationToken));
                }
                catch (Exception ex)
                {
                    // synchronous saves may fail immediatedly
                    errors.Add(ex);
                    continue;
                }
            }

            await Task.WhenAll(saveTasks);

            if (errors.Count > 0)
            {
                throw new AggregateException("Failed to save cert to repositories", errors);
            }
        }
Beispiel #2
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            foreach (var certSource in _certSources)
            {
                var certs = await certSource.GetCertificatesAsync(cancellationToken);

                foreach (var cert in certs)
                {
                    _selector.Add(cert);
                }
            }
        }
Beispiel #3
0
        private async Task SaveCertificateAsync(X509Certificate2 cert, CancellationToken cancellationToken)
        {
            _selector.Add(cert);

            var saveTasks = new List <Task>
            {
                Task.Delay(TimeSpan.FromMinutes(5), cancellationToken)
            };

            foreach (var repo in _certificateRepositories)
            {
                saveTasks.Add(repo.SaveAsync(cert, cancellationToken));
            }

            await Task.WhenAll(saveTasks);
        }
        private async Task LoadCerts(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var factory = new CertificateFactory(_options, _challengeStore, _logger, _hostEnvironment);

            var cert = await GetOrCreateCertificate(factory, cancellationToken);

            _selector.Add(cert);

            var saveTasks = new List <Task>
            {
                Task.Delay(TimeSpan.FromMinutes(5), cancellationToken)
            };

            foreach (var repo in _certificateRepositories)
            {
                saveTasks.Add(repo.SaveAsync(cert, cancellationToken));
            }

            await Task.WhenAll(saveTasks);
        }