internal ConfigEnvironment DoLoad(bool updateDictionary = true) { Exception error = null; // Get arrays of config server uris to check var uris = _settings.GetUris(); try { foreach (string label in GetLabels()) { Task <ConfigEnvironment> task = null; if (uris.Length > 1) { _logger?.LogInformation("Multiple Config Server Uris listed."); // Invoke config servers task = RemoteLoadAsync(uris, label); } else { // Single, server make Config Server URI from settings #pragma warning disable CS0618 // Type or member is obsolete var path = GetConfigServerUri(label); // Invoke config server task = RemoteLoadAsync(path); #pragma warning restore CS0618 // Type or member is obsolete } // Wait for results from server ConfigEnvironment env = task.GetAwaiter().GetResult(); // Update config Data dictionary with any results if (env != null) { _logger?.LogInformation( "Located environment: {name}, {profiles}, {label}, {version}, {state}", env.Name, env.Profiles, env.Label, env.Version, env.State); if (updateDictionary) { if (!string.IsNullOrEmpty(env.State)) { Data["spring:cloud:config:client:state"] = env.State; } if (!string.IsNullOrEmpty(env.Version)) { Data["spring:cloud:config:client:version"] = env.Version; } var sources = env.PropertySources; if (sources != null) { int index = sources.Count - 1; for (; index >= 0; index--) { AddPropertySource(sources[index]); } } } return(env); } } } catch (Exception e) { error = e; } _logger?.LogWarning("Could not locate PropertySource: " + error?.ToString()); if (_settings.FailFast) { throw new ConfigServerException("Could not locate PropertySource, fail fast property is set, failing", error); } return(null); }
internal ConfigEnvironment DoLoad(bool updateDictionary = true) { Exception error = null; // Get arrays of config server uris to check var uris = _settings.GetUris(); try { foreach (var label in GetLabels()) { Task <ConfigEnvironment> task = null; if (uris.Length > 1) { _logger?.LogInformation("Multiple Config Server Uris listed."); // Invoke config servers task = RemoteLoadAsync(uris, label); } else { // Single, server make Config Server URI from settings #pragma warning disable CS0618 // Type or member is obsolete var path = GetConfigServerUri(label); // Invoke config server task = RemoteLoadAsync(path); #pragma warning restore CS0618 // Type or member is obsolete } // Wait for results from server var env = task.GetAwaiter().GetResult(); // Update config Data dictionary with any results if (env != null) { _logger?.LogInformation( "Located environment: {name}, {profiles}, {label}, {version}, {state}", env.Name, env.Profiles, env.Label, env.Version, env.State); if (updateDictionary) { var data = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (!string.IsNullOrEmpty(env.State)) { data["spring:cloud:config:client:state"] = env.State; } if (!string.IsNullOrEmpty(env.Version)) { data["spring:cloud:config:client:version"] = env.Version; } var sources = env.PropertySources; if (sources != null) { var index = sources.Count - 1; for (; index >= 0; index--) { AddPropertySource(sources[index], data); } } // Adds client settings (e.g spring:cloud:config:uri, etc) back to the (new) Data dictionary AddConfigServerClientSettings(data);