private Dictionary <string, ConfigEntry> GetConfigurationEntries() { var dictionary = new Dictionary <string, ConfigEntry>(); foreach (var configItem in ConfigCache.LatestConfig.Items.OrderBy(item => item.Key)) { var overrides = configItem.Overrides.Select(e => new ConfigEntry { Value = e.Value, File = e.FileName }).Skip(1).ToArray(); if (!overrides.Any()) { overrides = null; } var configItemInfo = configItem.Overrides.First(); dictionary.Add(configItem.Key, new ConfigEntry { Value = configItemInfo.Value, File = configItemInfo.FileName, Overridden = overrides, UsedAs = UsageTracking.Get(configItem.Key)?.FullName }); } return(dictionary); }
public ConfigObjectCreator(Type objectType, ConfigCache configCache, UsageTracking usageTracking, ILog log, Func <string, AggregatingHealthStatus> getAggregatedHealthCheck) { UsageTracking = usageTracking; Log = log; ObjectType = objectType; ConfigCache = configCache; ConfigPath = GetConfigPath(); healthStatus = getAggregatedHealthCheck("Configuration"); Validator = new DataAnnotationsValidator.DataAnnotationsValidator(); }
public ConfigurationResponseBuilder(ConfigCache configCache, IEnvironmentVariableProvider envs, IAssemblyProvider assemblyProvider, UsageTracking usageTracking) { UsageTracking = usageTracking; ConfigCache = configCache; Envs = envs; AssemblyProvider = assemblyProvider; }
public ConfigurationResponseBuilder(ConfigCache configCache, IEnvironment envs, IAssemblyProvider assemblyProvider, UsageTracking usageTracking, ServiceArguments serviceArguments, CurrentApplicationInfo appInfo) { UsageTracking = usageTracking; ServiceArguments = serviceArguments; AppInfo = appInfo; ConfigCache = configCache; Envs = envs; AssemblyProvider = assemblyProvider; }
public ConfigObjectCreator(Type objectType, ConfigCache configCache, UsageTracking usageTracking, ILog log, Func <string, AggregatingHealthStatus> getAggregatedHealthCheck) { UsageTracking = usageTracking; Log = log; ObjectType = objectType; ConfigCache = configCache; ConfigPath = GetConfigPath(); Validator = new DataAnnotationsValidator.DataAnnotationsValidator(); Create(); ConfigCache.ConfigChanged.LinkTo(new ActionBlock <ConfigItemsCollection>(c => Create())); InitializeBroadcast(); healthStatus = getAggregatedHealthCheck("Configuration"); healthStatus.RegisterCheck(ObjectType.Name, HealthCheck); }
public ConfigObjectCreator(Type objectType, ConfigCache configCache, UsageTracking usageTracking, ILog log, IHealthMonitor healthMonitor) { UsageTracking = usageTracking; Log = log; ObjectType = objectType; ConfigCache = configCache; ConfigPath = GetConfigPath(); Validator = new DataAnnotationsValidator.DataAnnotationsValidator(); Create(); ConfigCache.ConfigChanged.LinkTo(new ActionBlock <ConfigItemsCollection>(c => Create())); InitializeBroadcast(); healthMonitor.SetHealthFunction($"{ObjectType.Name} Configuration", HealthCheck); }
public void Reload() { var errors = new List <ValidationResult>(); JObject config = null; object updatedConfig = null; try { config = ConfigCache.CreateJsonConfig(ConfigPath) ?? Empty; if (JToken.DeepEquals(LatestNode, config)) { if (Latest != null) { ValidationErrors = null; } return; } } catch (Exception ex) { errors.Add(new ValidationResult("Failed to acquire config JObject: " + HealthMonitor.GetMessages(ex))); } if (config != null && errors.Any() == false) { LatestNode = config; try { updatedConfig = LatestNode.ToObject(ObjectType); } catch (JsonException ex) { errors.Add(new ValidationResult("Failed to deserialize config object: " + HealthMonitor.GetMessages(ex))); } if (updatedConfig != null) { Validator.TryValidateObjectRecursive(updatedConfig, errors); } } if (errors.Any() == false) { Latest = updatedConfig; ValidationErrors = null; UsageTracking.AddConfigObject(Latest, ConfigPath); Log.Info(_ => _("A config object has been updated", unencryptedTags: new { ConfigObjectType = ObjectType.FullName, ConfigObjectPath = ConfigPath })); SendChangeNotification?.Invoke(Latest); } else { ValidationErrors = string.Join(" \n", errors.Select(a => a.ErrorMessage)); Log.Error(_ => _("A config object has been updated but failed validation", unencryptedTags: new { ConfigObjectType = ObjectType.FullName, ConfigObjectPath = ConfigPath, ValidationErrors })); } }
public void Reload() { var errors = new List <ValidationResult>(); JObject config = null; object updatedConfig = null; try { config = ConfigCache.CreateJsonConfig(ConfigPath) ?? Empty; if (JToken.DeepEquals(LatestNode, config)) { if (Latest != null) { ValidationErrors = null; } return; } } catch (Exception ex) { errors.Add(new ValidationResult("Failed to acquire config JObject: " + HealthMonitor.GetMessages(ex))); } if (config != null && errors.Any() == false) { try { updatedConfig = config.ToObject(ObjectType); } catch (Exception ex) { // It is not only JsonException, as sometimes a custom deserializer capable to throw god knows what (including ProgrammaticException) errors.Add(new ValidationResult("Failed to deserialize config object: " + HealthMonitor.GetMessages(ex))); } if (updatedConfig != null) { Validator.TryValidateObjectRecursive(updatedConfig, errors); } } if (errors.Any() == false) { ValidationErrors = null; UsageTracking.AddConfigObject(Latest, ConfigPath); if (isCreated) { Log.Info(_ => _("A config object has been updated", unencryptedTags: new { ConfigObjectType = ObjectType.FullName, ConfigObjectPath = ConfigPath, OverallModifyTime = ConfigCache.LatestConfigFileModifyTime, }, encryptedTags: new { Changes = DiffJObjects(LatestNode, config, new StringBuilder(), new Stack <string>()).ToString(), })); } else//It mean we are first time not need to send update messsage { isCreated = true; } LatestNode = config; Latest = updatedConfig; SendChangeNotification?.Invoke(Latest); } else { ValidationErrors = string.Join(" \n", errors.Select(a => a.ErrorMessage)); Log.Error(_ => _("A config object has been updated but failed validation", unencryptedTags: new { ConfigObjectType = ObjectType.FullName, ConfigObjectPath = ConfigPath, ValidationErrors })); } }