/// <summary> /// Validates the options, if option is not set correctly, set to default and return the error /// </summary> /// <param name="optionKey"></param> /// <param name="restoreDataObject"></param> /// <returns></returns> public string ValidateOption(string optionKey, IRestoreDatabaseTaskDataObject restoreDataObject) { string errorMessage = string.Empty; if (optionBuilders.ContainsKey(optionKey)) { var builder = optionBuilders[optionKey]; var currentValue = builder.CurrentValueFunction(restoreDataObject); var defaultValue = builder.DefaultValueFunction(restoreDataObject); OptionValidationResult result = optionBuilders[optionKey].ValidateFunction(restoreDataObject, currentValue, defaultValue); if (result.IsReadOnly) { if (!ValueEqualsDefault(currentValue, defaultValue)) { builder.SetValueFunction(restoreDataObject, defaultValue); errorMessage = $"{optionKey} is ready only and cannot be modified"; } } if (!string.IsNullOrEmpty(result.ErrorMessage)) { errorMessage = result.ErrorMessage; builder.SetValueFunction(restoreDataObject, defaultValue); } } else { errorMessage = $"cannot find restore option builder for {optionKey}"; Logger.Write(LogLevel.Warning, errorMessage); } return(errorMessage); }
private RestorePlanDetailInfo Create( string optionKey, IRestoreDatabaseTaskDataObject restoreDataObject, OptionBuilder optionBuilder) { object currnetValue = optionBuilder.CurrentValueFunction(restoreDataObject); object defaultValue = optionBuilder.DefaultValueFunction(restoreDataObject); OptionValidationResult validationResult = optionBuilder.ValidateFunction(restoreDataObject, currnetValue, defaultValue); return(new RestorePlanDetailInfo { Name = optionKey, CurrentValue = currnetValue, DefaultValue = defaultValue, IsReadOnly = validationResult.IsReadOnly, IsVisiable = validationResult.IsVisible, ErrorMessage = validationResult.ErrorMessage }); }