/// <summary> /// Sets the value of this parameter as seen by the Control_t that references it. /// </summary> /// <param name="hostParameter"><see cref="IParameter"/> that hosts the value.</param> /// <param name="value">Control value that implements <see cref="IParameterConvertible"/>.</param> /// <remarks>An <see cref="IParameterConvertible"/> is passed in enabling the control value to be converted into any /// desired type, provided that the value supports conversion to that type.</remarks> public ValidationResult SetValueFromControl(IParameter hostParameter, IParameterConvertible value) { if (ConstValue != null) { return(new ValidationResult(ValidationResult.ResultType.Invalid, string.Format(ErrorMessages.AttemptToSetConstValueParameter, ConstValue))); } try { _value = ConvertToNativeType(hostParameter, value); return(ValidateValue(_value, hostParameter.Use == Use_t.Required, hostParameter.EnumPairs)); } catch (InvalidFieldValueException ex) { _log.Error(m => m("Invalid value of type {0} for parameter {1}; exception text: {2}", hostParameter.Type, hostParameter.Name, ex.Message)); return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.DataConversionFailure, value, HumanReadableTypeName)); } catch (FormatException ex) { _log.Error(m => m("Unable to convert value '{0}' to type {1} for parameter {2}; exception text: {3}", value, hostParameter.Type, hostParameter.Name, ex.Message)); return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.DataConversionFailure, value, HumanReadableTypeName)); } catch (InvalidCastException ex) { _log.Error(m => m("Unable to convert value '{0}' to type {1} for parameter {2}; exception text: {3}", value, hostParameter.Type, hostParameter.Name, ex.Message)); return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.DataConversionFailure, value, HumanReadableTypeName)); } catch (ArgumentException ex) { _log.Error(m => m("Unable to convert value '{0}' to type {1} for parameter {2}; exception text: {3}", value, hostParameter.Type, hostParameter.Name, ex.Message)); return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.DataConversionFailure, value, HumanReadableTypeName)); } }
/// <summary> /// Sets the value of this parameter using the Control_t that references it. The resulting parameter value may be /// null if the control is not set to a value, or if it has explicitly been set via a state rule to {NULL}. /// </summary> /// <param name="control">Control to extract this parameter's new value from.</param> public ValidationResult SetValueFromControl(Control_t control) { IParameterConvertible value = control.GetValueForParameter(); try { ValidationResult result = _value.SetValueFromControl(this, value); // Update the text in the ValidationResult to include this parameter's name if (result.IsMissing) { return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied, Name)); } return(result); } catch (Atdl4netException ex) { throw ThrowHelper.Rethrow(this, ex, ErrorMessages.UnsuccessfulSetParameterOperation, Name, control.Id, ex.Message); } }
/// <summary> /// Converts the supplied value to the type parameter type (DateTime?) for this class. /// </summary> /// <param name="hostParameter"><see cref="IParameter"/> that hosts this value.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> /// <remarks>Used when setting a parameter value from a control (or anything else that /// implements <see cref="IParameterConvertible"/>).</remarks> protected override DateTime?ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { return(value.ToDateTime(hostParameter, CultureInfo.CurrentUICulture)); }
/// <summary> /// Converts the supplied value to the type parameter type (MonthYear?) for this class. /// </summary> /// <param name="hostParameter"><see cref="IParameter"/> that hosts this value.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> /// <remarks>Used when setting a parameter value from a control (or anything else that /// implements <see cref="IParameterConvertible"/>).</remarks> protected override MonthYear?ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { string monthYear = value.ToString(hostParameter); return(monthYear != null ? (MonthYear?)MonthYear.Parse(monthYear) : null); }
/// <summary> /// Converts the supplied value to the type parameter type (Tenor?) for this class. /// </summary> /// <param name="hostParameter"><see cref="IParameter"/> that hosts this value.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> /// <remarks>Used when setting a parameter value from a control (or anything else that /// implements <see cref="IParameterConvertible"/>).</remarks> protected override Tenor?ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { string tenor = value.ToString(hostParameter); return(tenor != null ? (Tenor?)Tenor.Parse(tenor) : null); }
/// <summary> /// Converts the supplied value to the type parameter type (T?) for this class. /// </summary> /// <param name="hostParameter"><see cref="IParameter"/> that hosts this value.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> /// <remarks>Used when setting a parameter value from a control (or anything else that /// implements <see cref="IParameterConvertible"/>).</remarks> protected abstract T?ConvertToNativeType(IParameter hostParameter, IParameterConvertible value);
/// <summary> /// Converts the supplied value to the type parameter type (T?) for this class. /// </summary> /// <param name="hostParameter">Parameter that this value belongs to.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> /// <remarks>Used when setting a parameter value from a control (or anything else that /// implements <see cref="IParameterConvertible"/>).</remarks> protected override IsoLanguageCode?ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { string wireValue = value.ToString(hostParameter); return(!string.IsNullOrEmpty(wireValue) ? ConvertFromWireValueFormat(wireValue) : null); }
/// <summary> /// Converts the supplied value to the type parameter type (int?) for this class. /// </summary> /// <param name="hostParameter"><see cref="IParameter"/> that hosts this value.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> /// <remarks>Used when setting a parameter value from a control (or anything else that /// implements <see cref="IParameterConvertible"/>).</remarks> protected override uint? ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { return value.ToUInt32(hostParameter, CultureInfo.CurrentUICulture); }
/// <summary> /// Converts the supplied value to the type parameter type (string) for this class. /// </summary> /// <param name="hostParameter"><see cref="IParameter"/> that hosts this value.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to string; null otherwise.</returns> protected override string ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { return(value.ToString(hostParameter)); }
/// <summary> /// Converts the supplied value to the type parameter type (T?) for this class. /// </summary> /// <param name="hostParameter">Parameter that this value belongs to.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> protected override char[] ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { string result = value != null?value.ToString(hostParameter) : null; return(result != null?result.ToCharArray() : null); }
/// <summary> /// Converts the supplied value to the type parameter type (T?) for this class. /// </summary> /// <param name="hostParameter">Parameter that this value belongs to.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> /// <remarks>Used when setting a parameter value from a control (or anything else that /// implements <see cref="IParameterConvertible"/>).<br/><br/> /// Unlike all other (non-enumerated) control/parameter relationships, Percentage_t does not have a /// one-to-one mapping with its associated control value as the control will typically contain a user-oriented /// format (e.g., 25) when the parameter must contain the true value (i.e., 0.25, assuming multiplyBy100 /// is not set to true).</remarks> protected override decimal?ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { decimal?convertedValue = value.ToDecimal(hostParameter, CultureInfo.CurrentUICulture); return((convertedValue != null) ? convertedValue /= 100 : null); }
/// <summary> /// Converts the supplied value to the type parameter type (T?) for this class. /// </summary> /// <param name="hostParameter"><see cref="IParameter"/> that hosts this value.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> /// <remarks>Used when setting a parameter value from a control (or anything else that /// implements <see cref="IParameterConvertible"/>).</remarks> protected override bool?ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { return(value.ToBoolean(hostParameter)); }
/// <summary> /// Converts the supplied value to the type parameter type (T?) for this class. /// </summary> /// <param name="hostParameter"><see cref="IParameter"/> that hosts this value.</param> /// <param name="value">Value to convert, may be null.</param> /// <returns>If input value is not null, returns value converted to T?; null otherwise.</returns> /// <remarks>Used when setting a parameter value from a control (or anything else that /// implements <see cref="IParameterConvertible"/>).</remarks> protected override char?ConvertToNativeType(IParameter hostParameter, IParameterConvertible value) { return(value.ToChar(hostParameter)); }