/// <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)); }
/// <summary> /// Removes a collection member at the given index /// </summary> /// <param name="index">The index to remove from.</param> /// <param name="error">If an error happens it will contain a text representation of the error.</param> /// <returns>If the index was able to be removed</returns> /// <exception cref="InvalidOperationException">This operation is only allowed on Collections.</exception> public bool RemoveCollectionMember(int index, ref string error) { if (index < 0) { throw new InvalidOperationException("Indexes must be greater than or equal to zero!"); } 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) => { var children = RealModelSystemStructure.Children; if (children.Count <= index) { e = "There is no collection member at index " + index + "!"; return false; } data.Index = index; data.StructureInQuestion = RealModelSystemStructure.Children[data.Index] as ModelSystemStructure; data.ModelInQuestion = Children[data.Index]; RealModelSystemStructure.Children.RemoveAt(data.Index); Children.RemoveAt(data.Index); ModelHelper.PropertyChanged(PropertyChanged, this, "Children"); return true; }, (ref string e) => { RealModelSystemStructure.Children.Insert(data.Index, data.StructureInQuestion); Children.Insert(data.Index, data.ModelInQuestion); ModelHelper.PropertyChanged(PropertyChanged, this, "Children"); return true; }, (ref string e) => { RealModelSystemStructure.Children.RemoveAt(data.Index); Children.RemoveAt(data.Index); ModelHelper.PropertyChanged(PropertyChanged, this, "Children"); return true; }), ref error)); }
/// <summary> /// Removes a collection member at the given index /// </summary> /// <param name="index">The index to remove from.</param> /// <param name="error">If an error happens it will contain a text representation of the error.</param> /// <returns>If the index was able to be removed</returns> /// <exception cref="InvalidOperationException">This operation is only allowed on Collections.</exception> public bool RemoveCollectionMember(int index, ref string error) { if(index < 0) { throw new InvalidOperationException("Indexes must be greater than or equal to zero!"); } 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) => { var children = RealModelSystemStructure.Children; if(children.Count <= index) { e = "There is no collection member at index " + index + "!"; return false; } data.Index = index; data.StructureInQuestion = RealModelSystemStructure.Children[data.Index] as ModelSystemStructure; data.ModelInQuestion = Children[data.Index]; RealModelSystemStructure.Children.RemoveAt(data.Index); Children.RemoveAt(data.Index); ModelHelper.PropertyChanged(PropertyChanged, this, "Children"); return true; }, (ref string e) => { RealModelSystemStructure.Children.Insert(data.Index, data.StructureInQuestion); Children.Insert(data.Index, data.ModelInQuestion); ModelHelper.PropertyChanged(PropertyChanged, this, "Children"); return true; }, (ref string e) => { RealModelSystemStructure.Children.RemoveAt(data.Index); Children.RemoveAt(data.Index); ModelHelper.PropertyChanged(PropertyChanged, this, "Children"); return true; }), ref error); }
/// <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); }