Ejemplo n.º 1
0
        public async Task <IDictionary <string, Backend> > GetBackendsAsync(IConfigErrorReporter errorReporter, CancellationToken cancellation)
        {
            var backends = await _backendsRepo.GetBackendsAsync(cancellation) ?? new Dictionary <string, Backend>(StringComparer.Ordinal);

            var configuredBackends = new Dictionary <string, Backend>(StringComparer.Ordinal);

            // The IBackendsRepo provides a fresh snapshot that we need to reconfigure each time.
            foreach (var(id, backend) in backends)
            {
                try
                {
                    if (id != backend.Id)
                    {
                        errorReporter.ReportError(ConfigErrors.ConfigBuilderBackendIdMismatch, id,
                                                  $"The backend Id '{backend.Id}' and its lookup key '{id}' do not match.");
                        continue;
                    }

                    foreach (var filter in _filters)
                    {
                        await filter.ConfigureBackendAsync(backend, cancellation);
                    }

                    ValidateSessionAffinity(errorReporter, id, backend);

                    configuredBackends[id] = backend;
                }
                catch (Exception ex)
                {
                    errorReporter.ReportError(ConfigErrors.ConfigBuilderBackendException, id, "An exception was thrown from the configuration callbacks.", ex);
                }
            }

            return(configuredBackends);
        }
Ejemplo n.º 2
0
        public async Task <IDictionary <string, Backend> > GetBackendsAsync(IConfigErrorReporter errorReporter, CancellationToken cancellation)
        {
            var backends = await _backendsRepo.GetBackendsAsync(cancellation) ?? new Dictionary <string, Backend>(StringComparer.Ordinal);

            var configuredBackends = new Dictionary <string, Backend>(StringComparer.Ordinal);

            // The IBackendsRepo provides a fresh snapshot that we need to reconfigure each time.
            foreach (var(id, backend) in backends)
            {
                try
                {
                    foreach (var filter in _filters)
                    {
                        await filter.ConfigureBackendAsync(id, backend, cancellation);
                    }

                    configuredBackends[id] = backend;
                }
                catch (Exception ex)
                {
                    errorReporter.ReportError(ConfigErrors.ConfigBuilderBackendException, id, "An exception was thrown from the configuration callbacks.", ex);
                }
            }

            return(configuredBackends);
        }
Ejemplo n.º 3
0
        public async Task <Result <DynamicConfigRoot> > BuildConfigAsync(IConfigErrorReporter errorReporter, CancellationToken cancellation)
        {
            Contracts.CheckValue(errorReporter, nameof(errorReporter));

            var backends = await _backendsRepo.GetBackendsAsync(cancellation) ?? new Dictionary <string, Backend>(StringComparer.Ordinal);

            var routes = await GetRoutesAsync(errorReporter, cancellation);

            var config = new DynamicConfigRoot
            {
                Backends = backends,
                Routes   = routes,
            };

            return(Result.Success(config));
        }