Beispiel #1
0
        protected Relationship ConvertEntityRelationship(VrXmlRelationship xmlRel)
        {
            GameObject   ownerObject = string.IsNullOrEmpty(xmlRel.ownerEntityId) ? gameObject : entityObjects[xmlRel.ownerEntityId];
            Relationship rel         = null;

            if (xmlRel is VrXmlCompositionRelationship)
            {
                var xmlOneToMany = xmlRel as VrXmlCompositionRelationship;
                rel = AddCompositionRelationship(xmlOneToMany.ownerEntityId, xmlOneToMany.subjectEntityId, xmlOneToMany.objectEntitiesId);
            }
            else if (xmlRel is VrXmlInclusionRelationship)
            {
                var xmlOneToMany = xmlRel as VrXmlInclusionRelationship;
                rel = AddInclusionRelationship(xmlOneToMany.ownerEntityId, xmlOneToMany.subjectEntityId, xmlOneToMany.objectEntitiesId);
            }
            else if (xmlRel is VrXmlOneToOneRelationship)
            {
                var xmlOneToOne = xmlRel as VrXmlOneToOneRelationship;
                rel = AddOneToOneRelationship(xmlOneToOne.ownerEntityId, xmlOneToOne.subjectEntityId, xmlOneToOne.objectEntityId);
            }
            else if (xmlRel is VrXmlOneToManyRelationship)
            {
                var xmlOneToMany = xmlRel as VrXmlOneToManyRelationship;
                rel = AddOneToManyRelationship(xmlOneToMany.ownerEntityId, xmlOneToMany.subjectEntityId, xmlOneToMany.objectEntitiesId);
            }
            else if (xmlRel is VrXmlManyToManyRelationship)
            {
                var xmlManyToMany = xmlRel as VrXmlManyToManyRelationship;
                rel = AddManyToManyRelationship(xmlManyToMany.ownerEntityId, xmlManyToMany.subjectEntitiesId, xmlManyToMany.objectEntitiesId);
            }

            //// update cross references
            //rel.OnValidate();
            return(rel);
        }
Beispiel #2
0
        protected VrXmlRelationship ConvertObjectRelationship(Relationship rel)
        {
            VrXmlRelationship xmlRel = null;
            var oneToOne             = rel as OneToOneRelationship;
            var oneToMany            = rel as OneToManyRelationship;
            var manyToMany           = rel as ManyToManyRelationship;

            if (rel is CompositionRelationship)
            {
                xmlRel = new VrXmlCompositionRelationship();
            }
            else if (rel is InclusionRelationship)
            {
                xmlRel = new VrXmlInclusionRelationship();
            }
            else if (rel is OneToManyRelationship)
            {
                xmlRel = new VrXmlOneToOneRelationship();
            }
            else if (rel is OneToManyRelationship)
            {
                xmlRel = new VrXmlOneToManyRelationship();
            }
            else if (rel is ManyToManyRelationship)
            {
                xmlRel = new VrXmlManyToManyRelationship();
            }
            var xmlOneToOne   = xmlRel as VrXmlOneToOneRelationship;
            var xmlOneToMany  = xmlRel as VrXmlOneToManyRelationship;
            var xmlManyToMany = xmlRel as VrXmlManyToManyRelationship;

            if (oneToOne)
            {
                xmlOneToOne.subjectEntityId = oneToOne.subjectEntity.id;
                xmlOneToOne.objectEntityId  = oneToOne.objectEntity.id;
            }
            else if (oneToMany)
            {
                xmlOneToMany.subjectEntityId = oneToMany.subjectEntity.id;
                xmlOneToMany.objectEntitiesId.AddRange(oneToMany.objectEntities.Select(ent => ent.id));
            }
            else if (manyToMany)
            {
                xmlManyToMany.subjectEntitiesId.AddRange(manyToMany.subjectEntities.Select(ent => ent.id));
                xmlManyToMany.objectEntitiesId.AddRange(manyToMany.objectEntities.Select(ent => ent.id));
            }
            xmlRel.id            = rel.id;
            xmlRel.typeName      = rel.typeName;
            xmlRel.ownerEntityId = rel.ownerEntity ? rel.ownerEntity.id : null;
            return(xmlRel);
        }