/// <summary> /// Attempts to set the value of the parameter to the new given value /// </summary> /// <param name="newValue">The value to change the parameter to</param> /// <param name="error">If the value is invalid this will contain a message as to why.</param> /// <returns>True if the parameter was set to the new value, false otherwise with an error message in error.</returns> public bool SetValue(string newValue, ref string error) { ParameterChange change = new ParameterChange(); return(Session.RunCommand(XTMFCommand.CreateCommand( // do ((ref string e) => { // Check to see if we are in a linked parameter change.ContainedIn = Session.ModelSystemModel.LinkedParameters.GetContained(this); if (change.ContainedIn == null) { change.NewValue = newValue; change.OldValue = _Value; if (!ArbitraryParameterParser.Check(RealParameter.Type, change.NewValue, ref e)) { return false; } Value = change.NewValue; } else { change.NewValue = newValue; change.OldValue = change.ContainedIn.GetValue(); return change.ContainedIn.SetWithoutCommand(change.NewValue, ref e); } return true; }), // undo (ref string e) => { if (change.ContainedIn == null) { Value = change.OldValue; } else { return change.ContainedIn.SetWithoutCommand(change.OldValue, ref e); } return true; }, // redo (ref string e) => { if (change.ContainedIn == null) { Value = change.NewValue; } else { return change.ContainedIn.SetWithoutCommand(change.NewValue, ref e); } return true; } ), ref error)); }
/// <summary> /// Internally set the value of the linked parameter without using a command in the session. /// </summary> /// <param name="newValue">The value to set it to</param> /// <param name="error">An error message in case of failure</param> /// <returns>True if successful, false if there is an error.</returns> internal bool SetWithoutCommand(string newValue, ref string error) { lock (ParameterModelsLock) { foreach (var parameter in ParameterModels) { if (!ArbitraryParameterParser.Check(parameter.RealParameter.Type, newValue, ref error)) { return(false); } } if (!RealLinkedParameter.SetValue(newValue, ref error)) { return(false); } foreach (var parameter in ParameterModels) { parameter.UpdateValueFromReal(); } } return(true); }