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);
                    }
                }
            }
        }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["EntityToken"] == null)
        {
            RelationshipGraphHolder.Controls.Add(new LiteralControl("No entity token.... nothing to do...."));

            return;
        }

        string serializedEntityToken = Request.QueryString["EntityToken"];

        EntityToken entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken);
        //Composite.Core.WebClient.ElementInformation elementInformation = ElementInformationSerializer.Deserialize(serializedEntityToken);

        RelationshipGraph graph = new RelationshipGraph(entityToken, RelationshipGraphSearchOption.Both);

        foreach (RelationshipGraphLevel level in graph.Levels)
        {
            if (level.AllEntities.Count() != 0)
            {
                RelationshipGraphHolder.Controls.Add(new LiteralControl(new XElement("h2", string.Format("Level {0}", level.Level)).ToString()));
            }

            foreach (EntityToken token in level.Entities)
            {
                PrettyPrintEntityToken(token, "red");
            }

            foreach (EntityToken token in level.HookedEntities)
            {
                PrettyPrintEntityToken(token, "green");
            }
        }
    }
Example #3
0
        /// <summary>
        /// Posts refresh messages to the ancestors of the specified entityToken
        /// </summary>
        /// <param name="childEntityToken"></param>
        /// <param name="parentLevel">1 means the first parent, 2 means the second, etc.</param>
        public void PostRefreshMessages(EntityToken childEntityToken, int parentLevel = 1)
        {
            Verify.ArgumentNotNull(childEntityToken, "childEntityToken");

            if (_postRefreshMessagesCalled)
            {
                throw new InvalidOperationException("Only one PostRefreshMessages call is allowed");
            }

            _postRefreshMessagesCalled = true;

            RelationshipGraph relationshipGraph = new RelationshipGraph(childEntityToken, RelationshipGraphSearchOption.Both);

            var levels = relationshipGraph.Levels.Evaluate();

            if (levels.Count <= parentLevel)
            {
                return;
            }

            RelationshipGraphLevel relationshipGraphLevel = levels.ElementAt(parentLevel);

            IManagementConsoleMessageService messageService = _flowControllerServicesContainer.GetService<IManagementConsoleMessageService>();

            foreach (EntityToken entityToken in relationshipGraphLevel.AllEntities)
            {
                messageService.RefreshTreeSection(entityToken);
                Log.LogVerbose(this.GetType().Name, "Refreshing EntityToken: Type = {0}, Source = {1}, Id = {2}, EntityTokenType = {3}", entityToken.Type, entityToken.Source, entityToken.Id, entityToken.GetType());
            }
        }
Example #4
0
        public static IEnumerable <EntityToken> FindEntityTokens(RelationshipGraph beforeGraph, bool skipBottemNodes)
        {
            if (beforeGraph == null)
            {
                throw new ArgumentNullException("beforeGraph");
            }

            List <EntityToken> foundEntityTokens = new List <EntityToken>();

            foreach (RelationshipGraphNode node in beforeGraph.BottomNodes)
            {
                if (skipBottemNodes)
                {
                    foreach (RelationshipGraphNode parentNode in node.ParentNodes)
                    {
                        FindExistingParents(parentNode, foundEntityTokens);
                    }
                }
                else
                {
                    FindExistingParents(node, foundEntityTokens);
                }
            }

            return(foundEntityTokens);
        }
        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);
                    }
                }
            }
        }
Example #6
0
        /// <exclude />
        public DeleteTreeRefresher(EntityToken beforeDeleteEntityToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            Verify.ArgumentNotNull(beforeDeleteEntityToken, "beforeDeleteEntityToken");
            Verify.ArgumentNotNull(flowControllerServicesContainer, "flowControllerServicesContainer");

            _beforeGraph = new RelationshipGraph(beforeDeleteEntityToken, RelationshipGraphSearchOption.Both);
            _flowControllerServicesContainer = flowControllerServicesContainer;            
        }
Example #7
0
        /// <exclude />
        public AddNewTreeRefresher(EntityToken parentEntityToken, FlowControllerServicesContainer flowControllerServicesContainer)
        {
            Verify.ArgumentNotNull(parentEntityToken, "parentEntityToken");
            Verify.ArgumentNotNull(flowControllerServicesContainer, "flowControllerServicesContainer");

            _beforeGraph = new RelationshipGraph(parentEntityToken, RelationshipGraphSearchOption.Both, false, false);
            _flowControllerServicesContainer = flowControllerServicesContainer;
        }
