Exemplo n.º 1
0
        public IModelSystemStructure Clone()
        {
            ModelSystemStructure cloneUs = new ModelSystemStructure(this.Configuration);

            cloneUs.Name        = this.Name;
            cloneUs.Description = this.Description;
            cloneUs.Module      = this.Module;
            if (this.Parameters != null)
            {
                if ((cloneUs.Parameters = this.Parameters.Clone()) != null)
                {
                    (cloneUs.Parameters as ModuleParameters).BelongsTo = cloneUs;
                    foreach (var p in cloneUs.Parameters)
                    {
                        (p as ModuleParameter).BelongsTo = cloneUs;
                    }
                }
            }
            cloneUs.Required        = this.Required;
            cloneUs.ParentFieldName = this.ParentFieldName;
            cloneUs.ParentFieldType = this.ParentFieldType;
            cloneUs._Type           = this._Type;
            cloneUs.IsCollection    = this.IsCollection;
            if (this.Children != null)
            {
                foreach (var child in this.Children)
                {
                    cloneUs.Add(child.Clone());
                }
            }
            return(cloneUs);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
 public IModelSystemStructure Clone()
 {
     ModelSystemStructure cloneUs = new ModelSystemStructure(this.Configuration);
     cloneUs.Name = this.Name;
     cloneUs.Description = this.Description;
     cloneUs.Module = this.Module;
     if(this.Parameters != null)
     {
         if((cloneUs.Parameters = this.Parameters.Clone()) != null)
         {
             (cloneUs.Parameters as ModuleParameters).BelongsTo = cloneUs;
             foreach(var p in cloneUs.Parameters)
             {
                 (p as ModuleParameter).BelongsTo = cloneUs;
             }
         }
     }
     cloneUs.Required = this.Required;
     cloneUs.ParentFieldName = this.ParentFieldName;
     cloneUs.ParentFieldType = this.ParentFieldType;
     cloneUs._Type = this._Type;
     cloneUs.IsCollection = this.IsCollection;
     if(this.Children != null)
     {
         foreach(var child in this.Children)
         {
             cloneUs.Add(child.Clone());
         }
     }
     return cloneUs;
 }