Ejemplo n.º 1
0
        /// <summary>
        /// Gets the source proto role player.
        /// </summary>
        /// <param name="partition">Partition.</param>
        /// <returns>Source proto role player.</returns>
        public ModelProtoRolePlayer GetSourceRolePlayer(Partition partition)
        {
            DomainDataDirectory  domainDataDirectory = partition.Store.DomainDataDirectory;
            ModelProtoRolePlayer protoRolePlayer     = rolePlayers[0];
            DomainRoleInfo       domainRoleInfo      = domainDataDirectory.GetDomainRole(protoRolePlayer.DomainRoleId);

            if (!domainRoleInfo.IsSource)
            {
                protoRolePlayer = rolePlayers[1];
            }
            return(protoRolePlayer);
        }
Ejemplo n.º 2
0
        private void InitDictionaries(Partition partition)
        {
            bNeedsInitialization = false;

            this.embeddingMapping         = new Dictionary <Guid, List <ModelProtoElement> >();
            this.referencingMapping       = new Dictionary <Guid, List <ModelProtoLink> >();
            this.referencingMappingTarget = new Dictionary <Guid, List <ModelProtoLink> >();
            this.elementMapping           = new Dictionary <Guid, ModelProtoElement>();

            foreach (ModelProtoElement element in this.ProtoElements)
            {
                embeddingMapping.Add(element.ElementId, new List <ModelProtoElement>());
                referencingMapping.Add(element.ElementId, new List <ModelProtoLink>());
                referencingMappingTarget.Add(element.ElementId, new List <ModelProtoLink>());
                elementMapping.Add(element.ElementId, element);
            }
            foreach (ModelProtoLink link in this.ProtoEmbeddingLinks)
            {
                ModelProtoRolePlayer rolePlayer = link.GetSourceRolePlayer(partition);
                ModelProtoElement    p          = GetElementById(rolePlayer.RolePlayerId);
                if (p != null)
                {
                    embeddingMapping[p.ElementId].Add(
                        GetElementById(link.GetTargetRolePlayer(partition).RolePlayerId));
                }
            }

            foreach (ModelProtoLink link in this.ProtoReferenceLinks)
            {
                ModelProtoRolePlayer sourceRP = link.GetSourceRolePlayer(partition);
                ModelProtoElement    p        = GetElementById(sourceRP.RolePlayerId);
                if (p != null)
                {
                    referencingMapping[p.ElementId].Add(link);
                }

                ModelProtoRolePlayer targetRP = link.GetTargetRolePlayer(partition);
                p = GetElementById(targetRP.RolePlayerId);
                if (p != null)
                {
                    referencingMappingTarget[p.ElementId].Add(link);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="protoGroup">Proto group to paste/move.</param>
        /// <param name="rootElement">Element to execute paste/move on.</param>
        public ModelProtoGroupMerger(ModelProtoGroup protoGroup, ModelElement rootElement)
        {
            this.protoGroup       = protoGroup;
            this.validationResult = new ValidationResult();

            this.idMapping                = new Dictionary <Guid, Guid>();
            this.embeddingMapping         = new Dictionary <Guid, List <ModelProtoElement> >();
            this.referencingMapping       = new Dictionary <Guid, List <ModelProtoLink> >();
            this.referencingMappingTarget = new Dictionary <Guid, List <ModelProtoLink> >();
            this.elementMapping           = new Dictionary <Guid, ModelProtoElement>();

            if (protoGroup.Operation == ModelProtoGroupOperation.Move)
            {
                // move element
                foreach (ModelProtoElement protoElement in protoGroup.ProtoRootElements)
                {
                    (rootElement as IModelMergeElements).ModelMove(protoElement, this);
                }
                return;
            }

            foreach (ModelProtoElement element in protoGroup.ProtoElements)
            {
                idMapping.Add(element.ElementId, Guid.Empty);
                embeddingMapping.Add(element.ElementId, new List <ModelProtoElement>());
                referencingMapping.Add(element.ElementId, new List <ModelProtoLink>());
                referencingMappingTarget.Add(element.ElementId, new List <ModelProtoLink>());
                elementMapping.Add(element.ElementId, element);
            }
            foreach (ModelProtoLink link in protoGroup.ProtoEmbeddingLinks)
            {
                ModelProtoRolePlayer rolePlayer = link.GetSourceRolePlayer(rootElement.Store.DefaultPartition);
                ModelProtoElement    p          = GetElementById(rolePlayer.RolePlayerId);
                if (p != null)
                {
                    embeddingMapping[p.ElementId].Add(
                        GetElementById(link.GetTargetRolePlayer(rootElement.Store.DefaultPartition).RolePlayerId));
                }
            }

            foreach (ModelProtoLink link in protoGroup.ProtoReferenceLinks)
            {
                ModelProtoRolePlayer sourceRP = link.GetSourceRolePlayer(rootElement.Store.DefaultPartition);
                ModelProtoElement    p        = GetElementById(sourceRP.RolePlayerId);
                if (p != null)
                {
                    referencingMapping[p.ElementId].Add(link);
                }

                ModelProtoRolePlayer targetRP = link.GetTargetRolePlayer(rootElement.Store.DefaultPartition);
                p = GetElementById(targetRP.RolePlayerId);
                if (p != null)
                {
                    referencingMappingTarget[p.ElementId].Add(link);
                }
            }

            // start merging
            foreach (ModelProtoElement protoElement in protoGroup.ProtoRootElements)
            {
                (rootElement as IModelMergeElements).ModelMerge(protoElement, this, true);
            }

            // process reference relationships
            foreach (ModelProtoLink link in protoGroup.ProtoReferenceLinks)
            {
                ModelProtoRolePlayer sourceRP = link.GetSourceRolePlayer(rootElement.Store.DefaultPartition);
                if (this.idMapping.ContainsKey(sourceRP.RolePlayerId))
                {
                    System.Guid id = this.idMapping[sourceRP.RolePlayerId];
                    if (id != Guid.Empty)
                    {
                        ModelElement copiedModelElement = rootElement.Store.ElementDirectory.FindElement(id);
                        if (copiedModelElement != null)
                        {
                            if (copiedModelElement is IModelMergeElements)
                            {
                                (copiedModelElement as IModelMergeElements).ModelMerge(link, this);
                            }
                        }
                        continue;
                    }
                }

                System.Guid  elementId    = sourceRP.RolePlayerId;
                ModelElement modelElement = rootElement.Store.ElementDirectory.FindElement(elementId);
                if (modelElement != null)
                {
                    if (modelElement is IModelMergeElements)
                    {
                        (modelElement as IModelMergeElements).ModelMerge(link, this);
                    }
                }
            }

            // finalize merging
            foreach (ModelProtoElement protoElement in protoGroup.ProtoElements)
            {
                Guid id = Guid.Empty;
                try
                {
                    id = GetIdMapping(protoElement.ElementId);
                }
                catch
                {
                    id = Guid.Empty;
                    continue;
                }

                /*
                 * if (id == Guid.Empty)
                 * {
                 *  ModelElement m = rootElement.Store.ElementDirectory.FindElement(id);
                 *  if (m != null)
                 *      id = m.Id;
                 *  else
                 *      continue;
                 * }*/

                ModelElement m = rootElement.Store.ElementDirectory.FindElement(id);
                if (m != null)
                {
                    (m as IModelMergeElements).ModelFinalize(protoElement, this);
                }
            }

            // finalize merging
            foreach (ModelProtoElement protoElement in protoGroup.ProtoRootElements)
            {
                (rootElement as IModelMergeElements).ModelFinalizeMerge(protoElement, this);
            }
        }