Example #8
0
        /// <exclude />
        public void PostRefreshMesseges(EntityToken newChildEntityToken)
        {
            Verify.ArgumentNotNull(newChildEntityToken, "newChildEntityToken");
            Verify.That(!_postRefreshMessegesCalled, "Only one PostRefreshMesseges call is allowed");

            _postRefreshMessegesCalled = true;

            _afterGraph = new RelationshipGraph(newChildEntityToken, RelationshipGraphSearchOption.Both, false, false);

            IManagementConsoleMessageService messageService = _flowControllerServicesContainer.GetService<IManagementConsoleMessageService>();

            foreach (EntityToken entityToken in RefreshBeforeAfterEntityTokenFinder.FindEntityTokens(_beforeGraph, _afterGraph))
            {
                messageService.RefreshTreeSection(entityToken);
                Log.LogVerbose("AddNewTreeRefresher", string.Format("Refreshing EntityToken: Type = {0}, Source = {1}, Id = {2}, EntityTokenType = {3}", entityToken.Type, entityToken.Source, entityToken.Id, entityToken.GetType()));
            }
        }
Example #9
0
        /// <exclude />
        public void PostRefreshMessages(EntityToken afterUpdateEntityToken)
        {
            if (_postRefreshMessagesCalled)
            {
                throw new InvalidOperationException("Only one PostRefreshMessages call is allowed");
            }

            _postRefreshMessagesCalled = true;

            _afterGraph = new RelationshipGraph(afterUpdateEntityToken, RelationshipGraphSearchOption.Both, false, false);

            IManagementConsoleMessageService messageService = _flowControllerServicesContainer.GetService<IManagementConsoleMessageService>();

            foreach (EntityToken entityToken in RefreshBeforeAfterEntityTokenFinder.FindEntityTokens(_beforeGraph, _afterGraph))
            {
                messageService.RefreshTreeSection(entityToken);
                Log.LogVerbose(this.GetType().Name, "Refreshing EntityToken: Type = {0}, Source = {1}, Id = {2}, EntityTokenType = {3}", entityToken.Type, entityToken.Source, entityToken.Id, entityToken.GetType());
            }
        }
