Beispiel #1
0
        /// <summary>
        /// Evaluate all the <see cref="StrategyEdit_t">StrategyEdit</see>s for this strategy.
        /// </summary>
        /// <param name="inputValueProvider">Provider that providers access to any additional FIX field values that may
        /// be required in the Edit evaluation.</param>
        /// <param name="shortCircuit">If true, this method returns as soon as any error is found; if false, all StrategyEdits
        /// are evaluated before the method returns.</param>
        public bool EvaluateAllStrategyEdits(IInitialFixValueProvider inputValueProvider, bool shortCircuit)
        {
            FixFieldValueProvider additionalValues = inputValueProvider == null ?
                                                     FixFieldValueProvider.Empty : new FixFieldValueProvider(inputValueProvider, Parameters);

            return(_strategyEdits.EvaluateAll(additionalValues, shortCircuit));
        }
        private void OnInputFixValuesChanged()
        {
            if (Strategy == null)
            {
                return;
            }

            try
            {
                _inputValuesSet = true;

                FixFieldValueProvider fieldValueProvider = new FixFieldValueProvider(this, Strategy.Parameters);

                // First initialize all the control values from their initValue or initFixField...
                Strategy.LoadInitialControlValues(fieldValueProvider);

                // ... then load all the parameter values from the supplied FIX fields...
                Strategy.LoadParameterValues(fieldValueProvider, true);

                // ... then refresh the values of the controls from their parameters...
                Strategy.UpdateControlValuesFromParameters(fieldValueProvider);

                // ... and finally update all the state rules
                Strategy.RunAllStateRules();

                if (ViewModel != null)
                {
                    ViewModel.RefreshViewState();
                }
            }
            catch (Exception ex)
            {
                NotifyExceptionOccurred(ex);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Evaluates this instance based on current field values and any additional FIX field values that this
        /// EditEvaluatingCollection references.
        /// </summary>
        /// <param name="additionalValues">Any additional FIX field values that may be required in the Edit evaluation.</param>
        public void Evaluate(FixFieldValueProvider additionalValues)
        {
            _log.Debug(m => m("Evaluating EditEvaluatingCollection with {0} elements; current state = {1}", this.Count, _currentState.ToString().ToLower()));

            if (LogicOperator == null)
            {
                throw ThrowHelper.New <InvalidOperationException>(this, ErrorMessages.MissingLogicalOperatorOnSetOfEdits);
            }

            bool shortCircuit = false;
            bool newState     = (LogicOperator == LogicOperator_t.And) ? true : false;
            int  xorCount     = 0;

            foreach (IEdit <T> item in this.Items)
            {
                if (shortCircuit)
                {
                    break;
                }

                item.Evaluate(additionalValues);

                switch (LogicOperator)
                {
                case LogicOperator_t.And:
                    newState &= item.CurrentState;
                    if (!newState)
                    {
                        shortCircuit = true;
                    }
                    break;

                case LogicOperator_t.Or:
                    newState |= item.CurrentState;
                    if (newState)
                    {
                        shortCircuit = true;
                    }
                    break;

                case LogicOperator_t.Not:
                    newState = !item.CurrentState;
                    break;

                // From the spec: "As a convention we define XOR as 'one and only one', which means it evaluates to true when one
                // and only one of its operands is true. If none or more than one of its operands is true then XOR is false."
                case LogicOperator_t.Xor:
                    if (item.CurrentState)
                    {
                        xorCount++;
                    }
                    newState = xorCount == 1;
                    break;
                }

                _log.Debug(m => m("EditEvaluatingCollection state is now {0}", newState.ToString().ToLower()));
            }

            _currentState = newState;
        }
        /// <summary>
        /// Evaluates all strategy edits within the currently selected strategy.
        /// </summary>
        /// <param name="inputValueProvider">Provider that providers access to any additional FIX field values that may
        /// be required in the Edit evaluation.</param>
        /// <returns>Summary state of all StrategyEdits after the evaluation.</returns>
        public bool EvaluateAllStrategyEdits(IInitialFixValueProvider inputValueProvider)
        {
            FixFieldValueProvider additionalValues = inputValueProvider == null ?
                                                     FixFieldValueProvider.Empty : new FixFieldValueProvider(inputValueProvider, _underlyingStrategy.Parameters);

            return(StrategyEdits.EvaluateAll(additionalValues));
        }
        /// <summary>
        /// Evaluates all the underlying <see cref="StrategyEdit_t"/>s and notifies any interested parties of change
        /// of state.
        /// </summary>
        /// <param name="inputValueProvider">Provider that providers access to any additional FIX field values that may
        /// be required in the Edit evaluation.</param>
        /// <returns>Summary state of all StrategyEdits after the evaluation.</returns>
        public bool EvaluateAll(FixFieldValueProvider inputValueProvider)
        {
            bool overallState = true;

            foreach (StrategyEditViewModel strategyEdit in this)
            {
                overallState &= strategyEdit.Evaluate(inputValueProvider);
            }

            return(overallState);
        }
        /// <summary>
        /// Evaluates all strategy edits within the currently selected strategy.
        /// </summary>
        /// <param name="inputValueProvider">Provider that providers access to any additional FIX field values that may
        /// be required in the Edit evaluation.</param>
        /// <returns>Summary state of all StrategyEdits after the evaluation.</returns>
        public bool EvaluateAffectedStrategyEdits(IInitialFixValueProvider inputValueProvider, FixField updatedField)
        {
            FixFieldValueProvider additionalValues = inputValueProvider == null ?
                                                     FixFieldValueProvider.Empty : new FixFieldValueProvider(inputValueProvider, _underlyingStrategy.Parameters);

            bool result = StrategyEdits.EvaluateAffected(additionalValues, updatedField);

            foreach (ControlViewModel control in Controls)
            {
                control.OnValueChangeCompleted();
            }

            return(result);
        }
        /// <summary>
        /// Evaluates all the underlying <see cref="StrategyEdit_t"/>s and notifies any interested parties of change
        /// of state.
        /// </summary>
        /// <param name="inputValueProvider">Provider that providers access to any additional FIX field values that may
        /// be required in the Edit evaluation.</param>
        /// <returns>Summary state of all StrategyEdits after the evaluation.</returns>
        public bool EvaluateAffected(FixFieldValueProvider inputValueProvider, FixField fixField)
        {
            bool overallState = true;

            foreach (StrategyEditViewModel strategyEdit in this)
            {
                if (strategyEdit.Sources.Contains(Enum.GetName(typeof(FixField), fixField)))
                {
                    overallState &= strategyEdit.Evaluate(inputValueProvider);
                }
            }

            return(overallState);
        }
        /// <summary>
        /// Evaluates the underlying <see cref="StrategyEdit_t"/> and notifies any interested parties of change
        /// of state.
        /// </summary>
        /// <returns>State of this StrategyEdit after the evaluation.</returns>
        /// <param name="additionalValues">Any additional FIX field values that may be required in the Edit evaluation.</param>
        public bool Evaluate(FixFieldValueProvider additionalValues)
        {
            bool oldState = _underlyingStrategyEdit.CurrentState;

            _underlyingStrategyEdit.Evaluate(additionalValues);

            bool newState = _underlyingStrategyEdit.CurrentState;

            if (oldState != newState)
            {
                NotifyStateChanged(oldState, newState);
            }

            return(newState);
        }
        /// <summary>
        /// Loads the initial values for each control based on the InitPolicy, InitFixField and InitValue attributes.
        /// </summary>
        /// <param name="controlInitValueProvider">Value provider for initializing control values from InitFixField.</param>
        /// <remarks>The spec states: 'If the value of the initPolicy attribute is undefined or equal to "UseValue" and the initValue attribute is
        /// defined then initialize with initValue.  If the value is equal to "UseFixField" then attempt to initialize with the value of
        /// the tag specified in the initFixField attribute. If the value is equal to "UseFixField" and it is not possible to access the
        /// value of the specified fix tag then revert to using initValue. If the value is equal to "UseFixField", the field is not accessible,
        /// and initValue is not defined, then do not initialize.</remarks>
        public void LoadDefaults(FixFieldValueProvider controlInitValueProvider)
        {
            Control_t control = null;

            try
            {
                foreach (Control_t thisControl in this)
                {
                    control = thisControl;

                    thisControl.LoadInitValue(controlInitValueProvider);
                }
            }
            catch (System.Exception ex)
            {
                throw ThrowHelper.Rethrow(this, ex, ErrorMessages.InitControlValueError, control != null ? control.Id : "(unknown)");
            }
        }
        /// <summary>
        /// Evaluates all the <see cref="StrategyEdit_t"/>s for this control.
        /// </summary>
        /// <param name="additionalValues">Any additional FIX field values that may be required in the Edit evaluation.</param>
        /// <remarks>See <see cref="CurrentState"/> for an explanation of why we don't cache the state locally within the class.</remarks>
        public void Evaluate(FixFieldValueProvider additionalValues)
        {
            _log.Debug(m => m("Evaluating ValidationState for control {0}, CurrentState = {1}", _controlId, CurrentState.ToString().ToLower()));

            bool state = (_controlValidationResult == null || _controlValidationResult.IsValid);

            // Evaluating the StrategyEdits may give us meaningless information if the parameter value
            // didn't validate, but we go ahead and do it anyway because failing to do leaves us in an
            // indeterminate state from this value change.
            state &= (_parameterValidationResult == null || _parameterValidationResult.IsValid);

            foreach (StrategyEditViewModel strategyEdit in _strategyEdits)
            {
                state &= strategyEdit.Evaluate(additionalValues);
            }

            _log.Debug(m => m("Evaluated ValidationState for control {0}, CurrentState = {1}", _controlId, state.ToString().ToLower()));
        }
Beispiel #11
0
        /// <summary>
        /// Evaluates based on the current field values and any additional FIX field values that this EditEvaluator
        /// references.  Used for evaluating Edits in the context of StrategyEdits.
        /// </summary>
        /// <param name="additionalValues">Any additional FIX field values that may be required in the Edit evaluation.</param>
        public void Evaluate(FixFieldValueProvider additionalValues)
        {
            _log.Debug(m => m("EditEvaluator evaluating state of Edit_t/EditRef_t; current state is {0}", CurrentState.ToString().ToLower()));

            if (_edit != null)
            {
                _edit.Evaluate(additionalValues);
            }
            else if (_editRef != null)
            {
                _editRef.Evaluate(additionalValues);
            }
            else
            {
                throw ThrowHelper.New <InvalidOperationException>(this, ErrorMessages.NeitherEditNorEditRefSetOnObject, this.GetType().Name);
            }

            _log.Debug(m => m("EditEvaluator evaluated to state {0}", CurrentState.ToString().ToLower()));
        }
        /// <summary>
        /// Validates all the <see cref="StrategyEdit_t">StrategyEdit</see>s in this collection.
        /// </summary>
        /// <param name="additionalValues">Any additional FIX field values that may be required in the Edit evaluation.</param>
        /// <param name="shortCircuit">If true, this method returns as soon as any error is found; if false, all StrategyEdits
        /// are evaluated before the method returns.</param>
        public bool EvaluateAll(FixFieldValueProvider additionalValues, bool shortCircuit)
        {
            bool valid = true;

            foreach (StrategyEdit_t strategyEdit in Items)
            {
                strategyEdit.Evaluate(additionalValues);

                if (!strategyEdit.CurrentState)
                {
                    if (shortCircuit)
                    {
                        return(false);
                    }

                    valid = false;
                }
            }

            return(valid);
        }
        /// <summary>
        /// Loads the initial value for this control based on the InitPolicy, InitFixField and InitValue attributes.
        /// </summary>
        /// <param name="controlInitValueProvider">Value provider for initializing control values from InitFixField.</param>
        /// <remarks>The spec states: 'If the value of the initPolicy attribute is undefined or equal to "UseValue" and the initValue attribute is
        /// defined then initialize with initValue.  If the value is equal to "UseFixField" then attempt to initialize with the value of
        /// the tag specified in the initFixField attribute. If the value is equal to "UseFixField" and it is not possible to access the
        /// value of the specified fix tag then revert to using initValue. If the value is equal to "UseFixField", the field is not accessible,
        /// and initValue is not defined, then do not initialize.<br></br>
        /// Note that it is possible to initialize an enumerated control (e.g., DropDownList_t) from a FIX_ value.  In this case, it must
        /// be possible to retrieve a valid EnumID for the supplied FIX wire value.  The target parameter is used to translate the wire value
        /// into </remarks>
        public override void LoadInitValue(FixFieldValueProvider controlInitValueProvider)
        {
            // If UseFixField, then attempt to initialize with FIX field...
            if (InitPolicy == InitPolicy_t.UseFixField)
            {
                _log.Debug(m => m("Attempting to initialize control {0} from FIX field...", Id));

                if (!string.IsNullOrEmpty(InitFixField))
                {
                    string value;

                    if (controlInitValueProvider.TryGetValue(InitFixField, ParameterRef, out value))
                    {
                        if (LoadDefaultFromFixValue(value))
                        {
                            _log.Debug(m => m("Control {0} successfully initialized with value '{1}' from FIX field {2}", Id, value, InitFixField));

                            return;
                        }
                    }
                    else
                    {
                        _log.WarnFormat("Unable to initialize control {0} with FIX field {1} as no valid value was found", Id, InitFixField);
                    }
                }
                else
                {
                    _log.WarnFormat("Unable to initialize control {0} with initPolicy = UseFixField as no valid initFixField was supplied", Id);
                }
            }

            _log.Debug(m => m("Initializing control {0} with InitValue '{1}'...", Id, InitValue != null ? InitValue.ToString() : "null"));

            // Unable to initialize with FIX field so let's try using InitValue.  If InitValue is null, then control value will
            // be set to default/empty value.
            LoadDefaultFromInitValue();
        }
Beispiel #14
0
 /// <summary>
 /// Evaluates this EditRef based on the current field values and any additional FIX field values that this
 /// EditRef references.
 /// </summary>
 /// <param name="additionalValues">Any additional FIX field values that may be required in the Edit evaluation.</param>
 public void Evaluate(FixFieldValueProvider additionalValues)
 {
     _referencedEdit.Evaluate(additionalValues);
 }
Beispiel #15
0
 /// <summary>
 /// Loads the initial control values, either from the control's initValue attribute, or using the
 /// FIX_ mechanism in conjunction with the supplied initial FIX values.
 /// </summary>
 /// <param name="controlInitValueProvider">Initial value provider that provides access to the initial FIX field values,
 /// needed to allow control values to be initialised using the FIX_ mechanism .</param>
 public void LoadInitialControlValues(FixFieldValueProvider controlInitValueProvider)
 {
     Controls.LoadDefaults(controlInitValueProvider);
 }
Beispiel #16
0
 /// <summary>
 /// Updates the values of each control within this strategy from its respective parameter.
 /// </summary>
 /// <param name="controlInitValueProvider">Initial value provider that provides access to the initial FIX field values,
 /// needed to allow control values to be initialised using the FIX_ mechanism .</param>
 public void UpdateControlValuesFromParameters(FixFieldValueProvider controlInitValueProvider)
 {
     Controls.UpdateValuesFromParameters(Parameters);
 }
Beispiel #17
0
 /// <summary>
 /// Loads the initial value for this control based on the InitPolicy, InitFixField and InitValue attributes.
 /// </summary>
 /// <param name="controlInitValueProvider">Value provider for initializing control values from InitFixField.</param>
 /// <remarks>The spec states: 'If the value of the initPolicy attribute is undefined or equal to "UseValue" and the initValue attribute is
 /// defined then initialize with initValue.  If the value is equal to "UseFixField" then attempt to initialize with the value of
 /// the tag specified in the initFixField attribute. If the value is equal to "UseFixField" and it is not possible to access the
 /// value of the specified fix tag then revert to using initValue. If the value is equal to "UseFixField", the field is not accessible,
 /// and initValue is not defined, then do not initialize.</remarks>
 public abstract void LoadInitValue(FixFieldValueProvider controlInitValueProvider);
Beispiel #18
0
 /// <summary>
 /// Loads this strategy's parameters with the supplied FIX values.
 /// </summary>
 /// <param name="controlInitValueProvider"><see cref="FixFieldValueProvider"/> providing the FIX values to initialize from.</param>
 /// <param name="resetExistingValues">Set to true if each parameter value is to be reset if its value is specified in
 /// inputValues; set to false to leave the parameter value unchanged.</param>
 public void LoadParameterValues(FixFieldValueProvider controlInitValueProvider, bool resetExistingValues)
 {
     Parameters.LoadInitialValues(controlInitValueProvider.FixValues, resetExistingValues);
 }