Пример #1
0
        private RelationRepresentation CreateRepresentation(IRelation relation)
        {
            var parentLinkTemplate = GetLinkTemplate(relation.RelationType.ParentObjectType);
            var childLinkTemplate  = GetLinkTemplate(relation.RelationType.ChildObjectType);

            var rep = new RelationRepresentation(RelationLinkTemplate, parentLinkTemplate, childLinkTemplate);

            return(Mapper.Map(relation, rep));
        }
Пример #2
0
 public HttpResponseMessage Post(RelationRepresentation representation)
 {
     try
     {
         var relation = Mapper.Map <IRelation>(representation);
         RelationService.Save(relation);
         return(Request.CreateResponse(HttpStatusCode.OK, CreateRepresentation(relation)));
     }
     catch (ModelValidationException exception)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, exception.Errors));
     }
 }
Пример #3
0
        public HttpResponseMessage Put(int id, RelationRepresentation rel)
        {
            try
            {
                var found = RelationService.GetById(id);
                if (found == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                Mapper.Map(rel, found);
                RelationService.Save(found);

                return(Request.CreateResponse(HttpStatusCode.OK, CreateRepresentation(found)));
            }
            catch (ModelValidationException exception)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, exception.Errors));
            }
        }
Пример #4
0
        private static void RepresentationFragment(this Links component, Dataset dataset, ViewConfig viewConfig)
        {
            BHoMGroup <IBHoMObject> entityGroup = (BHoMGroup <IBHoMObject>)dataset.Data.Find(x => x.Name == "Entities");
            List <IBHoMObject>      entities    = entityGroup.Elements;

            BHoMGroup <IBHoMObject> relationGroup = (BHoMGroup <IBHoMObject>)dataset.Data.Find(x => x.Name == "Relations");
            List <IBHoMObject>      relations     = relationGroup.Elements;

            Gradient gradient = Create.Gradient();

            List <object> colourNames = new List <object>();

            if (component.Colour.Contains("Source."))
            {
                colourNames = Convert.ToDataList(entities.PropertyValue(component.Colour.Replace("Source.", "")));
            }
            if (component.Colour.Contains("Target."))
            {
                colourNames = Convert.ToDataList(entities.PropertyValue(component.Colour.Replace("Target.", "")));
            }
            else
            {
                colourNames = Convert.ToDataList(relations.PropertyValue(component.Colour));
            }

            IScale colourScale = Create.IScale(colourNames, gradient.Markers.Values.Cast <object>().ToList());

            foreach (IBHoMObject obj in relations)
            {
                IBHoMObject start = entities.Find(ent => ent.BHoM_Guid.Equals(obj.PropertyValue(component.Start)));
                IBHoMObject end   = entities.Find(ent => ent.BHoM_Guid.Equals(obj.PropertyValue(component.End)));

                EntityRepresentation startFrag = start.FindFragment <EntityRepresentation>();
                EntityRepresentation endFrag   = end.FindFragment <EntityRepresentation>();

                RelationRepresentation representation = new RelationRepresentation();
                Line line = Geometry.Create.Line(startFrag.OutgoingRelationPoint, endFrag.IncomingRelationPoint);

                representation.Curves.Add(line);

                representation.Curves.AddRange(component.Marker.IMarker(line.End, line.Direction()));
                representation.TextDirection = line.Direction();
                representation.TextPosition  = line.IPointAtLength(line.Length() / 3);

                if (component.Text.Contains("Source."))
                {
                    representation.Text = start.PropertyValue(component.Text.Replace("Source.", "")).ToString();
                }
                else if (component.Text.Contains("Target."))
                {
                    representation.Text = end.PropertyValue(component.Text.Replace("Target.", "")).ToString();
                }
                else
                {
                    representation.Text = obj.PropertyValue(component.Text).ToString();
                }


                if (component.Colour.Contains("Source."))
                {
                    representation.Colour = Convert.ColourFromObject(colourScale.IScale(start.PropertyValue(component.Colour.Replace("Source.", ""))));
                }
                else if (component.Colour.Contains("Target."))
                {
                    representation.Colour = Convert.ColourFromObject(colourScale.IScale(end.PropertyValue(component.Colour.Replace("Target.", ""))));
                }
                else
                {
                    representation.Colour = Convert.ColourFromObject(colourScale.IScale(obj.PropertyValue(component.Colour)));
                }

                obj.Fragments.AddOrReplace(representation);
            }
        }