Example #1
0
        public ActionResult FindRoles(GraphViewModel graphViewModel)
        {
            try
            {
                if (graphViewModel.Graph.Edges.Count != 0 && graphViewModel.Graph.GraphSet.Count == 0)
                {
                    foreach (Edge <UserDto> edge in graphViewModel.Graph.Edges)
                    {
                        graphViewModel.Graph.CreateGraphSet(edge);
                    }
                }

                FetchItemServiceResponse <Graph <UserDto> > response = _graphService.DetectRolesInGraph(graphViewModel.Graph);

                if (response.Succeeded)
                {
                    graphViewModel.Graph = response.Item;
                    FetchItemServiceResponse <SSRMRolesDto> ssrmRolesCounts = _graphService.FetchSSRMRolesCounts(graphViewModel.Graph);
                    graphViewModel.SsrmRolesDto = ssrmRolesCounts.Item;

                    List <NodeDto> nodes = graphViewModel.Graph.Nodes.Select(x => new NodeDto()
                    {
                        id    = x.Id,
                        label = x.NodeElement.Name,
                        group = (graphViewModel.GraphDto.nodes.First(y => y.id == x.Id).group),
                        title = $"Node degree: {x.Degree}",
                        size  = GetNodeSizeBasedOnRole(x),
                        shape = (graphViewModel.GraphDto.nodes.First(y => y.id == x.Id).shape)
                    }).ToList();
                    List <EdgeDto> edges = graphViewModel.Graph.Edges.Select(x => new EdgeDto()
                    {
                        from = x.Node1.Id, to = x.Node2.Id
                    }).ToList();

                    if (nodes.FirstOrDefault(x => x.id == graphViewModel.SelectedEgoId) != null)
                    {
                        nodes.First(x => x.id == graphViewModel.SelectedEgoId).size = 25;
                    }

                    foreach (Node <UserDto> node in graphViewModel.Graph.Nodes.Where(x => x.Role != 0))
                    {
                        nodes.First(x => x.id == node.Id).shape = GetNodeShapeBasedOnRole(node);
                    }
                    graphViewModel.Graph.SetCommunityNodes();
                    GraphDto graphDto = new GraphDto
                    {
                        nodes = nodes,
                        edges = edges
                    };
                    graphViewModel.RolesDetected = true;
                    graphViewModel.GraphDto      = graphDto;
                }
            }
            catch (Exception e)
            {
                return(new HttpStatusCodeResult(500, e.Message));
            }
            return(View("GraphView_partial", graphViewModel));
        }