Esempio n. 1
0
        public static People FromIdentities(int[] personIds, bool preserveOrder)
        {
            People set = FromIdentities(personIds);

            if (preserveOrder == false)
            {
                return(set);
            }

            Dictionary <int, Person> lookup = new Dictionary <int, Person>();

            foreach (Person person in set)
            {
                lookup[person.Identity] = person;
            }

            People result = new People();

            foreach (int identity in personIds)
            {
                result.Add(lookup[identity]);
            }

            return(result);
        }
Esempio n. 2
0
        public static People GetActivists(Organization organization, Geography geography)
        {
            var people = new People();

            // Expensive op:
            BasicPersonRole[] basicPersonRoles =
                SwarmDb.GetDatabaseForReading().GetRolesForOrganizationsGeographies(organization.GetTree().Identities,
                                                                                    geography.GetTree().Identities);

            var lookup = new Dictionary <int, bool>();

            foreach (BasicPersonRole basicRole in basicPersonRoles)
            {
                if (basicRole.Type == RoleType.LocalActive || basicRole.Type == RoleType.LocalLead ||
                    basicRole.Type == RoleType.LocalDeputy)
                {
                    if (!lookup.ContainsKey(basicRole.PersonId))
                    {
                        people.Add(Person.FromIdentity(basicRole.PersonId));
                        lookup[basicRole.PersonId] = true;
                    }
                }
            }

            people.Sort();
            return(people);
        }
Esempio n. 3
0
        public static People FromIdentities(int[] personIds)
        {
            if (personIds.Length > 500)
            {
                // If over fivehundred identities are requested, we won't pass the array to
                // SQL Server. Rather, we'll get ALL the people and parse the list ourselves.

                Dictionary <int, bool> lookup = new Dictionary <int, bool>();

                foreach (int key in personIds)
                {
                    lookup[key] = true;
                }

                BasicPerson[] basicArray = SwarmDb.GetDatabaseForReading().GetAllPeople();
                People        result     = new People();

                for (int index = 0; index < basicArray.Length; index++)
                {
                    if (lookup.ContainsKey(basicArray[index].Identity))
                    {
                        result.Add(Person.FromBasic(basicArray[index]));
                    }
                }

                return(result);
            }
            return(People.FromArray(SwarmDb.GetDatabaseForReading().GetPeople(personIds)));
        }
Esempio n. 4
0
        public static People FromSingle (Person person)
        {
            People result = new People();
            result.Add (person);

            return result;
        }
Esempio n. 5
0
        public People GetVisiblePeople(Organization organization)
        {
            People result = new People();

            // First, get all the currently visible people for this org

            Dictionary <RoleType, bool> roleTypeLookup = Authorization.VisibleRolesDictionary;
            Roles orgRoles = Roles.FromOrganization(organization);

            Dictionary <int, bool> personIdLookup = new Dictionary <int, bool>();

            foreach (PersonRole orgRole in orgRoles)
            {
                if (roleTypeLookup.ContainsKey(orgRole.Type))
                {
                    personIdLookup[orgRole.PersonId] = true;
                }
            }

            // Now that we have all the visible people in the org, match them against the current list

            foreach (Person person in this)
            {
                if (personIdLookup.ContainsKey(person.Identity))
                {
                    result.Add(person);
                }
            }

            return(result);
        }
Esempio n. 6
0
        public static People FromSingle(Person person)
        {
            var result = new People();

            result.Add(person);

            return(result);
        }
Esempio n. 7
0
        public static People FromArray(BasicPerson[] personArray)
        {
            People result = new People();

            result.Capacity = personArray.Length * 11 / 10;
            foreach (BasicPerson basic in personArray)
            {
                result.Add(Person.FromBasic(basic));
            }

            return(result);
        }
Esempio n. 8
0
        public static People FromArray(Person[] personArray)
        {
            People result = new People();

            result.Capacity = personArray.Length * 11 / 10;
            foreach (Person person in personArray)
            {
                result.Add(person);
            }

            return(result);
        }
Esempio n. 9
0
        public People Filter (Predicate<Person> match)
        {
            People retlist = new People();

            ForEach (delegate (Person p)
            {
                if (match (p))
                    retlist.Add (p);
            });

            return retlist;
        }
Esempio n. 10
0
        public static People LogicalOr(People set1, People set2)
        {
            // If either set is invalid, return the other
            // (a null is different from an empty set)

            if (set1 == null)
            {
                return(set2);
            }

            if (set2 == null)
            {
                return(set1);
            }

            // Build table, eliminating duplicates

            Dictionary <int, Person> table = new Dictionary <int, Person>();

            foreach (Person person in set1)
            {
                if (person == null)
                {
                    continue;
                }

                table[person.Identity] = person;
            }

            foreach (Person person in set2)
            {
                if (person == null)
                {
                    continue;
                }

                table[person.Identity] = person;
            }

            // Assemble result, without any nulls in the original sets

            People result = new People();

            foreach (Person person in table.Values)
            {
                result.Add(person);
            }

            return(result);
        }
