コード例 #1
0
        /// <summary>
        /// Sets the value of this control using the value of the supplied parameter.
        /// </summary>
        /// <param name="parameter">Parameter to set this control's value from.</param>
        public override void SetValueFromParameter(IParameter parameter)
        {
            IControlConvertible value = parameter.GetValueForControl();

            _value = value.ToEnumState(parameter.EnumPairs);

            _log.Debug(m => m("List control {0} value is now {1}", Id, _value.ToString()));
        }
コード例 #2
0
        /// <summary>
        /// Loads this control with any supplied InitValue. If InitValue is not supplied, then control value will
        /// be set to default/empty value.
        /// </summary>
        protected override void LoadDefaultFromInitValue()
        {
            _value = new EnumState(ListItems.EnumIds);

            if (InitValue != null)
            {
                _value.LoadInitValue(InitValue, IsNonEnumValueAllowed);
            }
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of <see cref="EnumState"/> and copies the data from the supplied EnumState.
        /// </summary>
        /// <param name="sourceState">EnumState to copy the initial state from.</param>
        public EnumState(EnumState sourceState)
        {
            if (sourceState == null)
            {
                throw ThrowHelper.New <ArgumentException>(typeof(EnumState), "A valid EnumState value must be supplied to use this constuctor");
            }

            _enumIds      = sourceState._enumIds;
            _enumStates   = new BitArray(sourceState._enumStates);
            _nonEnumValue = sourceState._nonEnumValue;
        }
コード例 #4
0
        /// <summary>
        /// Attempts to load the supplied FIX field value into this control.
        /// </summary>
        /// <param name="value">Value to set this control to.</param>
        /// <returns>true if it was possible to set the value of this control using the supplied value; false otherwise.</returns>
        /// <remarks>Although the method name might suggest that value is a FIX wire value, for list controls, this
        /// parameter is in fact an enumID.</remarks>
        protected override bool LoadDefaultFromFixValue(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(false);
            }

            _value = new EnumState(ListItems.EnumIds);

            _value.LoadInitValue(value, IsNonEnumValueAllowed);

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Updates this EnumState with the state of the supplied EnumState.
        /// </summary>
        /// <param name="source">Source EnumState to update this instance from.</param>
        /// <remarks>Implementation note: there are probably more effective ways to copy data from one BitArray to another that the one taken, but
        /// the current implementation ensures that the two EnumStates reference a common set of EnumIDs.</remarks>
        public void UpdateFrom(EnumState source)
        {
            if (source == null)
            {
                throw ThrowHelper.New <ArgumentNullException>(this, "A valid EnumState must be supplied");
            }

            if (_enumIds.Length != source._enumIds.Length)
            {
                throw ThrowHelper.New <ArgumentException>(this, "Unable to update this EnumState from supplied EnumState as the number of EnumIDs was not consistent");
            }

            _log.Debug(m => m("Updating EnumState from {0} to {1}", this.ToString(), source.ToString()));

            int enumCount = _enumIds.Length;

            for (int n = 0; n < _enumIds.Length; n++)
            {
                for (int index = 0; index < source._enumIds.Length; index++)
                {
                    if (source._enumIds[index] == _enumIds[n])
                    {
                        _enumStates.Set(n, source._enumStates[index]);

                        enumCount--;

                        break;
                    }
                }
            }

            if (enumCount != 0)
            {
                throw ThrowHelper.New <ArgumentException>(this, "Mismatch between the EnumIDs of the source and target EnumState");
            }

            _nonEnumValue = source._nonEnumValue;
        }
コード例 #6
0
        /// <summary>
        /// Sets the value of this control using the value of the supplied parameter.
        /// </summary>
        /// <param name="parameter">Parameter to set this control's value from.</param>
        public override void SetValueFromParameter(IParameter parameter)
        {
            IControlConvertible value = parameter.GetValueForControl();

            // Special treatment needed here as we can't just assume that the source parameter has enumerated values, but if it
            // does, then we can't use ToBoolean as that won't map the wire values correctly to the state of this control.
            if (HasEnumeratedState)
            {
                if (parameter.HasEnumPairs)
                {
                    EnumState state = value.ToEnumState(parameter.EnumPairs);

                    if (state[CheckedEnumRef])
                    {
                        _value = true;
                    }
                    else if (state[UncheckedEnumRef])
                    {
                        _value = false;
                    }
                    else
                    {
                        _value = null;
                    }
                }
                else
                {
                    throw ThrowHelper.New <InconsistentStrategyException>(this, ErrorMessages.InconsistentEnumPairsListItemsError);
                }
            }
            else
            {
                _value = value.ToBoolean();
            }

            _log.Debug(m => m("Binary control {0} value is now {1}", _value));
        }
コード例 #7
0
        /// <summary>
        /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance
        /// precedes, follows, or occurs in the same position in the sort order as the other object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        /// <remarks>IComparable is implemented by EnumState to allow its use within Edit_t processing.  Although this interface is
        /// designed to provide less than/greater than comparison, it is primarily used here for determining equality.</remarks>
        public int CompareTo(object obj)
        {
            if (obj is string)
            {
                string enumId = (string)obj;

                if (!IsValidEnumId(enumId))
                {
                    throw ThrowHelper.New <InvalidFieldValueException>(this, ErrorMessages.UnrecognisedEnumIdValue, enumId);
                }

                return(this[enumId] ? 0 : -1);
            }
            else if (obj is EnumState)
            {
                EnumState enumState = (EnumState)obj;

                return(this.Equals(enumState) ? 0 : -1);
            }
            else
            {
                throw ThrowHelper.New <ArgumentException>(this, ErrorMessages.CompareValueFailure, this.ToString(), obj.GetType().FullName);
            }
        }
コード例 #8
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);
        }