/// <summary> /// Update the provided setting collection in the store /// </summary> /// <param name="settingsCollection">Updated collection object</param> /// <param name="validationResults">Out param List of errors/warnings</param> /// <returns>Operation result</returns> public OperationResult UdpateSettingsCollection(SettingsCollectionBase settingsCollection, out List <ValidationResult> validationResults) { OperationResult result; validationResults = new List <ValidationResult>(); var validationRes = settingsCollection.ValidateSettings(_settingsCollections); // If any validation errors, return with the list if (validationRes.Any(x => x.Result == ValidationResult.ResultType.Error)) { validationResults = validationRes.Where(x => x.Result == ValidationResult.ResultType.Error).ToList(); result = OperationResult.Failure; } else { // If any validation warnings if (validationRes.Any(x => x.Result == ValidationResult.ResultType.Warning)) { validationResults = validationRes.Where(x => x.Result == ValidationResult.ResultType.Warning).ToList(); result = OperationResult.Failure; } else { validationResults = validationRes; result = OperationResult.Success; } _storage.UpdateSettingCollectionValues(settingsCollection.GenerateDTO()); } return(result); }
public SettingsCollectionDTO GenerateDTO(SettingsCollectionBase settingsCollection) { var dto = new SettingsCollectionDTO(); var settingCollectionType = settingsCollection.GetType(); dto.TypeFullName = settingCollectionType.FullName; dto.AssemblyFullName = settingCollectionType.Assembly.FullName; dto.TypeAssemblyQualifiedName = settingCollectionType.AssemblyQualifiedName; // Translate properties var properties = GetType().GetProperties() .Where(p => typeof(SettingBase).IsAssignableFrom(p.PropertyType)); foreach (var prop in properties) { var set = (SettingBase)prop.GetValue(settingsCollection); var settingDto = new SettingDTO(); settingDto.Name = prop.Name; settingDto.ValueTypeFullName = set.ValueType.FullName; settingDto.ValueTypeAssemblyQualifiedName = set.ValueType.AssemblyQualifiedName; settingDto.ValueAssemblyFullName = set.ValueType.Assembly.FullName; settingDto.ValueTypeAssemblyQualifiedName = set.ValueType.AssemblyQualifiedName; settingDto.Value = set.Value; } return(dto); }
/// <summary> /// Add a new settings collection /// </summary> /// <param name="settingsCollection"></param> /// <remarks>Raises an invalid argument exception if the Collection is not direct sub class of SettingsCollectionBase</remarks> public void AddSettingsCollection(SettingsCollectionBase settingsCollection) { if (settingsCollection.GetType().BaseType != typeof(SettingsCollectionBase)) { throw new ArgumentException("The collection type must be directly derived from SettingsCollectionBase. Multi-level inheritance is not supported"); } lock (_settingsCollections) { _settingsCollections.Add(settingsCollection); } }
private List <ValidationResult> ValidateSettingValues(SettingsCollectionBase collection) { var res = collection.ValidateSettings(_settingsCollections); return(res); }