/// <summary> /// Fills the list of entities /// </summary> private void FillEntities() { // Displays entities if (entityCache == null) { MessageBox.Show(this, "You are not connected to an organization, so it is not possible to display a list of entities\n\nPlease use menu \"More actions\" to load entities and web resources", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); Close(); } foreach (var emd in entityCache) { if (emd.DisplayName.UserLocalizedLabel != null) { var item = new ListViewItem { Text = emd.DisplayName.UserLocalizedLabel.Label, Tag = emd }; ListViewDelegates.AddItem(lvSelectedEntities, item); } } // Enables controls ListViewDelegates.Sort(lvSelectedEntities); ListViewDelegates.SetEnableState(lvSelectedEntities, true); CommonDelegates.SetEnableState(btnCancel, true); CommonDelegates.SetEnableState(btnValidate, true); }
private void FillImageList() { ListViewDelegates.ClearItems(lstWebResources); if (webResourcesImageCache == null || webResourcesImageCache.Count == 0) { webResourcesImageCache = new List <Entity>(); QueryExpression qe = new QueryExpression("webresource"); ConditionExpression ce = new ConditionExpression(); ce.AttributeName = "webresourcetype"; if (requestedType == (int)WebResourceType.Image) { ce.Operator = ConditionOperator.In; ce.Values.AddRange(5, 6, 7); } else { ce.Operator = ConditionOperator.Equal; ce.Values.Add(requestedType); } qe.Criteria.AddCondition(ce); qe.ColumnSet.AllColumns = true; EntityCollection ec = service.RetrieveMultiple(qe); foreach (Entity webresource in ec.Entities) { webResourcesImageCache.Add(webresource); } } foreach (Entity webresource in webResourcesImageCache) { if (requestedType == 11 && webresource.GetAttributeValue <OptionSetValue>("webresourcetype").Value == 11 || requestedType != 11 && webresource.GetAttributeValue <OptionSetValue>("webresourcetype").Value != 11) { ListViewItem item = new ListViewItem(webresource.Contains("displayname") ? webresource["displayname"].ToString() : "N/A"); item.SubItems.Add(webresource["name"].ToString()); item.Tag = webresource; ListViewDelegates.AddItem(lstWebResources, item); } } ListViewDelegates.Sort(lstWebResources); ListViewDelegates.SetEnableState(lstWebResources, true); CommonDelegates.SetEnableState(btnWebResourcePickerCancel, true); CommonDelegates.SetEnableState(btnWebResourcePickerValidate, true); CommonDelegates.SetEnableState(btnNewResource, true); CommonDelegates.SetEnableState(btnRefresh, true); }
/// <summary> /// Fills the list of entities /// </summary> private void FillEntities() { // Checks the application cache and load it if needed //if (entityCache == null || entityCache.Count == 0) //{ // entityCache = new List<EntityMetadata>(); // var request = new RetrieveAllEntitiesRequest // { // EntityFilters = EntityFilters.Entity // }; // var response = (RetrieveAllEntitiesResponse)SiteMapEditor.service.Execute(request); // foreach (var emd in response.EntityMetadata) // { // SiteMapEditor.entityCache.Add(emd); // } //} // Displays entities foreach (var emd in entityCache) { if ((emd.IsCustomizable.Value || emd.IsManaged.Value == false) && emd.DisplayName.UserLocalizedLabel != null) { var item = new ListViewItem { Text = emd.DisplayName.UserLocalizedLabel.Label, Tag = emd }; ListViewDelegates.AddItem(lvSelectedEntities, item); } } // Enables controls ListViewDelegates.Sort(lvSelectedEntities); ListViewDelegates.SetEnableState(lvSelectedEntities, true); CommonDelegates.SetEnableState(btnCancel, true); CommonDelegates.SetEnableState(btnValidate, true); }
void DoWork() { var filterTerm = txtSearch.Text; IEnumerable <Entity> matchingPrivileges = null; if (filterTerm.Length != 0) { matchingPrivileges = privileges.Where( x => x["name"].ToString().ToLower().IndexOf(filterTerm.ToLower(), StringComparison.Ordinal) >= 0); } else { matchingPrivileges = privileges; } var lviList = new List <ListViewItem>(); var lvgList = new List <ListViewGroup>(); foreach (var privilege in matchingPrivileges) { var groupName = string.Empty; var group = (from entity in entities where entity.Privileges.Any(p => p.PrivilegeId == privilege.Id) select new { entity.LogicalName, entity.DisplayName.UserLocalizedLabel.Label }).FirstOrDefault(); var entitySchemaName = (from entity in entities where entity.Privileges.Any(p => p.Name == privilege["name"].ToString()) select entity.SchemaName).FirstOrDefault(); if (group == null) { if (privilege["name"].ToString().EndsWith("Entity")) { groupName = "Entity"; } else if (privilege["name"].ToString().EndsWith("Attribute")) { groupName = "Attribute"; } else if (privilege["name"].ToString().EndsWith("Relationship")) { groupName = "Relationship"; } else if (privilege["name"].ToString().EndsWith("OptionSet")) { groupName = "OptionSet"; } else { groupName = "_Common"; } } else { if (group.LogicalName == "customeraddress") { groupName = entities.First(x => x.LogicalName == "account").DisplayName.UserLocalizedLabel.Label; } else if (group.LogicalName == "email" || group.LogicalName == "task" || group.LogicalName == "letter" || group.LogicalName == "phonecall" || group.LogicalName == "appointment" || group.LogicalName == "serviceappointment" || group.LogicalName == "campaignresponse" || group.LogicalName == "fax") { groupName = entities.First(x => x.LogicalName == "activitypointer").DisplayName.UserLocalizedLabel.Label; } else { groupName = group.Label; } } var lvGroup = lvgList.FirstOrDefault(f => f.Name == groupName); if (lvGroup == null) { lvgList.Add(new ListViewGroup(groupName, groupName)); } var item = new ListViewItem { Text = privilege["name"].ToString().Remove(0, 3), ImageIndex = 1, Tag = privilege, Group = groupName != null ? lvgList.First(f => f.Name == groupName) : lvgList.First(f => f.Name == "_Common") }; if (entitySchemaName != null) { item.Text = item.Text.Replace(entitySchemaName, ""); } lviList.Add(item); } ListViewDelegates.AddGroupsRange(lvPrivileges, lvgList.ToArray()); ListViewDelegates.AddItemsRange(lvPrivileges, lviList.ToArray()); ListViewDelegates.SortGroup(lvPrivileges, true); ListViewDelegates.Sort(lvPrivileges, true); CommonDelegates.SetEnableState(btnAdd, true); CommonDelegates.SetEnableState(btnRemove, true); }
void DoWork() { var filterTerm = textBox1.Text; IEnumerable <Entity> privileges = rManager.Privileges; if (filterTerm.Length != 0) { privileges = rManager.Privileges.Where( x => x["name"].ToString().ToLower().IndexOf(filterTerm.ToLower(), StringComparison.Ordinal) >= 0); } var items = new List <ListViewItem>(); foreach (var privilege in privileges) { var groupName = string.Empty; var group = (from entity in entities where entity.Privileges.Any(p => p.PrivilegeId == privilege.Id) select new{ entity.LogicalName, entity.DisplayName.UserLocalizedLabel.Label }).FirstOrDefault(); var entitySchemaName = (from entity in entities where entity.Privileges.Any(p => p.Name == privilege["name"].ToString()) select entity.SchemaName).FirstOrDefault(); if (group == null) { if (privilege["name"].ToString().EndsWith("Entity")) { groupName = "Entity"; } else if (privilege["name"].ToString().EndsWith("Attribute")) { groupName = "Attribute"; } else if (privilege["name"].ToString().EndsWith("Relationship")) { groupName = "Relationship"; } else if (privilege["name"].ToString().EndsWith("OptionSet")) { groupName = "OptionSet"; } else { groupName = "_Common"; } } else { if (group.LogicalName == "customeraddress") { groupName = entities.First(x => x.LogicalName == "account").DisplayName.UserLocalizedLabel.Label; } else if (group.LogicalName == "email" || group.LogicalName == "task" || group.LogicalName == "letter" || group.LogicalName == "phonecall" || group.LogicalName == "appointment" || group.LogicalName == "serviceappointment" || group.LogicalName == "campaignresponse" || group.LogicalName == "fax") { groupName = entities.First(x => x.LogicalName == "activitypointer").DisplayName.UserLocalizedLabel.Label; } else { groupName = group.Label; } } if (ListViewDelegates.GetGroup(lvPrivileges, groupName) == null) { ListViewDelegates.AddGroup(lvPrivileges, groupName); } var item = new ListViewItem { Text = privilege["name"].ToString().Remove(0, 3), Tag = privilege, Group = groupName != null ? ListViewDelegates.GetGroup(lvPrivileges, groupName) : ListViewDelegates.GetGroup(lvPrivileges, "_Common") }; if (entitySchemaName != null) { item.Text = item.Text.Replace(entitySchemaName, ""); } items.Add(item); } ListViewDelegates.AddRange(lvPrivileges, items); ListViewDelegates.SortGroup(lvPrivileges, true); ListViewDelegates.Sort(lvPrivileges, true); }
private void DoWork() { var filterTerm = textBox1.Text; IEnumerable <Entity> privileges = rManager.Privileges; if (filterTerm.Length != 0) { privileges = rManager.Privileges.Where( x => x["name"].ToString().ToLower().IndexOf(filterTerm.ToLower(), StringComparison.Ordinal) >= 0); } var items = new List <ListViewItem>(); foreach (var privilege in privileges) { string entitySchemaName = null; var groupName = string.Empty; var entitiesWithPrivilege = (from emd in entities where emd.Privileges.Any(p => p.PrivilegeId == privilege.Id) select emd).ToList(); EntityMetadata entity; if (entitiesWithPrivilege.Count > 0 && entitiesWithPrivilege.Any(g => g.IsActivity.Value)) { entity = entitiesWithPrivilege.FirstOrDefault(g => g.LogicalName == "activitypointer"); entitySchemaName = "Activity"; } else { entity = entitiesWithPrivilege.FirstOrDefault(); if (entity != null) { entitySchemaName = entity.SchemaName; } } if (entity == null) { if (privilege["name"].ToString().EndsWith("Entity")) { groupName = "Entity"; } else if (privilege["name"].ToString().EndsWith("Attribute")) { groupName = "Attribute"; } else if (privilege["name"].ToString().EndsWith("Relationship")) { groupName = "Relationship"; } else if (privilege["name"].ToString().EndsWith("OptionSet")) { groupName = "OptionSet"; } else { groupName = "_Common"; } } else { if (entity.LogicalName == "customeraddress") { groupName = entities.First(x => x.LogicalName == "account").DisplayName.UserLocalizedLabel.Label; } else if (entity.IsActivity.Value || entity.LogicalName == "bulkoperation") { groupName = entities.First(x => x.LogicalName == "activitypointer").DisplayName.UserLocalizedLabel.Label; } else { groupName = entity.DisplayName.UserLocalizedLabel.Label; } } if (ListViewDelegates.GetGroup(lvPrivileges, groupName) == null) { ListViewDelegates.AddGroup(lvPrivileges, groupName); } var item = new ListViewItem { Text = privilege["name"].ToString().Remove(0, 3), Tag = privilege, Group = groupName != null ? ListViewDelegates.GetGroup(lvPrivileges, groupName) : ListViewDelegates.GetGroup(lvPrivileges, "_Common") }; if (entitySchemaName != null) { item.Text = item.Text.Replace(entitySchemaName, ""); } items.Add(item); } ListViewDelegates.AddRange(lvPrivileges, items); ListViewDelegates.SortGroup(lvPrivileges, true); ListViewDelegates.Sort(lvPrivileges, true); }
private void DoWork() { var filterTerm = txtSearch.Text; IEnumerable <Entity> matchingPrivileges; if (filterTerm.Length != 0) { matchingPrivileges = privileges.Where( x => x["name"].ToString().ToLower().IndexOf(filterTerm.ToLower(), StringComparison.Ordinal) >= 0 || entities.Any(e => e.DisplayName?.UserLocalizedLabel?.Label.ToLower().IndexOf(filterTerm.ToLower()) >= 0 && e.Privileges.Any(p => p.PrivilegeId == x.Id))); } else { matchingPrivileges = privileges; } var lviList = new List <ListViewItem>(); var lvgList = new List <ListViewGroup>(); foreach (var privilege in matchingPrivileges) { string entitySchemaName = null; var groupName = string.Empty; var entitiesWithPrivilege = (from emd in entities where emd.Privileges.Any(p => p.PrivilegeId == privilege.Id) select emd).ToList(); EntityMetadata entity; if (entitiesWithPrivilege.Count > 0 && entitiesWithPrivilege.Any(g => g.IsActivity.Value)) { entity = entitiesWithPrivilege.FirstOrDefault(g => g.LogicalName == "activitypointer"); entitySchemaName = "Activity"; } else { entity = entitiesWithPrivilege.FirstOrDefault(); if (entity != null) { entitySchemaName = entity.SchemaName; } } if (entity == null) { if (privilege["name"].ToString().EndsWith("Entity")) { groupName = "Entity"; } else if (privilege["name"].ToString().EndsWith("Attribute")) { groupName = "Attribute"; } else if (privilege["name"].ToString().EndsWith("Relationship")) { groupName = "Relationship"; } else if (privilege["name"].ToString().EndsWith("OptionSet")) { groupName = "OptionSet"; } else { groupName = "_Common"; } } else { if (entity.LogicalName == "customeraddress") { groupName = entities.First(x => x.LogicalName == "account").DisplayName.UserLocalizedLabel.Label; } else if (entity.IsActivity.Value || entity.LogicalName == "bulkoperation") { groupName = entities.First(x => x.LogicalName == "activitypointer").DisplayName.UserLocalizedLabel.Label; } else { groupName = entity.DisplayName.UserLocalizedLabel.Label; } } var lvGroup = lvgList.FirstOrDefault(f => f.Name == groupName); if (lvGroup == null) { lvgList.Add(new ListViewGroup(groupName, groupName)); } var item = new ListViewItem { Text = privilege["name"].ToString().Remove(0, 3), ImageIndex = 1, Tag = privilege, Group = groupName != null ? lvgList.First(f => f.Name == groupName) : lvgList.First(f => f.Name == "_Common") }; if (entitySchemaName != null) { item.Text = item.Text.Replace(entitySchemaName, ""); } lviList.Add(item); } ListViewDelegates.AddGroupsRange(lvPrivileges, lvgList.ToArray()); ListViewDelegates.AddItemsRange(lvPrivileges, lviList.ToArray()); ListViewDelegates.SortGroup(lvPrivileges, true); ListViewDelegates.Sort(lvPrivileges, true); CommonDelegates.SetEnableState(btnAdd, true); CommonDelegates.SetEnableState(btnRemove, true); }