/// <summary> /// Escalates the impact category based on the impact to a particular resource type. /// </summary> /// <param name="oldCategory">The current impact category.</param> /// <param name="resourceType">The resource type name.</param> /// <param name="impact">The impact to the given resource.</param> /// <returns>The new impact category.</returns> private ImpactCategory ApplyResourceImpact( ImpactCategory oldCategory, string resourceType, ResourceImpactEnum impact) { ImpactCategory newCategory = TranslateResourceImpactToCategory(resourceType, impact); newCategory = EscalateImpactCategory(oldCategory, newCategory); if (oldCategory != newCategory) { Tracer.WriteNoise( "Overall impact changed from {0} to {1} due to resource impact {2}={3}", oldCategory, newCategory, resourceType, impact); } return(newCategory); }
/// <summary> /// Reads the configuration value. /// </summary> /// <typeparam name="T">The type of the converted result.</typeparam> /// <param name="keyName">Name of the key.</param> /// <param name="defaultValue">The default value to be used if read was not successful.</param> /// <returns>The configuration value or the provided default value.</returns> public T ReadConfigValue <T>( string keyName, T defaultValue = default(T)) { keyName.Validate("keyName"); T result = defaultValue; string configValue = this.ConfigStore.ReadUnencryptedString(this.Name, keyName); if (string.IsNullOrEmpty(configValue)) { return(result); } Exception ex = null; try { if (typeof(T).GetTypeInfo().IsEnum) { result = (T)Enum.Parse(typeof(T), configValue, true); } else if (typeof(T) == typeof(TimeSpan)) { result = (T)(object)TimeSpan.Parse(configValue); } else { result = (T)Convert.ChangeType(configValue, typeof(T), CultureInfo.InvariantCulture); } } catch (ArgumentException e) { ex = e; } catch (InvalidCastException e) { ex = e; } catch (FormatException e) { ex = e; } catch (OverflowException e) { ex = e; } if (ex != null) { traceType.WriteWarning( "Error converting value '{0}' from config section/key name '{1}/{2}'. Returning default value: {3}. Error details: {4}", configValue, this.Name, keyName, result, ex); } else { traceType.WriteNoise( "Converted value '{0}' from config section/key name '{1}/{2}'. Returning converted value: {3}", configValue, this.Name, keyName, result); } return(result); }