Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }