Example #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 immediately
                    errors.Add(ex);
                }
            }

            await Task.WhenAll(saveTasks);

            if (errors.Count > 0)
            {
                throw new AggregateException("Failed to save cert to repositories", errors);
            }
        }
Example #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);
                }
            }
        }