コード例 #1
0
        /// <summary>
        /// Gets all the relationships for this submodel
        /// </summary>
        /// <param name="submodel"></param>
        /// <returns></returns>
        public IEnumerable <Relationship> GetRelationships(Submodel submodel)
        {
            if (Model == null)
            {
                throw new InvalidOperationException("Cannot get relationship of nodes when model is not set.");
            }

            return(submodel.Relationships.Where(item => item.Source.Label == Label || item.Target?.Label == Label));
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the inherited relationship for this submodel
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Dictionary <RelationshipDirection, List <Relationship> > GetInheritedRelationships(Submodel model)
        {
            Dictionary <RelationshipDirection, List <Relationship> > result = new Dictionary <RelationshipDirection, List <Schemas.Relationship> >();

            result.Add(RelationshipDirection.In, new List <Schemas.Relationship>());
            result.Add(RelationshipDirection.Out, new List <Schemas.Relationship>());

            Entity current = ParentEntity;

            while (current != null)
            {
                result[RelationshipDirection.In].AddRange(model.Relationships.Where(item => item.Source.Label == current.Label));
                result[RelationshipDirection.Out].AddRange(model.Relationships.Where(item => item.Target?.Label == current.Label));

                current = current.ParentEntity;
            }

            return(result);
        }