private void InitializeClassRelationships(Guid source, Guid target, DomainRelationshipAdvancedInfo info, bool bPropagateToDescendants) { if (info is ReferenceRelationshipAdvancedInfo) { domainClassSourceReferences[source].Add(info as ReferenceRelationshipAdvancedInfo); domainClassTargetReferences[target].Add(info as ReferenceRelationshipAdvancedInfo); } else { domainClassSourceEmbeddings[source].Add(info as EmbeddingRelationshipAdvancedInfo); domainClassTargetEmbeddings[target].Add(info as EmbeddingRelationshipAdvancedInfo); } if (bPropagateToDescendants) { DomainClassInfo infoSource = this.Store.DomainDataDirectory.GetDomainClass(source); foreach (DomainClassInfo d in infoSource.AllDescendants) { InitializeClassRelationships(d.Id, target, info, false); } DomainClassInfo infoTarget = this.Store.DomainDataDirectory.GetDomainClass(target); foreach (DomainClassInfo d in infoTarget.AllDescendants) { InitializeClassRelationships(source, d.Id, info, false); } } }
internal void InitializeClassRelationships() { if (IsClassRelationshipsInitialized) { return; } IsClassRelationshipsInitialized = true; foreach (Guid key in classDictionary.Keys) { domainClassSourceReferences.Add(key, new List <ReferenceRelationshipAdvancedInfo>()); domainClassTargetReferences.Add(key, new List <ReferenceRelationshipAdvancedInfo>()); domainClassSourceEmbeddings.Add(key, new List <EmbeddingRelationshipAdvancedInfo>()); domainClassTargetEmbeddings.Add(key, new List <EmbeddingRelationshipAdvancedInfo>()); } foreach (Guid key in relationshipDictionary.Keys) { DomainRelationshipAdvancedInfo info = relationshipDictionary[key]; domainClassTargetReferences.Add(info.RelationshipDomainClassId, new List <ReferenceRelationshipAdvancedInfo>()); } foreach (Guid key in relationshipDictionary.Keys) { DomainRelationshipAdvancedInfo info = relationshipDictionary[key]; InitializeClassRelationships(info.SourceElementDomainClassId, info.TargetElementDomainClassId, info, true); /*if (info is ReferenceRelationshipAdvancedInfo) * { * domainClassSourceReferences[info.SourceElementDomainClassId].Add(info as ReferenceRelationshipAdvancedInfo); * domainClassTargetReferences[info.TargetElementDomainClassId].Add(info as ReferenceRelationshipAdvancedInfo); * } * else * { * domainClassSourceEmbeddings[info.SourceElementDomainClassId].Add(info as EmbeddingRelationshipAdvancedInfo); * domainClassTargetEmbeddings[info.TargetElementDomainClassId].Add(info as EmbeddingRelationshipAdvancedInfo); * }*/ } foreach (Guid key in classDictionary.Keys) { if (domainClassSourceReferences[key].Count == 0) { domainClassSourceReferences.Remove(key); } if (domainClassTargetReferences[key].Count == 0) { domainClassTargetReferences.Remove(key); } if (domainClassSourceEmbeddings[key].Count == 0) { domainClassSourceEmbeddings.Remove(key); } if (domainClassTargetEmbeddings[key].Count == 0) { domainClassTargetEmbeddings.Remove(key); } } }
/// <summary> /// Processes a proto element representation of the element and adds required proto links. /// This method is called on base classes from derived classes. /// /// Hint: Properties do not need to be added in this method. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> public virtual void ModelProcessMergeCopy(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { foreach (ElementLink link in DomainRoleInfo.GetAllElementLinks(this)) { if (link is DomainModelLink) { DomainModelLink modelLink = link as DomainModelLink; DomainRelationshipAdvancedInfo info = this.Store.DomainDataAdvDirectory.GetRelationshipInfo(modelLink.GetDomainClassId()); if (info is ReferenceRelationshipAdvancedInfo) { if (DomainRoleInfo.GetSourceRolePlayer(modelLink) == this) { if (!(info as ReferenceRelationshipAdvancedInfo).PropagatesCopyToTarget) { continue; } } else if (!(info as ReferenceRelationshipAdvancedInfo).PropagatesCopyToSource) { continue; } ModelProtoLink protoLink = new ModelProtoLink(link); protoGroup.AddNewReferenceLink(protoLink); } else { DomainModelElement child = DomainRoleInfo.GetTargetRolePlayer(link) as DomainModelElement; if (child == this || child == null) { continue; } if ((info as EmbeddingRelationshipAdvancedInfo).PropagatesCopyToChild) { if (!(info as EmbeddingRelationshipAdvancedInfo).IsTargetIncludedSubmodel) { ModelProtoLink protoLink = new ModelProtoLink(link); protoGroup.AddNewEmbeddingLink(protoLink); child.ModelCreateMergeCopy(protoGroup); } else if (child is IParentModelElement) { ModelProtoLink protoLink = new ModelProtoLink(link); protoLink.IsTargetIncludedSubmodel = true; protoLink.DomainFilePath = (child as IParentModelElement).DomainFilePath; protoGroup.AddNewReferenceLink(protoLink); } } } } } /* * // process reference relationships * List<ReferenceRelationshipAdvancedInfo> infos = this.Store.DomainDataAdvDirectory.FindDomainClassSourceReferences(this.GetDomainClassId()); * if (infos != null) * foreach (ReferenceRelationshipAdvancedInfo info in infos) * { * if (info.PropagatesCopyToTarget) * { * System.Collections.ObjectModel.ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(this, info.SourceRoleId); * foreach (ElementLink link in links) * { * ModelProtoLink protoLink = new ModelProtoLink(link); * protoGroup.AddNewReferenceLink(protoLink); * } * } * } * infos = this.Store.DomainDataAdvDirectory.FindDomainClassTargetReferences(this.GetDomainClassId()); * if (infos != null) * foreach (ReferenceRelationshipAdvancedInfo info in infos) * { * if (info.PropagatesCopyToSource) * { * System.Collections.ObjectModel.ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(this, info.TargetRoleId); * foreach (ElementLink link in links) * { * ModelProtoLink protoLink = new ModelProtoLink(link); * protoGroup.AddNewReferenceLink(protoLink); * } * } * } * * // process embedding relationships * List<EmbeddingRelationshipAdvancedInfo> infosEmb = this.Store.DomainDataAdvDirectory.FindDomainClassSourceEmbeddings(this.GetDomainClassId()); * if (infosEmb != null) * foreach (EmbeddingRelationshipAdvancedInfo info in infosEmb) * { * if (info.PropagatesCopyToChild) * { * System.Collections.ObjectModel.ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(this, info.SourceRoleId); * foreach (ElementLink link in links) * { * ModelProtoLink protoLink = new ModelProtoLink(link); * protoGroup.AddNewEmbeddingLink(protoLink); * * DomainModelElement child = DomainRoleInfo.GetTargetRolePlayer(link) as DomainModelElement; * if( child != null ) * child.ModelCreateMergeCopy(protoGroup); * } * } * } */ }