Пример #1
0
        /// <summary>
        /// Gets all the relationships for this submodel
        /// </summary>
        /// <param name="model"></param>
        /// <param name="direction"></param>
        /// <param name="includeInherited"></param>
        /// <returns></returns>
        public IEnumerable <Relationship> GetRelationships(Submodel model, RelationshipDirection direction, bool includeInherited)
        {
            Func <Relationship, bool> func;

            switch (direction)
            {
            case RelationshipDirection.Out:
                func = RelationshipOut;
                break;

            case RelationshipDirection.Both:
                func = RelationshipBoth;
                break;

            case RelationshipDirection.In:
            default:
                func = RelationshipIn;
                break;
            }

            Dictionary <string, Relationship> relationships = model.Relationships.Where(func).ToDictionary(x => x.Name);

            if (includeInherited == false)
            {
                return(relationships.Select(x => x.Value).ToList());
            }

            Dictionary <RelationshipDirection, List <Relationship> > inheritedPropertyByDirection = GetInheritedRelationships(model);

            foreach (Relationship item in inheritedPropertyByDirection[RelationshipDirection.In])
            {
                if (relationships.ContainsKey(item.Name))
                {
                    continue;
                }

                Relationship relationship = new Relationship(model.Model, (relationship)item.Xml.Clone());
                relationships.Add(relationship.Name, relationship);
                model.CreatedInheritedRelationships.Add(relationship);
            }

            foreach (Relationship item in inheritedPropertyByDirection[RelationshipDirection.Out])
            {
                if (relationships.ContainsKey(item.Name))
                {
                    continue;
                }

                Relationship relationship = new Relationship(model.Model, (relationship)item.Xml.Clone());
                relationships.Add(relationship.Name, relationship);
                model.CreatedInheritedRelationships.Add(relationship);
            }

            return(relationships.Select(x => x.Value).ToList());

            bool RelationshipIn(Relationship item)
            {
                return(item.Source.Label == this.Label);
            }

            bool RelationshipOut(Relationship item)
            {
                return(item.Target?.Label == this.Label);
            }

            bool RelationshipBoth(Relationship item)
            {
                return(item.Source.Label == this.Label || item.Target?.Label == this.Label);
            }
        }
Пример #2
0
 public void RemoveRelationship(Relationship relationship)
 {
     Model.Relationships.Relationship.Remove(relationship);
     relationship.DeleteDrawingEdge(false);
 }