예제 #1
0
        public override void ModelFinalize(CopyPaste.ModelProtoElement protoElement, CopyPaste.ModelProtoGroupMerger groupMerger)
        {
            base.ModelFinalize(protoElement, groupMerger);

            DomainClass domainClass = this.Store.ElementDirectory.FindElement(groupMerger.GetIdMapping(protoElement.ElementId)) as DomainClass;

            if (domainClass == null)
            {
                return;
            }

            if (domainClass.IsDomainModel)
            {
                domainClass.IsDomainModel = false;
            }

            if (domainClass.BaseClass != null)
            {
                ReadOnlyCollection <DomainClassReferencesBaseClass> col = DomainRoleInfo.GetElementLinks <DomainClassReferencesBaseClass>(domainClass, DomainClassReferencesBaseClass.DerivedClassDomainRoleId);
                if (col.Count != 1)
                {
                    throw new ArgumentNullException("Domain class can only reference one base class");
                }

                DomainClassReferencesBaseClass r = col[0];
                r.InhNodeId = Guid.Empty;     // otherwise node id of the source element would be used
            }

            if (domainClass.DomainModelTreeNodes.Count == 0)
            {
                RootNode node = new RootNode(domainClass.Store);
                node.DomainElement   = domainClass;
                node.IsElementHolder = true;

                // add to the domain model diagram tree
                domainClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(node);
                domainClass.ModelContext.ViewContext.DomainModelTreeView.RootNodes.Add(node);
            }

            SerializationDomainClassAddRule.OnDomainClassAdded(domainClass);
            SerializationHelper.UpdateDerivedElementsSerializationProperties(domainClass);
        }
예제 #2
0
        private static void FixUpSerializedDomainModel(ModelContext model)
        {
            foreach (DomainClass domainClass in model.Classes)
            {
                if (domainClass.IsDomainModel)
                {
                    SerializedDomainModel child = new SerializedDomainModel(domainClass.Store);
                    child.DomainClass       = domainClass;
                    child.SerializationName = domainClass.SerializationName;

                    model.SerializationModel.SerializedDomainModel = child;
                    SerializationHelper.AddSerializationDomainProperties(domainClass.Store, domainClass);
                }
                else
                {
                    SerializationDomainClassAddRule.OnDomainClassAdded(domainClass);
                    domainClass.SerializedDomainClass.SerializationName = domainClass.SerializationName;
                }
            }

            foreach (DomainRelationship relationship in model.Relationships)
            {
                if (relationship is EmbeddingRelationship)
                {
                    SerializationDomainRelationshipAddRule.OnEmbeddingRelationshipAdded(relationship as EmbeddingRelationship);
                    (relationship as EmbeddingRelationship).SerializedEmbeddingRelationship.SerializationName = relationship.SerializationName;
                }
                else
                {
                    SerializationDomainRelationshipAddRule.OnReferenceRelationshipAdded(relationship as ReferenceRelationship);
                    (relationship as ReferenceRelationship).SerializedReferenceRelationship.SerializationName = relationship.SerializationName;
                }
            }

            foreach (DomainClass domainClass in model.Classes)
            {
                SerializationHelper.UpdateSerializationDomainProperties(domainClass.Store, domainClass.SerializedDomainClass, domainClass);
                SerializationHelper.UpdateSerializationDomainRoles(domainClass.Store, domainClass.SerializedDomainClass, domainClass);

                foreach (DomainProperty p in domainClass.Properties)
                {
                    p.SerializedDomainProperty.IsSerializationNameTracking = TrackingEnum.True;
                }
            }

            foreach (DomainRelationship relationship in model.Relationships)
            {
                if (relationship is EmbeddingRelationship)
                {
                    SerializationHelper.UpdateSerializationDomainProperties(relationship.Store, (relationship as EmbeddingRelationship).SerializedEmbeddingRelationship, relationship);
                }
                else
                {
                    SerializationHelper.UpdateSerializationDomainProperties(relationship.Store, (relationship as ReferenceRelationship).SerializedReferenceRelationship, relationship);
                }

                foreach (DomainProperty p in relationship.Properties)
                {
                    p.SerializedDomainProperty.IsSerializationNameTracking = TrackingEnum.True;
                }
            }

            // correct IsSerializationNameTracking values

            foreach (DomainClass domainClass in model.Classes)
            {
                if (domainClass.SerializationName != domainClass.Name)
                {
                    domainClass.IsSerializationNameTracking = TrackingEnum.False;
                }

                domainClass.SerializedDomainClass.IsSerializationNameTracking = domainClass.IsSerializationNameTracking;

                foreach (DomainProperty p in domainClass.Properties)
                {
                    if (p.Name != p.SerializationName)
                    {
                        p.IsSerializationNameTracking = TrackingEnum.False;
                    }

                    p.SerializedDomainProperty.IsSerializationNameTracking = p.IsSerializationNameTracking;

                    if (p.Name == "DomainFilePath")
                    {
                        p.SerializedDomainProperty.OmitProperty = true;
                    }
                }
            }

            foreach (DomainRelationship relationship in model.Relationships)
            {
                if (relationship is EmbeddingRelationship)
                {
                    EmbeddingRelationship emb = relationship as EmbeddingRelationship;
                    if (emb.SerializationName != emb.Name)
                    {
                        emb.IsSerializationNameTracking = TrackingEnum.False;
                    }

                    emb.SerializedEmbeddingRelationship.IsSerializationNameTracking = emb.IsSerializationNameTracking;
                }
                else
                {
                    ReferenceRelationship refRel = relationship as ReferenceRelationship;
                    if (refRel.SerializationName != refRel.Name)
                    {
                        refRel.IsSerializationNameTracking = TrackingEnum.False;
                    }

                    refRel.SerializedReferenceRelationship.IsSerializationNameTracking = refRel.IsSerializationNameTracking;
                }

                foreach (DomainProperty p in relationship.Properties)
                {
                    if (p.Name != p.SerializationName)
                    {
                        p.IsSerializationNameTracking = TrackingEnum.True;
                    }

                    p.SerializedDomainProperty.IsSerializationNameTracking = p.IsSerializationNameTracking;
                }
            }
        }