/// <summary>
 /// Converts the value of this instance to an equivalent EnumState value.
 /// </summary>
 /// <returns>A valid EnumState, assuming the source value can be correctly converted.</returns>
 public EnumState ToEnumState(EnumPairCollection enumPairs)
 {
     if (_value == null)
         return new EnumState(enumPairs.EnumIds);
     else
         return EnumState.FromWireValue(enumPairs, ToString(CultureInfo.InvariantCulture));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Converts the value of this instance to an equivalent EnumState value.
 /// </summary>
 /// <returns>A valid EnumState, assuming the source value can be correctly converted.</returns>
 public EnumState ToEnumState(EnumPairCollection enumPairs)
 {
     if (_value == null)
     {
         return(new EnumState(enumPairs.EnumIds));
     }
     else
     {
         return(EnumState.FromWireValue(enumPairs, ToString(null)));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts the value of this instance to an equivalent EnumState value.
        /// </summary>
        /// <returns>A valid EnumState, assuming the source value can be correctly converted.</returns>
        /// <remarks>This method converts the enum value to a string, looks up the EnumID from the supplied
        /// EnumPairCollection and then returns a new EnumState.  This method may be a little slow for
        /// very large enumerations.</remarks>
        public EnumState ToEnumState(EnumPairCollection enumPairs)
        {
            EnumState state = new EnumState(enumPairs.EnumIds);

            string enumId;
            string wireValue = ToString(null);

            if (enumPairs.TryParseWireValue(wireValue, out enumId))
            {
                state[enumId] = true;
            }

            return(state);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts the value of this instance to an equivalent string value using the specified culture-specific formatting information.
        /// </summary>
        /// <param name="targetParameter">Target parameter for this conversion.</param>
        /// <returns>A string value equivalent to the value of this instance.  May be null.</returns>
        public override string ToString(IParameter targetParameter)
        {
            if (_value != null && HasEnumeratedState)
            {
                EnumPairCollection enumPairs = targetParameter.EnumPairs;

                string value = (bool)_value ? enumPairs.GetWireValueFromEnumId(CheckedEnumRef) : enumPairs.GetWireValueFromEnumId(UncheckedEnumRef);

                // It is possible for '{NULL}' to be provided as one of the enum wire values, so we have to act accordingly
                return(value != Atdl.NullValue ? value : null);
            }
            else
            {
                return(_value != null?_value.ToString().ToLower() : null);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Provides the state of this EnumState in a format ready to be sent over FIX, e.g., "A B C E".
        /// </summary>
        /// <param name="enumPairs">The EnumPairs for this parameter, to provide the mapping from EnumID values.</param>
        /// <returns>A space-separated string containing zero or more EnumPair WireValues.  If no EnumIDs are enabled,
        /// then null is returned.</returns>
        public string ToWireValue(EnumPairCollection enumPairs)
        {
            _log.Debug(m => m("Converting EnumState to WireValue; current state is {0}", ToString()));

            if (enumPairs.Count != _enumStates.Count)
            {
                throw ThrowHelper.New <InvalidOperationException>(ExceptionContext, ErrorMessages.InconsistentEnumPairsListItemsError);
            }

            // Override the values in the states collection if a non-enum value is supplied.  This is used to handle
            // the unique case of the EditableDropDownList_t control.
            if (NonEnumValue != null)
            {
                return(NonEnumValue.Length > 0 ? NonEnumValue : null);
            }

            bool          hasAtLeastOneValue = false;
            StringBuilder sb = new StringBuilder();

            for (int n = 0; n < _enumStates.Length; n++)
            {
                if (_enumStates[n])
                {
                    string value = enumPairs.GetWireValueFromEnumId(_enumIds[n]);

                    // Typically {NULL} will only be used in a mutually exclusive fashion, although nothing enforces this
                    if (value != Atdl.NullValue)
                    {
                        // Only prepend a space after the first entry
                        if (hasAtLeastOneValue)
                        {
                            sb.AppendFormat(" {0}", value);
                        }
                        else
                        {
                            sb.Append(value);

                            hasAtLeastOneValue = true;
                        }
                    }
                }
            }

            _log.Debug(m => m("EnumState as WireValue is {0}", sb.ToString()));

            return(hasAtLeastOneValue ? sb.ToString() : null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new EnumState from the supplied set of EnumPairs and input FIX string.
        /// </summary>
        /// <param name="enumPairs">EnumPairs for this parameter.</param>
        /// <param name="multiValueString">String containing one or more FIX wire values (space-separated).</param>
        /// <returns></returns>
        public static EnumState FromWireValue(EnumPairCollection enumPairs, string multiValueString)
        {
            _log.DebugFormat("Converting WireValue '{0}' to EnumState", multiValueString);

            string[] inputValues = multiValueString.Split(new char[] { ';', ' ', ',' });

            EnumState result = new EnumState(enumPairs.EnumIds);

            foreach (string inputValue in inputValues)
            {
                string enumId;

                if (!enumPairs.TryParseWireValue(inputValue, out enumId))
                {
                    throw ThrowHelper.New <ArgumentException>(ExceptionContext, ErrorMessages.UnrecognisedEnumIdValue, inputValue);
                }

                result[enumId] = true;
            }

            _log.Debug(m => m("Converting EnumState from WireValue; state is {0}", result.ToString()));

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Validates the supplied value in terms of the parameters constraints (e.g., MinValue, MaxValue, etc.).
        /// </summary>
        /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
        /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
        /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
        /// <returns>ValidationResult indicating whether the supplied value is valid.</returns>
        /// <remarks>DateTime.MaxValue (a date and time at the end of the year 9999) is used to indicate an invalid date or time.</remarks>
        protected override ValidationResult ValidateValue(DateTime?value, bool isRequired, EnumPairCollection enumPairs)
        {
            if (value != null)
            {
                if (value == DateTime.MaxValue)
                {
                    return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.InvalidDateOrTimeValueUnknown));
                }

                if (MaxValue != null && (DateTime)value > MaxValue)
                {
                    var constraintText = string.Format(ErrorMessages.ConstraintMaxValueExceeded, MaxValueString());
                    return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText, ErrorMessages.MaxValueExceeded,
                                                value, MaxValue));
                }

                if (MinValue != null && (DateTime)value < MinValue)
                {
                    var constraintText = string.Format(ErrorMessages.ConstraintMinValueExceeded, MinValueString());
                    return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText, ErrorMessages.MinValueExceeded,
                                                value, MinValue));
                }
            }
            else if (isRequired)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            return(ValidationResult.ValidResult);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Validates the supplied value in terms of the parameters constraints (e.g., MinValue, MaxValue, etc.).
        /// </summary>
        /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
        /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
        /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
        /// <returns>ValidationResult indicating whether the supplied value is valid.</returns>
        protected override ValidationResult ValidateValue(MonthYear?value, bool isRequired, EnumPairCollection enumPairs)
        {
            if (MaxValue != null && !(value >= MaxValue))
            {
                return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.MaxValueExceeded, value.ToString(), MaxValue));
            }

            if (MinValue != null && !(value <= MinValue))
            {
                return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.MinValueExceeded, value.ToString(), MinValue));
            }

            if (isRequired && value == null)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            return(ValidationResult.ValidResult);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Converts the value of this instance to an equivalent EnumState value.
 /// </summary>
 /// <returns>A valid EnumState, assuming the source value can be correctly converted.</returns>
 /// <remarks>This method converts the enum value to a string, looks up the EnumID from the supplied
 /// EnumPairCollection and then returns a new EnumState.  This method may be a little slow for
 /// very large enumerations.</remarks>
 public EnumState ToEnumState(EnumPairCollection enumPairs)
 {
     throw ThrowHelper.New <InvalidCastException>(this, ErrorMessages.UnsupportedParameterValueConversion, _value, "Enumerated Type");
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Validates the supplied value in terms of 'ISO 10383 correctness', i.e., MICs must be 4 characters in length.
        /// </summary>
        /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
        /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
        /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
        /// <returns>ValidationResult indicating whether the supplied value is valid.</returns>
        protected override ValidationResult ValidateValue(string value, bool isRequired, EnumPairCollection enumPairs)
        {
            if (value != null && value.Length != 4)
            {
                return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.InvalidExchangeCode));
            }

            if (isRequired && value == null)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            return(ValidationResult.ValidResult);
        }
        /// <summary>
        /// Validates the supplied value in terms of the parameters constraints (e.g., MinValue, MaxValue, etc.).
        /// </summary>
        /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
        /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
        /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
        /// <returns>ValidationResult indicating whether the supplied value is valid.</returns>
        protected override ValidationResult ValidateValue(uint?value, bool isRequired, EnumPairCollection enumPairs)
        {
            if (value != null && (uint)value < 1)
            {
                return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.NonZeroPositiveIntRequired, value));
            }

            if (isRequired && value == null)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            return(ValidationResult.ValidResult);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Validates the supplied value in terms of the parameters constraints.  This method does nothing because
        /// is not possible for an IsoLanguageCode value to be invalid.
        /// </summary>
        /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
        /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
        /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
        /// <returns>ValidationResult indicating whether the supplied value is valid.</returns>
        protected override ValidationResult ValidateValue(IsoLanguageCode?value, bool isRequired, EnumPairCollection enumPairs)
        {
            if (isRequired && value == null)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            return(ValidationResult.ValidResult);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Validates the supplied value in terms of the parameters constraints (e.g., MinValue, MaxValue, etc.).
 /// </summary>
 /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
 /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
 /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
 /// <returns>Value passed in is returned if it is valid; otherwise an appropriate exception is thrown.</returns>
 protected abstract ValidationResult ValidateValue(T?value, bool isRequired, EnumPairCollection enumPairs);
Ejemplo n.º 14
0
        /// <summary>
        /// Validates the supplied value in terms of the parameters constraints (e.g., MinValue, MaxValue, etc.).
        /// </summary>
        /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
        /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
        /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
        /// <returns>ValidationResult indicating whether the supplied value is valid.</returns>
        protected override ValidationResult ValidateValue(decimal?value, bool isRequired, EnumPairCollection enumPairs)
        {
            if (value != null)
            {
                int adjustmentFactor = (MultiplyBy100 == true) ? 1 : 100;

                var adjustedValue = 0 <= value && value <= 1 ? value * 100 : value; // used until we display on ui multiplied by 100
                var maxValue      = MaxValue * 100;                                 // used until we display on ui multiplied by 100
                var minValue      = MinValue * 100;                                 // used until we display on ui multiplied by 100

                if (maxValue != null && adjustedValue > maxValue)
                {
                    var constraintText = string.Format(ErrorMessages.ConstraintMaxValueExceeded, maxValue);
                    return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText, ErrorMessages.MaxValueExceeded, RemoveTrailingZeroes(adjustedValue * adjustmentFactor), RemoveTrailingZeroes(maxValue * adjustmentFactor))
                    {
                        DisplayValue = adjustedValue.ToString()
                    });
                }
                if (minValue != null && adjustedValue < minValue)
                {
                    var constraintText = string.Format(ErrorMessages.ConstraintMinValueExceeded, minValue);
                    return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText, ErrorMessages.MinValueExceeded, RemoveTrailingZeroes(adjustedValue * adjustmentFactor), RemoveTrailingZeroes(minValue * adjustmentFactor))
                    {
                        DisplayValue = adjustedValue.ToString()
                    });
                }
            }
            else if (isRequired)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            return(ValidationResult.ValidResult);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Validates the supplied value in terms of the parameters constraints.  This method does nothing because
        /// is not possible for a char value to be invalid.
        /// </summary>
        /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
        /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
        /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
        /// <returns>ValidationResult indicating whether the supplied value is valid.</returns>
        protected override ValidationResult ValidateValue(char?value, bool isRequired, EnumPairCollection enumPairs)
        {
            if (isRequired && value == null)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            if (value != null &&
                enumPairs.HasValues &&
                !enumPairs.TryParseWireValue(value.ToString(), out _))
            {
                var constraintText = string.Format(ErrorMessages.UnrecognisedEnumIdValue, value);
                return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText,
                                            ErrorMessages.InvalidControlValueError));
            }

            return(ValidationResult.ValidResult);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Validates the supplied value in terms of the parameters constraints.
        /// </summary>
        /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
        /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
        /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
        /// <returns>ValidationResult indicating whether the supplied value is valid.</returns>
        protected override ValidationResult ValidateValue(string value, bool isRequired, EnumPairCollection enumPairs)
        {
            if (!string.IsNullOrEmpty(value))
            {
                if (MaxLength != null && value.Length > MaxLength)
                {
                    var constraintText = string.Format(ErrorMessages.ConstraintMaxLengthExceeded, MaxLength);
                    return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText, ErrorMessages.MaxLengthExceeded,
                                                value, MaxLength));
                }

                if (MinLength != null && value.Length < MinLength)
                {
                    var constraintText = string.Format(ErrorMessages.ConstraintMinLengthExceeded, MinLength);
                    return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText, ErrorMessages.MinLengthExceeded,
                                                value, MinLength));
                }
            }
            else if (isRequired)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            if (value != null &&
                enumPairs.HasValues &&
                !enumPairs.TryParseWireValue(value, out _))
            {
                var constraintText = string.Format(ErrorMessages.UnrecognisedEnumIdValue, value);
                return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText,
                                            ErrorMessages.InvalidControlValueError));
            }

            return(ValidationResult.ValidResult);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Validates the supplied value in terms of the parameters constraints.
        /// </summary>
        /// <param name="value">Value to validate, may be null in which case no validation is applied.</param>
        /// <param name="isRequired">Set to true to check that this parameter is non-null.</param>
        /// <param name="enumPairs">We need to check that the value is found inside this collection</param>
        /// <returns>ValidationResult indicating whether the supplied value is valid.</returns>
        protected override ValidationResult ValidateValue(char[] value, bool isRequired, EnumPairCollection enumPairs)
        {
            if (MaxLength != null && value != null && value.Length > MaxLength)
            {
                var constraintText = string.Format(ErrorMessages.ConstraintMaxLengthExceeded, MaxLength);
                return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText, ErrorMessages.MaxLengthExceeded, value, MaxLength));
            }
            if (MinLength != null && value != null && value.Length < MinLength)
            {
                var constraintText = string.Format(ErrorMessages.ConstraintMinLengthExceeded, MinLength);
                return(new ValidationResult(ValidationResult.ResultType.InvalidConstraint, constraintText, ErrorMessages.MinLengthExceeded, value,
                                            MinLength));
            }
            if (isRequired && value == null)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            return(ValidationResult.ValidResult);
        }
Ejemplo n.º 18
0
        protected override ValidationResult ValidateValue(DateTime?value, bool isRequired, EnumPairCollection enumPairs)
        {
            //AMS-231 min/max value validation no longer required
            if (value != null)
            {
                if (value == DateTime.MaxValue)
                {
                    return(new ValidationResult(ValidationResult.ResultType.Invalid, ErrorMessages.InvalidDateOrTimeValueUnknown));
                }
            }
            else if (isRequired)
            {
                return(new ValidationResult(ValidationResult.ResultType.Missing, ErrorMessages.NonOptionalParameterNotSupplied2));
            }

            return(ValidationResult.ValidResult);
        }