Beispiel #1
0
        public virtual ProductComponent Clone()
        {
            // clone component
            var clonedComponent = (ProductComponent)this.MemberwiseClone();

            clonedComponent.Id        = Guid.NewGuid();
            clonedComponent.NHVersion = 0;

            // clone work instructions
            var workInstructionList = new List <GTSWorkInstruction>();

            GTSWorkInstruction placeHolder;

            WorkInstructions.ToList().ForEach(x =>
            {
                placeHolder = x.Clone();
                placeHolder.ProductComponent = clonedComponent;
                workInstructionList.Add(placeHolder);
            });

            // assign clone child collection to cloned model
            clonedComponent.WorkInstructions = workInstructionList;

            // clone product model configurations
            var productModelConfigurations = new List <ProductModelConfiguration>();
            ProductModelConfiguration configPlaceholder;

            ProductModelConfigurations.ToList().ForEach(x =>
            {
                configPlaceholder             = new ProductModelConfiguration();
                configPlaceholder.Id          = Guid.NewGuid();
                configPlaceholder.Name        = x.Name;
                configPlaceholder.ConfigIndex = x.ConfigIndex;
                configPlaceholder.Color       = x.Color;

                productModelConfigurations.Add(configPlaceholder);
            });

            // assign collection
            clonedComponent.ProductModelConfigurations = productModelConfigurations;

            return(clonedComponent);
        }
Beispiel #2
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns></returns>
        public virtual ProductModel Clone(bool createVersion = true, string modelName = "", string idMask = "", string description = "")
        {
            // clone item (without child collections), increase version
            var clonedModel = (ProductModel)this.MemberwiseClone();

            clonedModel.Id         = Guid.NewGuid();
            clonedModel.IsReleased = false;
            clonedModel.IsArchived = false;

            if (createVersion)
            {
                // create a new version
                clonedModel.Version = Version + 1;
            }
            else
            {
                if (string.IsNullOrEmpty(modelName) || string.IsNullOrEmpty(idMask) || string.IsNullOrEmpty(description))
                {
                    throw new ArgumentNullException("Pass a valid name, id mask and description if a model needs to be cloned.");
                }

                // or create a new model with new name, 0 version and new base model id
                clonedModel.Name        = modelName;
                clonedModel.Version     = 0;
                clonedModel.BaseModelId = Guid.NewGuid();
                clonedModel.IdMask      = IdMask;
                clonedModel.Comment     = description;
            }

            clonedModel.NHVersion = 0;

            // clone each child element and assign cloned item as parent
            var productComponentList = new List <ProductComponent>();
            ProductComponent placeHolder;

            ProductComponents.ToList().ForEach(x =>
            {
                placeHolder = x.Clone();
                placeHolder.ProductModel = clonedModel;
                productComponentList.Add(placeHolder);
            });

            // clone product model configurations
            var productModelConfigurations = new List <ProductModelConfiguration>();
            ProductModelConfiguration configPlaceholder;

            ProductModelConfigurations.ToList().ForEach(x =>
            {
                configPlaceholder             = new ProductModelConfiguration();
                configPlaceholder.Id          = Guid.NewGuid();
                configPlaceholder.Name        = x.Name;
                configPlaceholder.ConfigIndex = x.ConfigIndex;
                configPlaceholder.Color       = x.Color;

                productModelConfigurations.Add(configPlaceholder);
            });

            // assign collection to ProductModelConfigurations property
            clonedModel.ProductModelConfigurations = productModelConfigurations;

            // clone product part numbers
            var        productModelPartNrs = new List <PartNumber>();
            PartNumber placeholder;

            PartNumbers.ToList().ForEach(x =>
            {
                placeholder              = new PartNumber();
                placeholder.Id           = Guid.NewGuid();
                placeholder.Number       = x.Number;
                placeholder.ProductModel = clonedModel;

                productModelPartNrs.Add(placeholder);
            });

            //assign part numbers to part nrs property
            clonedModel.PartNumbers = productModelPartNrs;

            // create a new list object or a "Shared collection" exception will be thrown
            clonedModel.Tooling = new List <AssemblyTool>();
            ((List <AssemblyTool>)clonedModel.Tooling).AddRange(Tooling);

            // assign clone child collection to cloned model
            clonedModel.ProductComponents = productComponentList;

            return(clonedModel);
        }