Ejemplo n.º 1
0
        /// <summary>
        /// Create a new Linked Parameter with the given name
        /// </summary>
        /// <param name="name">The name of the linked parameter</param>
        /// <param name="error">If an error occurs this will contain a message to describe it.</param>
        /// <returns>True if it executed successfully</returns>
        public bool NewLinkedParameter(string name, ref string error)
        {
            var lp = new LinkedParameterChange();

            return(_Session.RunCommand(
                       XTMFCommand.CreateCommand("New Linked Parameter", (ref string e) =>
            {
                LinkedParameter linkedParameter = new LinkedParameter(name);
                LinkedParameterModel newModel = new LinkedParameterModel(linkedParameter, _Session, _ModelSystem);
                _RealLinkedParameters.Add(linkedParameter);
                LinkedParameters.Add(newModel);
                lp.Model = newModel;
                lp.Index = LinkedParameters.Count - 1;
                return true;
            },
                                                 (ref string e) =>
            {
                LinkedParameters.RemoveAt(lp.Index);
                _RealLinkedParameters.RemoveAt(lp.Index);
                InvokeRemoved(lp);
                return true;
            },
                                                 (ref string e) =>
            {
                LinkedParameters.Insert(lp.Index, lp.Model);
                _RealLinkedParameters.Insert(lp.Index, lp.Model.RealLinkedParameter);
                return true;
            }),
                       ref error
                       ));
        }
Ejemplo n.º 2
0
        /// <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));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets the name of the linked parameter
 /// </summary>
 /// <param name="newName">The desired new name</param>
 /// <param name="error">A message describing why the operation failed.</param>
 /// <returns>True if the name was changed, false otherwise.</returns>
 public bool SetName(string newName, ref string error)
 {
     lock (ParameterModelsLock)
     {
         string oldName = RealLinkedParameter.Name;
         return(Session.RunCommand(XTMFCommand.CreateCommand((ref string e) =>
         {
             RealLinkedParameter.Name = newName;
             return true;
         },
                                                             (ref string e) =>
         {
             RealLinkedParameter.Name = oldName;
             return true;
         },
                                                             (ref string e) =>
         {
             RealLinkedParameter.Name = newName;
             return true;
         }), ref error));
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Add a new collection member to a collection using the given type
        /// </summary>
        /// <param name="type">The type to add</param>
        /// <param name="name">The name to use, pass a null to automatically name the module</param>
        public bool AddCollectionMember(Type type, ref string error, string name = null)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (!IsCollection)
            {
                throw new InvalidOperationException("You can not add collection members to a module that is not a collection!");
            }

            CollectionChangeData data = new CollectionChangeData();

            return(Session.RunCommand(XTMFCommand.CreateCommand(
                                          (ref string e) =>
            {
                if (!ValidateType(type, ref e))
                {
                    return false;
                }
                if (RealModelSystemStructure.IsCollection)
                {
                    RealModelSystemStructure.Add(RealModelSystemStructure.CreateCollectionMember(name == null ? CreateNameFromType(type) : name, type));
                }
                else
                {
                    RealModelSystemStructure.Add(name == null ? CreateNameFromType(type) : name, type);
                }
                data.Index = RealModelSystemStructure.Children.Count - 1;
                data.StructureInQuestion = RealModelSystemStructure.Children[data.Index] as ModelSystemStructure;
                if (Children == null)
                {
                    Children = new ObservableCollection <ModelSystemStructureModel>();
                }
                Children.Add(data.ModelInQuestion = new ModelSystemStructureModel(Session, data.StructureInQuestion));
                return true;
            },
                                          (ref string e) =>
            {
                Children.RemoveAt(data.Index);
                RealModelSystemStructure.Children.RemoveAt(data.Index);
                return true;
            },
                                          (ref string e) =>
            {
                Children.Insert(data.Index, data.ModelInQuestion);
                RealModelSystemStructure.Children.Insert(data.Index, data.StructureInQuestion);
                return true;
            }),
                                      ref error));
        }