Esempio n. 11
0
        public People Filter(Predicate <Person> match)
        {
            People retlist = new People();

            this.ForEach(delegate(Person p)
            {
                if (match(p))
                {
                    retlist.Add(p);
                }
            });

            return(retlist);
        }
Esempio n. 12
0
        public static People GetLocalDeputies(int organizationId, int geographyId)
        {
            BasicPersonRole[] personRoles = SwarmDb.GetDatabaseForReading().GetRolesForOrganizationGeography(organizationId, geographyId);
            People            result      = new People();

            foreach (BasicPersonRole role in personRoles)
            {
                if (role.Type == RoleType.LocalDeputy)
                {
                    result.Add(Person.FromIdentity(role.PersonId));
                }
            }

            return(result);
        }
Esempio n. 13
0
        private static People FilterByApplicant(BasicPerson[] candidates, Organization organization)
        {
            // Get the organization tree

            Organizations orgTree = organization.ThisAndBelow();

            // Build a lookup table of this organization tree. For each person in 'people'
            // that has at least one membership in an organization in the lookup table,
            // add that person to the final result.

            Dictionary <int, BasicOrganization> lookup = new Dictionary <int, BasicOrganization>();

            foreach (Organization org in orgTree)
            {
                lookup[org.Identity] = org;
            }

            // Get the list of all memberships

            Dictionary <int, List <BasicApplicant> > applicants =
                SwarmDb.GetDatabaseForReading()
                .GetApplicantsFromPeople(People.FromArray(candidates).Identities);

            People result = new People();

            foreach (BasicPerson basicPerson in candidates)
            {
                bool applicantToOrganization = false;

                if (applicants.ContainsKey(basicPerson.Identity))
                {
                    foreach (BasicApplicant applicant in applicants[basicPerson.Identity])
                    {
                        if (lookup.ContainsKey(applicant.OrganizationId))
                        {
                            applicantToOrganization = true;
                        }
                    }
                }

                if (applicantToOrganization)
                {
                    result.Add(Person.FromBasic(basicPerson));
                }
            }

            return(result);
        }
Esempio n. 14
0
        private static People FilterByMembership(BasicPerson[] candidates, Organization organization)
        {
            // Get the organization tree

            Organizations orgTree = organization.ThisAndBelow();

            // Build a lookup table of this organization tree. For each person in 'people'
            // that has at least one membership in an organization in the lookup table,
            // add that person to the final result.

            Dictionary <int, BasicOrganization> lookup = new Dictionary <int, BasicOrganization>();

            foreach (Organization org in orgTree)
            {
                lookup[org.Identity] = org;
            }

            // Get the list of all memberships

            Dictionary <int, List <BasicParticipation> > memberships =
                SwarmDb.GetDatabaseForReading()
                .GetParticipationsForPeople(LogicServices.ObjectsToIdentifiers(candidates));

            People result = new People();

            foreach (BasicPerson basicPerson in candidates)
            {
                bool memberOfOrganization = false;

                if (memberships.ContainsKey(basicPerson.Identity))
                {
                    foreach (BasicParticipation membership in memberships[basicPerson.Identity])
                    {
                        if (lookup.ContainsKey(membership.OrganizationId))
                        {
                            memberOfOrganization = true;
                        }
                    }
                }

                if (memberOfOrganization)
                {
                    result.Add(Person.FromBasic(basicPerson));
                }
            }

            return(result);
        }
Esempio n. 15
0
        public static People FromGeography(int geographyId)
        {
            Geographies geoTree = Geography.FromIdentity(geographyId).ThisAndBelow();

            // First, get list of people in the geography, then filter on memberships

            BasicPerson[] people = SwarmDb.GetDatabaseForReading().GetPeopleInGeographies(geoTree.Identities);

            People result = new People();

            foreach (BasicPerson basicPerson in people)
            {
                result.Add(Person.FromBasic(basicPerson));
            }

            return(result);
        }
Esempio n. 16
0
        public static People LogicalAnd(People set1, People set2)
        {
            // If either set is invalid, return the other
            // (a null is different from an empty set)

            if (set1 == null)
            {
                return(set2);
            }

            if (set2 == null)
            {
                return(set1);
            }

            People result = new People();
            Dictionary <int, bool> set2Lookup = new Dictionary <int, bool>();

            // Build set2's lookup table

            foreach (Person person in set2)
            {
                set2Lookup[person.Identity] = true;
            }

            // Build result

            foreach (Person person in set1)
            {
                if (set2Lookup.ContainsKey(person.Identity))
                {
                    result.Add(person);
                }
            }

            return(result);
        }