private void PopulateRoles() { List <SecurityRole> MyEntitys = new List <SecurityRole>(); WorkAsync( new WorkAsyncInfo { Message = "Retrieving Security Roles", Work = (w, e) => { MyEntitys = GetSecurityRoles(); MyEntitys.Sort((p, q) => p.Name.CompareTo(q.Name)); SecurityRole Select = new SecurityRole(); Select.Name = "--Select--"; Select.RoldId = Guid.Empty; MyEntitys.Insert(0, Select); }, ProgressChanged = e => SetWorkingMessage(e.UserState.ToString()), PostWorkCallBack = e => { drp_roles.DataSource = null; drp_roles.Items.Clear(); drp_roles.DataSource = MyEntitys; drp_roles.DisplayMember = "Name"; drp_roles.ValueMember = "RoldId"; grdview_role.DataSource = null; grdview_misRole.DataSource = null; } }); }
private void GetRole(SecurityRole seletectRole) { WorkAsync( new WorkAsyncInfo { Message = "Retrieving Role Detail", Work = (w, e) => { var priv = RolePrivileges(seletectRole); e.Result = priv; //MyEntitys = Helper.getSecurityRole(); //MyEntitys.Sort((p, q) => p.Name.CompareTo(q.Name)); //SecurityRole Select = new SecurityRole(); //Select.Name = "--Select--"; //Select.RoldId = Guid.Empty; //MyEntitys.Insert(0, Select); }, ProgressChanged = e => SetWorkingMessage(e.UserState.ToString()), PostWorkCallBack = e => { PrivilegeSets = e.Result as List <PrivilegeSet>; grdview_role.DataSource = PrivilegeSets; InitTableGrid(); grdview_misRole.DataSource = MisPrivilegeSets; InitMiscGrid(); } }); }
private void drp_roles_SelectedIndexChanged(object sender, EventArgs e) { if (drp_roles.SelectedIndex > 0) { //GetRole((SecurityRole) drp_roles.SelectedItem); grdview_role.DataSource = null; SecurityRole entity = (SecurityRole)drp_roles.SelectedItem; ExecuteMethod(GetRole, entity); } }
private void ChkLocalised_CheckedChanged(object sender, EventArgs e) { roleSettings.DisplayNames = chkLocalised.Checked; if (drp_roles.SelectedIndex > 0) { grdview_role.DataSource = null; SecurityRole entity = (SecurityRole)drp_roles.SelectedItem; ExecuteMethod(GetRole, entity); } }
private object RolePrivileges(SecurityRole selectedRole) { EntityCollection returnCollection; var privileges = new List <PrivilegeSet>(); MisPrivilegeSets = new List <MisPrivilegeSet>(); int fetchCount = 5000; // Initialize the page number. int pageNumber = 1; // Initialize the number of records. string pagingCookie = null; string fetchXML = "<fetch returntotalrecordcount='true' >" + " <entity name='roleprivileges' >" + " <attribute name='privilegedepthmask' />" + " <link-entity name='role' from='roleid' to='roleid' alias='role' >" + " <attribute name='name' />" + " <filter>" + " <condition attribute='name' operator='eq' value='" + selectedRole.Name.Replace("&", "&").Replace("\"", """).Replace("'", "'").Replace("<", "<").Replace(">", ">") + "' />" + " </filter>" + " </link-entity>" + " <link-entity name='privilegeobjecttypecodes' from='privilegeid' to='privilegeid' alias='objecttype' >" + " <attribute name='objecttypecode' />" + " </link-entity>" + " <link-entity name='privilege' from='privilegeid' to='privilegeid' alias='privilege' >" + " <attribute name='accessright' alias='AccessRight' />" + " <attribute name='name' />" + "<attribute name = 'canbeentityreference' />" + " </link-entity>" + " </entity>" + "</fetch>"; while (true) { // Build fetchXml string with the placeholders. string xml = CreateXml(fetchXML, pagingCookie, pageNumber, fetchCount); // Execute the fetch query and get the xml result. RetrieveMultipleRequest fetchRequest1 = new RetrieveMultipleRequest { Query = new FetchExpression(xml) }; returnCollection = ((RetrieveMultipleResponse)Service.Execute(fetchRequest1)).EntityCollection; // Check for morerecords, if it returns 1. if (returnCollection.MoreRecords) { // Increment the page number to retrieve the next page. pageNumber++; // Set the paging cookie to the paging cookie returned from current results. pagingCookie = returnCollection.PagingCookie; } else { // If no more records in the result nodes, exit the loop. break; } } foreach (Entity ent in returnCollection.Entities) { var logicalName = ((AliasedValue)ent.Attributes["objecttype.objecttypecode"]).Value.ToString(); var isEntity = true; if (ent.Attributes.Contains("privilege.canbeentityreference")) { isEntity = (bool)((AliasedValue)ent.Attributes["privilege.canbeentityreference"]).Value; } var priName = ((AliasedValue)ent.Attributes["privilege.name"]).Value.ToString(); if (logicalName == "activitypointer") { AddPermission(ent, privileges); } else if (TableExlusionList.Contains(logicalName)) { } // else if (CustomisationList.Contains(logicalName)) AddPermission(ent, "Customization"); else if (PrvExclusionList.Contains(priName)) { } else if (TablePrefixes.Any(tp => priName.Contains(tp))) { AddPermission(ent, privileges); } else if (!isEntity) // not an entity { AddMiscPriv(ent); } else { AddPermission(ent, privileges); } } privileges.Sort(new PrivilegeComparer(SortOrder.Ascending)); return(privileges); }