示例#1
0
        /// <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));
            }
        }
示例#2
0
        /// <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);
            }
        }
示例#3
0
 /// <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));
 }
示例#4
0
        /// <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);
        }
示例#5
0
        /// <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);
        }
示例#6
0
 /// <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);
示例#7
0
        /// <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);
 }
示例#9
0
 /// <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));
 }
示例#10
0
        /// <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);
        }
示例#11
0
        /// <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);
        }
示例#12
0
 /// <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));
 }
示例#13
0
 /// <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));
 }