public static void OnDomainClassAdded(DomainClass domainClass)
        {
            if (domainClass.SerializedDomainClass == null)
            {
                SerializedDomainClass child = new SerializedDomainClass(domainClass.Store);
                child.DomainClass = domainClass;
                child.SerializationName = domainClass.SerializationName;

                domainClass.ModelContext.SerializationModel.Children.Add(child);
                SerializationHelper.AddSerializationDomainProperties(domainClass.Store, domainClass);
            }
        }
コード例 #2
0
        /// <summary>
        /// Updates the domain roles of the given element. (Roles from derived elements are included here).
        /// </summary>
        /// <param name="store">Store containing the domain model.</param>
        /// <param name="serializationElement"></param>
        /// <param name="domainClass"></param>
        public static void UpdateSerializationDomainRoles(Store store, SerializedDomainClass serializationElement, DomainClass domainClass)
        {
            if (serializationElement == null || domainClass == null)
                return;

            //if (!serializationElement.DomainClass.ParentModelContext.MetaModel.IsTopMost)
            //    return;

            List<SerializationElement> handledRS = new List<SerializationElement>();

            // get roles
            DomainClass temp = domainClass;
            SerializedDomainClass tempElement = serializationElement;
            while (temp != null && tempElement != null)
            {
                foreach (SerializationElement sP in tempElement.Children)
                {
                    if (sP is SerializedReferenceRelationship || sP is SerializedEmbeddingRelationship)
                    {
                        // see whether the relationship is abstract or not. If it is abstract, than we dont
                        // need to add its role players
                        DomainRelationship relationship = null;
                        SerializedReferenceRelationship s = sP as SerializedReferenceRelationship;
                        if (s != null)
                        {
                            relationship = s.ReferenceRelationship;
                            if (s.ReferenceRelationship.InheritanceModifier == InheritanceModifier.Abstract && s.ReferenceRelationship.Source.RolePlayer != domainClass)
                                continue;
                        }

                        SerializedEmbeddingRelationship sE = sP as SerializedEmbeddingRelationship;
                        if (sE != null)
                        {
                            relationship = sE.EmbeddingRelationship;
                            if (sE.EmbeddingRelationship.InheritanceModifier == InheritanceModifier.Abstract && sE.EmbeddingRelationship.Source.RolePlayer != domainClass)
                                continue;

                        }

                        // see if the current element is still active
                        bool bActive = false;
                        foreach (DomainRole role in temp.RolesPlayed)
                        {
                            if (role.Relationship.Source == role && role.Relationship == relationship)
                            {
                                bActive = true;
                                continue;
                            }
                        }
                        if (!bActive)
                            continue;

                        handledRS.Add(sP);

                        if (tempElement != serializationElement)
                        {
                            // see if we already have this element embedded
                            bool bAdd = true;
                            foreach (SerializationElement elem in serializationElement.Children)
                                if (elem == sP)
                                {
                                    bAdd = false;
                                    break;
                                }

                            if (bAdd)
                            {
                                serializationElement.Children.Add(sP);
                            }
                        }
                    }
                }

                temp = temp.BaseClass;
                if (temp != null)
                    tempElement = temp.SerializedDomainClass;
                else
                    tempElement = null;
            }

            // remove unneded rs
            List<SerializationElement> toRemove = new List<SerializationElement>();
            foreach (SerializationElement sP in serializationElement.Children)
            {
                if (sP is SerializedReferenceRelationship || sP is SerializedEmbeddingRelationship)
                    if (!handledRS.Contains(sP))
                    {
                        toRemove.Add(sP);
                    }
            }

            foreach (SerializationElement sP in toRemove)
                serializationElement.Children.Remove(sP);
        }