public String ContextFlow() { String contextid = ""; if (!String.IsNullOrWhiteSpace((String)RouteData.Values["id"])) { contextid = (String)RouteData.Values["id"]; } EnterpriseData ent = (EnterpriseData)Page.Session["enterprise_data"]; FlowData flowData = new FlowData(); Node eNode = flowData.AddNode(ent.Name, 0, 1); using (IAMDatabase db = new IAMDatabase(IAMDatabase.GetWebConnectionString())) { DataTable dtCtx = db.Select("select * from context where enterprise_id = " + ent.Id + (contextid != "" ? " and id = " + contextid : "")); if (dtCtx == null) { return(""); } foreach (DataRow dr in dtCtx.Rows) { Int64 contextID = (Int64)dr["id"]; String cName = "Contexto: " + dr["name"]; Node cNode = flowData.AddNode(cName, 1, 1); flowData.AddConnection(eNode, cNode, ""); Node roleNode = null; /* * DataTable dtRoles1 = DB.Select("select * from [role] e where e.context_id = " + contextID); * if (dtRoles1 != null) * { * roleNode = flowData.AddNode("Perfis", 6, dtRoles1.Rows.Count); * flowData.AddConnection(cNode, roleNode, ""); * * foreach (DataRow drR in dtRoles1.Rows) * { * * Int64 irId = (Int64)drR["id"]; * * Node roleNameNode = flowData.AddNode("Perfil: " + drR["name"].ToString(), 7, 1); * flowData.AddConnection(roleNode, roleNameNode, ""); * * } * }*/ Node userNode = flowData.AddNode("Usuários", 3, 1, true); flowData.AddConnection(cNode, userNode, ""); DataTable dtEntity = db.Select("select count(*) qty from [entity] e where e.context_id = " + contextID); if ((dtEntity == null) || (dtEntity.Rows.Count == 0) || ((Int32)dtEntity.Rows[0]["qty"] == 0)) { Node entNode = flowData.AddNode("Nenhuma entidade vinculada a este contexto", 4, 1, true); flowData.AddConnection(userNode, entNode, ""); } else { String rpEntName = "Entidades"; Node entNode = flowData.AddNode(rpEntName, 4, (Int32)dtEntity.Rows[0]["qty"], true); flowData.AddConnection(userNode, entNode, dtEntity.Rows[0]["qty"] + " entidades"); DataTable dtIdentity = db.Select("select COUNT(distinct i.id) qty from [identity] i inner join entity e on i.entity_id = e.id where e.context_id = " + contextID); if ((dtIdentity == null) || (dtIdentity.Rows.Count == 0)) { Node identNode = flowData.AddNode("Nenhuma identidade vinculado a esta entidade", 4, 1, true); flowData.AddConnection(entNode, identNode, ""); } else { String rpIdentName = "Identidades"; Node identNode = flowData.AddNode(rpIdentName, 5, (Int32)dtIdentity.Rows[0]["qty"], true); flowData.AddConnection(entNode, identNode, dtIdentity.Rows[0]["qty"] + " identidades"); DataTable dtResources = db.Select("select name, qty = (select COUNT(distinct i.id) from resource r1 inner join resource_plugin rp on r1.id = rp.resource_id inner join [identity] i on i.resource_plugin_id = rp.id inner join entity e on i.entity_id = e.id where r1.name = r.name and r1.context_id = r.context_id) from resource r where r.context_id = " + contextID + " group by r.name, r.context_id"); if (dtResources != null) { foreach (DataRow drR in dtResources.Rows) { String resourceName = drR["name"].ToString(); Node resNode = flowData.AddNode(resourceName, 6, (Int32)drR["qty"], true); flowData.AddConnection(identNode, resNode, drR["qty"] + " identidades"); } } } } Node confNode = flowData.AddNode("Configuração", 3, 1, true); flowData.AddConnection(cNode, confNode, ""); DataTable dtProxy = db.Select("select p.id, p.name from resource r inner join proxy p on r.proxy_id = p.id where r.context_id = " + contextID + " group by p.id, p.name order by p.name"); if ((dtProxy == null) || (dtProxy.Rows.Count == 0)) { Node pNode = flowData.AddNode("Nenhuma configuração vinculada a este contexto", 4, 1, true); flowData.AddConnection(confNode, pNode, ""); } else { //Node proxyNode = flowData.AddNode("Proxy", 2, dtProxy.Rows.Count, false); //flowData.AddConnection(cNode, proxyNode, ""); foreach (DataRow drP in dtProxy.Rows) { Int64 pId = (Int64)drP["id"]; Node pNode = flowData.AddNode("Proxy: " + drP["name"], 4, 1, true); flowData.AddConnection(confNode, pNode, ""); DataTable dtResource = db.Select("select r.*, p.name proxy_name from resource r inner join proxy p on r.proxy_id = p.id where r.context_id = " + contextID + " and p.id = " + pId); if (dtResource != null) { foreach (DataRow drR in dtResource.Rows) { Int64 rId = (Int64)drR["id"]; Node rNode = flowData.AddNode("Recurso: " + drR["name"], 5, 1, true); flowData.AddConnection(pNode, rNode, ""); DataTable dtResPlugin = db.Select("select p.name plugin_name, rp.* from resource_plugin rp inner join plugin p on rp.plugin_id = p.id where rp.resource_id = " + rId); if (dtResPlugin != null) { foreach (DataRow drRP in dtResPlugin.Rows) { Int64 rpId = (Int64)drRP["id"]; Node rpNode = flowData.AddNode("Plugin: " + drRP["plugin_name"].ToString(), 6, 1, true); flowData.AddConnection(rNode, rpNode, ""); DataTable dtRoles = db.Select("select r.id, r.name from role r inner join resource_plugin_role rpr on rpr.role_id = r.id where rpr.resource_plugin_id = " + rpId + " group by r.id, r.name"); if (dtRoles != null) { foreach (DataRow drRol in dtRoles.Rows) { String roleName = "Perfil: " + drRol["name"]; //if (roleNode != null) //{ //Node roleNameNode = flowData.Find(roleNode, roleName, 6); Node roleNameNode = flowData.Find(rpNode, roleName, 6); if (roleNameNode == null) { roleNameNode = flowData.AddNode("Perfil: " + drRol["name"].ToString(), 7, 1, true); } if (roleNameNode != null) { flowData.AddConnection(rpNode, roleNameNode, ""); } //Int32 roleNameNodeIndex = flowData.AddNode("Perfil: " + drRol["name"].ToString(), true); //flowData.AddLink(rpNodeIndex, roleNameNodeIndex, 1, ""); //} } } } } } } } } } } return(flowData.ToJson()); }