private void AddVolunteers(Person person, Organization organization) { TaskGroup group = new TaskGroup(TaskGroupType.Volunteers); Volunteers volunteers = Volunteers.GetOpen(); foreach (Volunteer volunteer in volunteers) { if (volunteer.Owner.Identity == person.Identity) { group.Tasks.Add(new TaskVolunteer(volunteer)); } } if (group.Tasks.Count > 0) { Add(group); } }
public static void TimeoutVolunteers() { Volunteers volunteers = Volunteers.GetOpen(); DateTime threshold = DateTime.Today.AddDays(-30); foreach (Volunteer volunteer in volunteers) { if (volunteer.OpenedDateTime < threshold) { // timed out OfficerChain officers = OfficerChain.FromOrganizationAndGeography(Organization.PPSE, volunteer.Geography); new MailTransmitter(Strings.MailSenderName, Strings.MailSenderAddress, "Volunteer Timed Out: [" + volunteer.Geography.Name + "]", String.Empty, officers, true).Send(); volunteer.Close("Timed out"); } } }
public static void TimeoutVolunteers() { Volunteers volunteers = Volunteers.GetOpen(); DateTime threshold = DateTime.Today.AddDays(-30); foreach (Volunteer volunteer in volunteers) { if (volunteer.OpenedDateTime < threshold) { // timed out /* -- wtf, Volunteer doesn't have an Org component? Well, will change anyway with Swarmops role structure * * OfficerChain officers = OfficerChain.FromOrganizationAndGeography(volunteer., * volunteer.Geography); * * new MailTransmitter(Strings.MailSenderName, Strings.MailSenderAddress, * "Volunteer Timed Out: [" + volunteer.Geography.Name + "]", * String.Empty, officers, true).Send(); */ volunteer.Close("Timed out"); } } }
protected void PopulateGrids(bool rebuildOthersGrid) { Volunteers allVolunteers = Volunteers.GetOpen(); int currentUserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name); Person viewingPerson = Person.FromIdentity(currentUserId); Authority authority = viewingPerson.GetAuthority(); Volunteers geoVolunteers = new Volunteers(); Volunteers directReportVolunteers = new Volunteers(); Volunteers vicesAndAdminsVolunteers = new Volunteers(); Volunteers ownerVolunteers = new Volunteers(); Geographies authGeos = this.GetAuthorityArea(); People directReports = GetDirectReports(); People vicesAndAdmins = this.GetVicesAndAdmins(); // Build lookup tables Dictionary <int, bool> geoLookup = new Dictionary <int, bool>(); Dictionary <int, bool> directReportLookup = new Dictionary <int, bool>(); Dictionary <int, bool> vicesAndAdminsLookup = new Dictionary <int, bool>(); Dictionary <int, bool> leadsVicesAndAdminsLookup = new Dictionary <int, bool>(); foreach (Geography geo in authGeos) { geoLookup[geo.Identity] = true; } foreach (Person person in directReports) { directReportLookup[person.Identity] = true; } foreach (Person person in vicesAndAdmins) { vicesAndAdminsLookup[person.Identity] = true; } // Build volunteer lists Dictionary <int, Organization> viewerOrgDict = new Dictionary <int, Organization>(); Organizations viewerOrgsList = authority.GetOrganizations(RoleTypes.AllLocalRoleTypes); foreach (Organization o in viewerOrgsList) { viewerOrgDict[o.Identity] = o; } //Volunteers filteredVolunteers = new Volunteers(); //foreach (Volunteer volunteer in allVolunteers) //{ // try // { // Person p = volunteer.Person; // filteredVolunteers.Add(volunteer); // } // catch // { // } //} //allVolunteers = filteredVolunteers; foreach (Volunteer volunteer in allVolunteers) { try { bool hasAuthority = false; // Only show geoVolunteers that volounteered for an org where viewer have a role. // (This is currently always PP) // Unless it is directly assigned. foreach (VolunteerRole rle in volunteer.Roles) { if (viewerOrgDict.ContainsKey(rle.OrganizationId)) { hasAuthority = true; break; } } if (hasAuthority && geoLookup.ContainsKey(volunteer.Geography.Identity)) { geoVolunteers.Add(volunteer); /* Fix for the viewing users volunteers showing up in more than one list */ // BROKEN FIX -- this caused only one volunteer to be displayed, EVER, and delayed // volunteer processing by several days -RF //break; } // If directly assigned to me show regardless of org. if (volunteer.OwnerPersonId == currentUserId) { ownerVolunteers.Add(volunteer); } if (hasAuthority && directReportLookup.ContainsKey(volunteer.OwnerPersonId)) { directReportVolunteers.Add(volunteer); } if (hasAuthority && vicesAndAdminsLookup.ContainsKey(volunteer.OwnerPersonId)) { vicesAndAdminsVolunteers.Add(volunteer); } } finally { // DEBUG USE ONLY - INTENTIONALLY NO EFFECT } } if (rebuildOthersGrid) { geoVolunteers.Remove(ownerVolunteers); geoVolunteers.Remove(directReportVolunteers); geoVolunteers.Remove(vicesAndAdminsVolunteers); this.GridOther.DataSource = geoVolunteers; } this.GridLeadGeography.DataSource = vicesAndAdminsVolunteers; this.GridReports.DataSource = directReportVolunteers; this.GridOwner.DataSource = ownerVolunteers; }
public string SwedishCityMapOrgStrengthLookupReplacer(Match match) { // Five groups: "color" and "id" are the keys, "start", "middle" and "end" are what to paste in between. Organization org = Organization.FromIdentity(1); // Replace later for more generic string resultColorString = "#000000"; string id = match.Groups["id"].Value; // If not constructed for this instance, construct the volunteer cache if (this.volunteerCache == null) { this.volunteerCache = new Dictionary <int, bool>(); Volunteers volunteers = Volunteers.GetOpen(); foreach (Volunteer volunteer in volunteers) { volunteerCache[volunteer.Geography.Identity] = true; } } try { Geography geo = Geography.FromOfficialDesignation(1, GeographyLevel.Municipality, id); int circuitLeadCount = 0; int cityLeadCount = 0; int cityVolunteerCount = 0; RoleLookup lookup = RoleLookup.FromGeographyAndOrganization(geo.Identity, 1); if (lookup[RoleType.LocalLead].Count > 0) { cityLeadCount = 1; if (lookup[RoleType.LocalDeputy].Count > 0) { cityLeadCount = 2; } } if (volunteerCache.ContainsKey(geo.Identity)) { cityVolunteerCount = 1; } // Move up to circuit level while (!(geo.AtLevel(GeographyLevel.ElectoralCircuit))) { geo = geo.Parent; } lookup = RoleLookup.FromGeographyAndOrganization(geo.Identity, 1); if (lookup[RoleType.LocalLead].Count > 0) { circuitLeadCount = 1; if (lookup[RoleType.LocalDeputy].Count > 0) { circuitLeadCount = 2; } } float saturation = 1.0f; float brightness = 0.15f + 0.2f * circuitLeadCount; float hue = cityLeadCount * 60; // red, yellow, green hues at 0°, 60°, 120° if (cityLeadCount < 2 && cityVolunteerCount > 0) { hue += 30; // There are volunteers? Place at orange (for none) or yellow-green (for one). } Color color = ColorFromAhsb(255, hue, saturation, brightness); resultColorString = String.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B); } catch (Exception) { } /* * try * { * if (lookup.ContainsKey(id)) * { * geoId = lookup[id]; * } * else * { * geoId = Int32.Parse(id); * } * * Geography geo = Geography.FromIdentity(geoId); * * RoleLookup officers = RoleLookup.FromGeographyAndOrganization(geo.Identity, org.Identity); * * bool hasLead = officers[RoleType.LocalLead].Count > 0; * bool hasSecond = officers[RoleType.LocalDeputy].Count > 0; * * Geographies geoTree = geo.GetTree(); * * int cities = 0; * int citiesWithLead = 0; * * foreach (Geography localGeo in geoTree) * { * if (localGeo.Identity == geo.Identity) * { * continue; * } * * if (localGeo.Name.EndsWith("kommun")) * { * cities++; * * officers = RoleLookup.FromGeographyAndOrganization(localGeo.Identity, org.Identity); * * if (officers[RoleType.LocalLead].Count > 0) * { * citiesWithLead++; * } * } * } * * int cityLeadPercent = 100; * * if (cities > 0) * { * cityLeadPercent = citiesWithLead * 100 / cities; * } * * // Determine color * * Color color = Color.Red; * * if (!hasLead) * { * color = Color.Red; * } * else if (cityLeadPercent > 80 && hasSecond) * { * color = Color.Green; * } * else * { * // Find a hue between Orange and Light Green. Say, between 30 and 120. * * cityLeadPercent += 30; * if (cityLeadPercent > 120) * { * cityLeadPercent = 120; * } * * color = ColorFromAhsb(100, cityLeadPercent, 1.0f, 0.5f); * } * * resultColorString = String.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B); * } * catch (Exception) * { * // Ignore - color will be black * } * */ return(match.Groups["start"].Value + resultColorString + match.Groups["middle"].Value + id + match.Groups["end"].Value); }