/// <summary>
        /// Adds a proto element to the current element.
        /// </summary>
        /// <param name="protoElement">Proto element representation of the element that is to be added.</param>
        /// <param name="groupMerger">
        /// Group merger class used to track id mapping, merge errors/warnings and 
        /// postprocess merging by rebuilding reference relationships.
        /// </param>
        /// <param name="isRoot">Root element?</param>
        public virtual void ModelMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger, bool isRoot)
        {
            if (!ModelIsPasteAllowed(groupMerger.ProtoGroup.Operation))
            {
                // add warning message
                groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergePasteDisallowedId,
                             ModelValidationViolationType.Warning, "Element couldn't be addded to " + this.DomainElementFullName + " because paste is not allowed."));
                return;
            }

            if (protoElement != null)
            {
                DomainClassInfo elementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(protoElement.DomainClassId);
                foreach (DomainRoleInfo info in elementDomainInfo.AllDomainRolesPlayed)
                {
                    if (!info.IsSource)
                        if (info.OppositeDomainRole.RolePlayer.Id == this.GetDomainClassId())
                            if (this.Store.DomainDataAdvDirectory.IsEmbeddingRelationship(info.DomainRelationship.Id) &&
                                !this.Store.DomainDataAdvDirectory.IsAbstractRelationship(info.DomainRelationship.Id))
                            {
                                // create element id
                                Guid newElementId = this.GetDomainModelServices().ElementIdProvider.GenerateNewKey();

                                // create property assignments
                                PropertyAssignment[] propertyAssignemnts = protoElement.GetPropertyAssignments(this.Store.DefaultPartition, newElementId);

                                // create the actual model element
                                DomainModelElement element = this.Store.ElementFactory.CreateElement(elementDomainInfo, propertyAssignemnts) as DomainModelElement;
                                if (element == null)
                                    throw new System.ArgumentNullException("Element is null in ModelMerge: " + elementDomainInfo.Name);

                                if (!element.ModelIsPasteAllowed(groupMerger.ProtoGroup.Operation))
                                {
                                    // add warning message
                                    groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergePasteDisallowedId,
                                         ModelValidationViolationType.Warning, "Element couldn't be addded to <#= role.RolePlayer.Name #> because paste is not allowed."));

                                    element.Delete();
                                    return;
                                }

                                // set name
                                if (isRoot && groupMerger.ProtoGroup.Operation != ModelProtoGroupOperation.Move)
                                {
                                    if (element.DomainElementHasName)
                                    {
                                        element.GetDomainModelServices().ElementNameProvider.SetName(element, "Copy of " + element.DomainElementName);
                                    }
                                }

                                // update id mapping
                                groupMerger.SetIdMapping(protoElement.ElementId, newElementId);

                                // add child element
                                if (info.OppositeDomainRole.Multiplicity == Multiplicity.One || info.OppositeDomainRole.Multiplicity == Multiplicity.ZeroOne)
                                {
                                    DomainRoleInfo.SetLinkedElement(this, info.OppositeDomainRole.Id, element);
                                }
                                else
                                {
                                    RoleAssignment[] assignments = new RoleAssignment[2];
                                    assignments[0] = new RoleAssignment(info.OppositeDomainRole.Id, this);
                                    assignments[1] = new RoleAssignment(info.Id, element);


                                    this.Store.ElementFactory.CreateElementLink(info.DomainRelationship, assignments);
                                }

                                // continue with child elements (Embedding Relationship)
                                System.Collections.Generic.List<ModelProtoElement> embeddedProtoElements = groupMerger.GetEmbeddedElements(this.Store.DefaultPartition, protoElement);
                                if (embeddedProtoElements.Count > 0)
                                {
                                    foreach (ModelProtoElement p in embeddedProtoElements)
                                        (element as IModelMergeElements).ModelMerge(p, groupMerger, false);
                                }

                                return;
                            }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds a proto element to the current element.
        /// </summary>
        /// <param name="protoElement">Proto element representation of the element that is to be added.</param>
        /// <param name="groupMerger">
        /// Group merger class used to track id mapping, merge errors/warnings and
        /// postprocess merging by rebuilding reference relationships.
        /// </param>
        /// <param name="isRoot">Root element?</param>
        public virtual void ModelMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger, bool isRoot)
        {
            if (!ModelIsPasteAllowed(groupMerger.ProtoGroup.Operation))
            {
                // add warning message
                groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergePasteDisallowedId,
                                                                         ModelValidationViolationType.Warning, "Element couldn't be addded to " + this.DomainElementFullName + " because paste is not allowed."));
                return;
            }

            if (protoElement != null)
            {
                DomainClassInfo elementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(protoElement.DomainClassId);
                foreach (DomainRoleInfo info in elementDomainInfo.AllDomainRolesPlayed)
                {
                    if (!info.IsSource)
                    {
                        if (info.OppositeDomainRole.RolePlayer.Id == this.GetDomainClassId())
                        {
                            if (this.Store.DomainDataAdvDirectory.IsEmbeddingRelationship(info.DomainRelationship.Id) &&
                                !this.Store.DomainDataAdvDirectory.IsAbstractRelationship(info.DomainRelationship.Id))
                            {
                                // create element id
                                Guid newElementId = this.GetDomainModelServices().ElementIdProvider.GenerateNewKey();

                                // create property assignments
                                PropertyAssignment[] propertyAssignemnts = protoElement.GetPropertyAssignments(this.Store.DefaultPartition, newElementId);

                                // create the actual model element
                                DomainModelElement element = this.Store.ElementFactory.CreateElement(elementDomainInfo, propertyAssignemnts) as DomainModelElement;
                                if (element == null)
                                {
                                    throw new System.ArgumentNullException("Element is null in ModelMerge: " + elementDomainInfo.Name);
                                }

                                if (!element.ModelIsPasteAllowed(groupMerger.ProtoGroup.Operation))
                                {
                                    // add warning message
                                    groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergePasteDisallowedId,
                                                                                             ModelValidationViolationType.Warning, "Element couldn't be addded to <#= role.RolePlayer.Name #> because paste is not allowed."));

                                    element.Delete();
                                    return;
                                }

                                // set name
                                if (isRoot && groupMerger.ProtoGroup.Operation != ModelProtoGroupOperation.Move)
                                {
                                    if (element.DomainElementHasName)
                                    {
                                        element.GetDomainModelServices().ElementNameProvider.SetName(element, "Copy of " + element.DomainElementName);
                                    }
                                }

                                // update id mapping
                                groupMerger.SetIdMapping(protoElement.ElementId, newElementId);

                                // add child element
                                if (info.OppositeDomainRole.Multiplicity == Multiplicity.One || info.OppositeDomainRole.Multiplicity == Multiplicity.ZeroOne)
                                {
                                    DomainRoleInfo.SetLinkedElement(this, info.OppositeDomainRole.Id, element);
                                }
                                else
                                {
                                    RoleAssignment[] assignments = new RoleAssignment[2];
                                    assignments[0] = new RoleAssignment(info.OppositeDomainRole.Id, this);
                                    assignments[1] = new RoleAssignment(info.Id, element);


                                    this.Store.ElementFactory.CreateElementLink(info.DomainRelationship, assignments);
                                }

                                // continue with child elements (Embedding Relationship)
                                System.Collections.Generic.List <ModelProtoElement> embeddedProtoElements = groupMerger.GetEmbeddedElements(this.Store.DefaultPartition, protoElement);
                                if (embeddedProtoElements.Count > 0)
                                {
                                    foreach (ModelProtoElement p in embeddedProtoElements)
                                    {
                                        (element as IModelMergeElements).ModelMerge(p, groupMerger, false);
                                    }
                                }

                                return;
                            }
                        }
                    }
                }
            }
        }