private void OnInitializeCommand() { try { _initialFixValues = null; NotifyPropertyChanged("InitialFixValues"); if (string.IsNullOrEmpty(InitialValuesString)) { _initialFixValues = FixTagValuesCollection.Empty; } else { _initialFixValues = new FixTagValuesCollection(InitialValuesString.Replace('|', '\x01').Trim()); } NotifyPropertyChanged("InitialFixValues"); RequestValidationRefresh(); } catch (FixParseException ex) { // Really shouldn't be throwing message boxes from the View Model, I know... MessageBox.Show(ex.Message); } }
/// <summary> /// Gets the complete set of FIX values for the strategy that this parameter collection belongs to. /// </summary> /// <returns><see cref="FixTagValuesCollection"/> that contains the FIX values corresponding to this set of /// parameters.</returns> public FixTagValuesCollection GetOutputValues() { FixTagValuesCollection output = new FixTagValuesCollection(); foreach (IParameter parameter in this.Items) { if (parameter.FixTag != null && parameter.WireValue != null) { output.Add((FixTag)parameter.FixTag, parameter.WireValue); } } return(output); }
/// <summary> /// Loads this set of parameters with the supplied FIX values. /// </summary> /// <param name="initialValues"><see cref="FixTagValuesCollection"/> containing the FIX values to initialize from.</param> /// <param name="resetNonSuppliedParameters">Set to true if each parameter value is to be reset if a corresponding value is /// not specified in inputValues; set to false to leave the parameter value unchanged.</param> public void LoadInitialValues(FixTagValuesCollection initialValues, bool resetNonSuppliedParameters) { string value; foreach (IParameter parameter in this.Items) { if (parameter.FixTag != null && initialValues.TryGetValue((FixTag)parameter.FixTag, out value)) { parameter.WireValue = value; } else if (resetNonSuppliedParameters) { parameter.Reset(); } } }
/// <summary> /// Refreshes the output FIX tags and values based on the current state of the Strategy. Note that if any StrategyEdit is /// invalid, then a <see cref="ValidationException"/> is thrown. /// </summary> /// <exception cref="ValidationException">Thrown if any control/parameter value is invalid or any StrategyEdit is invalid.</exception> public void RefreshOutputValues() { if (Strategy == null) { throw ThrowHelper.New <NullReferenceException>(this, ErrorMessages.NoStrategySelectedError); } // NB Not localizable as this is a developer-level rather than end-user error if (!_inputValuesSet) { throw ThrowHelper.New <InvalidOperationException>(this, ErrorMessages.UnableToInvokeMethodError, "RefreshOutputValues", "The InputFixValues property must be set prior to attempting to retrieve the output FIX values"); } // Step 1: Ensure all controls have internally valid values (NB this is NOT checking the parameter validity) if (!ViewModel.Controls.AreAllValid) { throw ThrowHelper.New <ValidationException>(this, ErrorMessages.OneOrMoreInvalidControlValues); } IList <ValidationResult> validationResults; // Step 2: Update all the parameter values from the controls, throwing if there are any problems if (!Strategy.TryUpdateParameterValuesFromControls(false, out validationResults)) { StringBuilder sb = new StringBuilder(); foreach (ValidationResult result in validationResults) { sb.AppendFormat("{0}\n", result.ErrorText); } string errorText = sb.ToString(); throw ThrowHelper.New <InvalidFieldValueException>(this, sb.ToString().Substring(0, errorText.Length - 1)); } // Step 3: Validate all StrategyEdits if (!ViewModel.EvaluateAllStrategyEdits(this)) { StringBuilder sb = new StringBuilder(); foreach (StrategyEdit_t strategyEdit in (from se in Strategy.StrategyEdits where !se.CurrentState select se)) { sb.AppendFormat("{0}\n", strategyEdit.ErrorMessage); } string errorText = sb.ToString(); throw ThrowHelper.New <ValidationException>(this, sb.ToString().Substring(0, errorText.Length - 1)); } FixTagValuesCollection fixTagValues = Strategy.Parameters.GetOutputValues(); // Step 4: Add in the StrategyIdentifier and optional VersionIdentifier tags if (Strategy.Parent != null) { fixTagValues.Add(Strategy.Parent.StrategyIdentifierTag, Strategy.WireValue); if (Strategy.Parent.VersionIdentifierTag != null) { fixTagValues.Add((FixTag)Strategy.Parent.VersionIdentifierTag, Strategy.Version); } } _log.Debug(m => m("RefreshOutputValues() yielding: {0}", fixTagValues.ToString())); OutputFixValues = fixTagValues; }