Example #10
0
        /// <summary>
        /// This uses a merged result of user permissions and user group permissions
        /// </summary>
        /// <param name="userToken"></param>
        /// <param name="entityToken"></param>
        /// <param name="userPermissionDefinitions"></param>
        /// <param name="userGroupPermissionDefinitions"></param>
        /// <returns></returns>
        public static bool IsSubBrachContainingPermissionTypes(UserToken userToken, EntityToken entityToken, IEnumerable <UserPermissionDefinition> userPermissionDefinitions, IEnumerable <UserGroupPermissionDefinition> userGroupPermissionDefinitions)
        {
            Verify.ArgumentNotNull(userToken, "userToken");
            Verify.ArgumentNotNull(entityToken, "entityToken");

            IEnumerable <PermissionType> permissionTypes = GetCurrentPermissionTypes(userToken, entityToken, userPermissionDefinitions, userGroupPermissionDefinitions);

            if (permissionTypes.Any())
            {
                return(true);
            }

            // User permissions
            foreach (UserPermissionDefinition userPermissionDefinition in userPermissionDefinitions)
            {
                if (!userPermissionDefinition.PermissionTypes.Contains(PermissionType.ClearPermissions))
                {
                    var graph = new RelationshipGraph(userPermissionDefinition.EntityToken, RelationshipGraphSearchOption.Both, true);

                    if (graph.Levels.Any(level => level.AllEntities.Contains(entityToken)))
                    {
                        return(true);
                    }
                }
            }

            // User group permissions
            foreach (UserGroupPermissionDefinition userGroupPermissionDefinition in userGroupPermissionDefinitions)
            {
                if (!userGroupPermissionDefinition.PermissionTypes.Contains(PermissionType.ClearPermissions))
                {
                    var graph = new RelationshipGraph(userGroupPermissionDefinition.EntityToken, RelationshipGraphSearchOption.Both, true);

                    if (graph.Levels.Any(level => level.AllEntities.Contains(entityToken)))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #11
0
        public static List<EntityToken> GetAllParents(EntityToken entityToken, int levelCount)
        {
            RelationshipGraph graph = new RelationshipGraph(entityToken, RelationshipGraphSearchOption.Both, true);

            List<EntityToken> tokens = new List<EntityToken>();

            int currentLevel = 0;
            foreach (RelationshipGraphLevel level in graph.Levels)
            {
                if (currentLevel > levelCount)
                {
                    break;
                }
                else if ((currentLevel > 0) && (currentLevel <= levelCount))
                {
                    tokens.AddRange(level.AllEntities);
                }
                    
                currentLevel++;
            }

            return tokens;
        }
        public static IEnumerable<EntityToken> FindEntityTokens(RelationshipGraph beforeGraph, bool skipBottemNodes)
        {
            if (beforeGraph == null) throw new ArgumentNullException("beforeGraph");

            List<EntityToken> foundEntityTokens = new List<EntityToken>();

            foreach (RelationshipGraphNode node in beforeGraph.BottomNodes)
            {
                if (skipBottemNodes)
                {
                    foreach (RelationshipGraphNode parentNode in node.ParentNodes)
                    {
                        FindExistingParents(parentNode, foundEntityTokens);
                    }
                }
                else
                {
                    FindExistingParents(node, foundEntityTokens);
                }
            }

            return foundEntityTokens;
        }
        public static IEnumerable <EntityToken> FindEntityTokens(RelationshipGraph beforeGraph, RelationshipGraph afterGraph)
        {
            Verify.ArgumentNotNull(beforeGraph, "beforeGraph");
            Verify.ArgumentNotNull(afterGraph, "afterGraph");

            var nodes = new List <RelationshipGraphNode>();

            FindNodes(beforeGraph, afterGraph, nodes);
            FindNodes(afterGraph, beforeGraph, nodes);

            if (nodes.Count > 1)
            {
                nodes = nodes.Where(n => n.ParentNodes.Any()).ToList(); // Ignoring root node
                nodes = FilterNodes(nodes);
            }

            foreach (RelationshipGraphNode node in nodes)
            {
                foreach (RelationshipGraphNode parentNode in node.ParentNodes)
                {
                    yield return(parentNode.EntityToken);
                }
            }
        }
        public static IEnumerable<EntityToken> FindEntityTokens(RelationshipGraph beforeGraph, RelationshipGraph afterGraph)
        {
            Verify.ArgumentNotNull(beforeGraph, "beforeGraph");
            Verify.ArgumentNotNull(afterGraph, "afterGraph");

            var nodes = new List<RelationshipGraphNode>();

            FindNodes(beforeGraph, afterGraph, nodes);
            FindNodes(afterGraph, beforeGraph, nodes);

            if (nodes.Count > 1)
            {
                nodes = nodes.Where(n => n.ParentNodes.Any()).ToList(); // Ignoring root node
                nodes = FilterNodes(nodes); 
            }

            foreach (RelationshipGraphNode node in nodes)
            {
                foreach (RelationshipGraphNode parentNode in node.ParentNodes)
                {
                    yield return parentNode.EntityToken;
                }
            }
        }
Example #15
0
        public static List <EntityToken> GetAllParents(EntityToken entityToken, int levelCount)
        {
            RelationshipGraph graph = new RelationshipGraph(entityToken, RelationshipGraphSearchOption.Both, true);

            List <EntityToken> tokens = new List <EntityToken>();

            int currentLevel = 0;

            foreach (RelationshipGraphLevel level in graph.Levels)
            {
                if (currentLevel > levelCount)
                {
                    break;
                }
                else if ((currentLevel > 0) && (currentLevel <= levelCount))
                {
                    tokens.AddRange(level.AllEntities);
                }

                currentLevel++;
            }

            return(tokens);
        }
Example #16
0
 public static IEnumerable <EntityToken> FindEntityTokens(RelationshipGraph beforeGraph)
 {
     return(FindEntityTokens(beforeGraph, false));
 }
Example #17
0
        /// <summary>
        /// This uses a merged result of user permissions and user group permissions
        /// </summary>
        /// <param name="userToken"></param>
        /// <param name="entityToken"></param>
        /// <param name="userPermissionDefinitions"></param>
        /// <param name="userGroupPermissionDefinitions"></param>
        /// <returns></returns>
        public static bool IsSubBrachContainingPermissionTypes(UserToken userToken, EntityToken entityToken, IEnumerable<UserPermissionDefinition> userPermissionDefinitions, IEnumerable<UserGroupPermissionDefinition> userGroupPermissionDefinitions)
        {
            Verify.ArgumentNotNull(userToken, "userToken");
            Verify.ArgumentNotNull(entityToken, "entityToken");

            IEnumerable<PermissionType> permissionTypes = GetCurrentPermissionTypes(userToken, entityToken, userPermissionDefinitions, userGroupPermissionDefinitions);

            if (permissionTypes.Any())
            {
                return true;
            }

            // User permissions
            foreach (UserPermissionDefinition userPermissionDefinition in userPermissionDefinitions)
            {
                if (!userPermissionDefinition.PermissionTypes.Contains(PermissionType.ClearPermissions))
                {
                    var graph = new RelationshipGraph(userPermissionDefinition.EntityToken, RelationshipGraphSearchOption.Both, true);

                    if (graph.Levels.Any(level => level.AllEntities.Contains(entityToken)))
                    {
                        return true;
                    }
                }
            }

            // User group permissions
            foreach (UserGroupPermissionDefinition userGroupPermissionDefinition in userGroupPermissionDefinitions)
            {
                if (!userGroupPermissionDefinition.PermissionTypes.Contains(PermissionType.ClearPermissions))
                {
                    var graph = new RelationshipGraph(userGroupPermissionDefinition.EntityToken, RelationshipGraphSearchOption.Both, true);

                    if (graph.Levels.Any(level => level.AllEntities.Contains(entityToken)))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
 public static IEnumerable<EntityToken> FindEntityTokens(RelationshipGraph beforeGraph)
 {
     return FindEntityTokens(beforeGraph, false);
 }