Пример #1
0
        public static List <CdmE2ERelationship> FromData(CdmCorpusContext ctx, RelationshipEntity relationshipEntity)
        {
            List <CdmE2ERelationship> relationships = new List <CdmE2ERelationship>();

            RelationshipProperties relationshipProperties = ((JToken)relationshipEntity.Properties).ToObject <RelationshipProperties>();

            foreach (var columnRelationshipInformation in relationshipProperties.ColumnRelationshipInformations)
            {
                var relationship = ctx.Corpus.MakeObject <CdmE2ERelationship>(CdmObjectType.E2ERelationshipDef);
                if (!string.IsNullOrWhiteSpace(relationshipEntity.Name))
                {
                    relationship.Name = relationshipEntity.Name;
                }

                if (relationshipProperties.RelationshipType == RelationshipType.MANYTOONE ||
                    relationshipProperties.RelationshipType == RelationshipType.ONETOONE)
                {
                    relationship.FromEntity          = $"{relationshipProperties.FromTableName}.cdm.json/{relationshipProperties.FromTableName}";
                    relationship.ToEntity            = $"{relationshipProperties.ToTableName}.cdm.json/{relationshipProperties.ToTableName}";
                    relationship.FromEntityAttribute = columnRelationshipInformation.FromColumnName;
                    relationship.ToEntityAttribute   = columnRelationshipInformation.ToColumnName;
                }
                else if (relationshipProperties.RelationshipType == RelationshipType.ONETOMANY)
                {
                    relationship.FromEntity          = $"{relationshipProperties.ToTableName}.cdm.json/{relationshipProperties.ToTableName}";
                    relationship.ToEntity            = $"{relationshipProperties.FromTableName}.cdm.json/{relationshipProperties.FromTableName}";
                    relationship.FromEntityAttribute = columnRelationshipInformation.ToColumnName;
                    relationship.ToEntityAttribute   = columnRelationshipInformation.FromColumnName;
                }
                else if (relationshipProperties.RelationshipType == RelationshipType.MANYTOMANY)
                {
                    // error
                    return(null);
                }

                if (relationshipProperties.Properties != null)
                {
                    if (relationshipProperties.Properties.ContainsKey("cdm:exhibitsTraits"))
                    {
                        Utils.AddListToCdmCollection(relationship.ExhibitsTraits, Utils.CreateTraitReferenceList(ctx, relationshipProperties.Properties["cdm:exhibitsTraits"]));
                    }
                }
                relationships.Add(relationship);
            }

            return(relationships);
        }
Пример #2
0
        public static RelationshipEntity ToData(CdmE2ERelationship instance, string dbName, ResolveOptions resOpt, CopyOptions options, IDictionary <string, RelationshipEntity> relationship = null)
        {
            var properties = new Dictionary <string, JToken>();

            if (instance.ExhibitsTraits != null && instance.ExhibitsTraits.Count > 0)
            {
                properties["cdm:exhibitsTraits"] = JToken.FromObject(CopyDataUtils.ListCopyData(resOpt, instance.ExhibitsTraits, options));
            }

            var relationshipProperties = new RelationshipProperties
            {
                NamespaceProperty = new NamespaceModel {
                    DatabaseName = dbName
                },
                FromTableName    = Utils.ExtractTableNameFromEntityPath(instance.FromEntity),
                ToTableName      = Utils.ExtractTableNameFromEntityPath(instance.ToEntity),
                Properties       = properties,
                PublishStatus    = PublishStatus.PUBLISHED,
                RelationshipType = RelationshipType.MANYTOONE
            };

            var relationshipName = instance.Name;

            if (string.IsNullOrEmpty(instance.Name))
            {
                relationshipName = $"{relationshipProperties.FromTableName}_{relationshipProperties.ToTableName}_relationship";
            }

            relationshipProperties.ColumnRelationshipInformations = new List <ColumnRelationshipInformation>();
            relationshipProperties.ColumnRelationshipInformations.Add(new ColumnRelationshipInformation(instance.FromEntityAttribute, instance.ToEntityAttribute));

            return(new RelationshipEntity
            {
                Name = relationshipName,
                Properties = relationshipProperties,
                Type = SASEntityType.RELATIONSHIP
            });
        }
Пример #3
0
        public void ToolMouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.xInitial = e.X;
            this.yInitial = e.Y;

            if (e.Button == MouseButtons.Left && canvas != null)
            {
                canvas.DeselectAllObjects();
                selectedObject = canvas.SelectObjectAt(e.X, e.Y);

                if (selectedObject != null)
                {
                    if (selectedObject is Vertex)
                    {
                        Vertex          objectTerpilih = (Vertex)selectedObject;
                        Form            main           = Form.ActiveForm;
                        ClassProperties fm             = new ClassProperties(canvas, objectTerpilih, main);
                        main.Enabled  = false;
                        fm.Text       = "Class Properties";
                        fm.ControlBox = false;
                        fm.Show();
                    }

                    else if (selectedObject is Edge)
                    {
                        Edge objectTerpilih       = (Edge)selectedObject;
                        Form main                 = Form.ActiveForm;
                        RelationshipProperties fm = new RelationshipProperties(canvas, objectTerpilih, main);
                        main.Enabled  = false;
                        fm.Text       = "Relationship Properties";
                        fm.ControlBox = false;
                        fm.Show();
                    }
                    id_object = selectedObject.ID;
                }
            }
        }