/// <exclude />
        public RelationshipGraph(EntityToken sourceEntityToken, RelationshipGraphSearchOption searchOption, bool lazyEvaluation, bool excludeReoccuringNodes)
        {
            _excludeReoccuringNodes = excludeReoccuringNodes;

            Verify.ArgumentNotNull(sourceEntityToken, "sourceEntityToken");

            _searchOption = searchOption;

            RelationshipGraphNode node = new RelationshipGraphNode(sourceEntityToken, 0, RelationshipGraphNodeType.Entity);

            _levels.Add(0, new List <RelationshipGraphNode> {
                node
            });

            string userName = UserValidationFacade.IsLoggedIn() ? UserSettings.Username : null;

            ExpandNextLevel(userName);

            if (lazyEvaluation == false)
            {
                while (_moreLevelsToExpend)
                {
                    ExpandNextLevel(userName);
                }
            }
        }
        private static void FindNodes(RelationshipGraph leftGraph, RelationshipGraph rightGraph, List <RelationshipGraphNode> foundNodes)
        {
            foreach (RelationshipGraphNode leftNode in leftGraph.TopNodes)
            {
                RelationshipGraphNode currentNode = null;

                foreach (RelationshipGraphNode rightNode in rightGraph.TopNodes)
                {
                    RelationshipGraphNode foundNode = FindNode(leftNode, rightNode, null);

                    if (foundNode != null)
                    {
                        if (currentNode == null || currentNode.Level > foundNode.Level)
                        {
                            currentNode = foundNode;
                        }
                    }
                }

                if (currentNode != null)
                {
                    if (foundNodes.Find(node => node.EntityToken.Equals(currentNode.EntityToken)) == null)
                    {
                        foundNodes.Add(currentNode);
                    }
                }
            }
        }
        private static RelationshipGraphNode FindNode(RelationshipGraphNode leftNode, RelationshipGraphNode rightNode, RelationshipGraphNode lastLeftNode)
        {
            // Searched for the first node in "leftNode" chain which isn't present in "rightNode" chain
            // leftNode  -> A -> B -> C -> D -> ....
            // rightNode -> A -> B -> C -> E -> ....
            // Result: D;

            // leftNode  -> A -> B -> C -> D
            // rightNode -> A -> B -> C -> D -> ....
            // Result: D;

            // leftNode  -> A -> B -> C -> D -> ....
            // rightNode -> A -> B -> C -> D
            // Result: D;

            // leftNode  -> A -> B -> C -> D
            // rightNode -> A -> B -> C -> D
            // Result: D;

            if (!leftNode.EntityToken.Equals(rightNode.EntityToken))
            {
                return(lastLeftNode);
            }

            if (leftNode.ChildNode != null && rightNode.ChildNode != null)
            {
                return(FindNode(leftNode.ChildNode, rightNode.ChildNode, leftNode));
            }

            return(leftNode);
        }
        private static RelationshipGraphNode FindNode(RelationshipGraphNode leftNode, RelationshipGraphNode rightNode, RelationshipGraphNode lastLeftNode)
        {
            // Searched for the first node in "leftNode" chain which isn't present in "rightNode" chain
            // leftNode  -> A -> B -> C -> D -> ....
            // rightNode -> A -> B -> C -> E -> ....
            // Result: D;

            // leftNode  -> A -> B -> C -> D
            // rightNode -> A -> B -> C -> D -> ....
            // Result: D;

            // leftNode  -> A -> B -> C -> D -> ....
            // rightNode -> A -> B -> C -> D 
            // Result: D;

            // leftNode  -> A -> B -> C -> D
            // rightNode -> A -> B -> C -> D 
            // Result: D;

            if (!leftNode.EntityToken.Equals(rightNode.EntityToken))
            {
                return lastLeftNode; 
            }
            
            if (leftNode.ChildNode != null && rightNode.ChildNode != null)
            {
                return FindNode(leftNode.ChildNode, rightNode.ChildNode, leftNode);
            }

            return leftNode;
        }
        private static bool IsParent(RelationshipGraphNode possibleChildNode, RelationshipGraphNode possibleParentNode)
        {
            foreach (RelationshipGraphNode parentNode in possibleChildNode.ParentNodes)
            {
                if (parentNode.EntityToken.Equals(possibleParentNode.EntityToken) ||
                    IsParent(parentNode, possibleParentNode))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #6
0
 private static void FindExistingParents(RelationshipGraphNode node, List <EntityToken> foundEntityTokens)
 {
     if ((SecurityAncestorFacade.GetParents(node.EntityToken) != null) ||
         (HookingFacade.GetHookies(node.EntityToken) != null))
     {
         if (foundEntityTokens.Find(et => et.GetHashCode() == node.EntityToken.GetHashCode()) == null)
         {
             foundEntityTokens.Add(node.EntityToken);
         }
     }
     else
     {
         foreach (RelationshipGraphNode parentNode in node.ParentNodes)
         {
             FindExistingParents(parentNode, foundEntityTokens);
         }
     }
 }
 private static void FindExistingParents(RelationshipGraphNode node, List<EntityToken> foundEntityTokens)
 {
     if ((SecurityAncestorFacade.GetParents(node.EntityToken) != null) ||
         (HookingFacade.GetHookies(node.EntityToken) != null))
     {
         if (foundEntityTokens.Find(et => et.GetHashCode() == node.EntityToken.GetHashCode()) == null)
         {
             foundEntityTokens.Add(node.EntityToken);
         }
     }
     else
     {
         foreach (RelationshipGraphNode parentNode in node.ParentNodes)
         {
             FindExistingParents(parentNode, foundEntityTokens);
         }
     }
 }
        private void AddNewParentEntityTokens(RelationshipGraphNode childNode, IEnumerable <EntityToken> parents, RelationshipGraphNodeType nodeType, int levelNumber)
        {
            int newLevelNumber = levelNumber + 1;

            List <RelationshipGraphNode> levelNodes;

            if (!_levels.TryGetValue(newLevelNumber, out levelNodes))
            {
                levelNodes = new List <RelationshipGraphNode>();
                _levels.Add(newLevelNumber, levelNodes);
            }


            foreach (EntityToken parent in parents)
            {
                if (parent == null)
                {
                    continue;
                }

                if (_visitedEntityTokens.Contains(parent))
                {
                    if (_excludeReoccuringNodes)
                    {
                        continue; // We have already visited this entity token, no new information here
                    }
                }
                else
                {
                    _visitedEntityTokens.Add(parent);
                }


                var parentNode = new RelationshipGraphNode(parent, newLevelNumber, nodeType);

                levelNodes.Add(parentNode);

                childNode.ParentNodes.Add(parentNode);
                parentNode.ChildNode = childNode;

                _moreLevelsToExpend = true;
            }
        }
        /// <exclude />
        public RelationshipGraph(EntityToken sourceEntityToken, RelationshipGraphSearchOption searchOption, bool lazyEvaluation, bool excludeReoccuringNodes)
        {
            _excludeReoccuringNodes = excludeReoccuringNodes;

            Verify.ArgumentNotNull(sourceEntityToken, "sourceEntityToken");

            _searchOption = searchOption;

            RelationshipGraphNode node = new RelationshipGraphNode(sourceEntityToken, 0, RelationshipGraphNodeType.Entity);
            _levels.Add(0, new List<RelationshipGraphNode> { node });

            string userName = UserValidationFacade.IsLoggedIn() ? UserSettings.Username : null;

            ExpandNextLevel(userName);

            if (lazyEvaluation == false)
            {
                while (_moreLevelsToExpend)
                {
                    ExpandNextLevel(userName);
                }
            }
        }
        private void AddNewParentEntityTokens(RelationshipGraphNode childNode, IEnumerable<EntityToken> parents, RelationshipGraphNodeType nodeType, int levelNumber)
        {
            int newLevelNumber = levelNumber + 1;

            List<RelationshipGraphNode> levelNodes;
            if (!_levels.TryGetValue(newLevelNumber, out levelNodes))
            {
                levelNodes = new List<RelationshipGraphNode>();
                _levels.Add(newLevelNumber, levelNodes);
            }

            foreach (EntityToken parent in parents)
            {
                if(parent == null)
                {
                    continue;
                }

                if (_visitedEntityTokens.Contains(parent))
                {
                    if (_excludeReoccuringNodes)
                    {
                        continue; // We have already visisted this entity token, no new information here
                    }
                }
                else
                {
                    _visitedEntityTokens.Add(parent);
                }

                var parentNode = new RelationshipGraphNode(parent, newLevelNumber, nodeType);

                levelNodes.Add(parentNode);

                childNode.ParentNodes.Add(parentNode);
                parentNode.ChildNode = childNode;

                _moreLevelsToExpend = true;
            }
        }
        private static bool IsParent(RelationshipGraphNode possibleChildNode, RelationshipGraphNode possibleParentNode)
        {
            foreach (RelationshipGraphNode parentNode in possibleChildNode.ParentNodes)
            {
                if (parentNode.EntityToken.Equals(possibleParentNode.EntityToken) 
                    || IsParent(parentNode, possibleParentNode))
                {
                    return true;
                }
            }

            return false;
        }