protected void Page_Load (object sender, EventArgs e) { if (_authority.HasPermission(Permission.CanEditMemberships, Organization.PPFIid, Geography.FinlandId, Authorization.Flag.ExactGeographyExactOrganization)) { loadCntry = Country.FromCode("FI"); geotree = loadCntry.Geography.GetTree(); nowValue = DateTime.Now; if (!IsPostBack) { foreach (Organization org in Organizations.GetAll()) { if (org.DefaultCountryId == loadCntry.Identity) { DropDownListOrgs.Items.Add(new ListItem(org.Name, "" + org.Identity)); } } } else { currentOrg = Organization.FromIdentity(Convert.ToInt32(DropDownListOrgs.SelectedValue)); } } else { Response.Write("Access not allowed"); Response.End(); } }
private static int FindDefaultCountry(Org org) { //Find default country = Country of anchor. Geographies line = Geography.FromIdentity(org.AnchorGeographyId).GetLine(); Geography[] arrLine = line.ToArray(); Array.Reverse(arrLine); Countries countries = Countries.GetAll(); int foundCntry = 1; //sweden foreach (Geography geo in arrLine) { if (geo.Identity == 1) { return(foundCntry); //Didnt find any, we are at world. } foreach (Country cntry in countries) { if (geo.Identity == cntry.GeographyId) { foundCntry = cntry.CountryId; return(foundCntry); } } } return(foundCntry); //Didnt find any }
public static Role[] SelectThisByOrganization(int organizationId) { try { BasicPersonRole[] personRoles = Roles.GetAllDownwardRolesRoles(organizationId, Geography.IgnoreGeography); Dictionary <int, List <Role> > result = new Dictionary <int, List <Role> >(); foreach (BasicPersonRole br in personRoles) { if (br.OrganizationId == organizationId) { if (!result.ContainsKey(br.OrganizationId)) { result[br.OrganizationId] = new List <Role>(); } result[br.OrganizationId].Add(new Role(br)); } } List <Role> result2 = new List <Role>(); lock (dataLock) { hierarchicalSortOrder = Geographies.GetHierarchicalSortOrder(); RecursiveAddInTreeOrder(result2, result, organizationId, 0); } return(result2.ToArray()); } catch { return(new Role[0]); } }
public static string GetRecipientCount(int recipientTypeId, int geographyId) { int personCount = 0; AuthenticationData authData = GetAuthenticationDataAndCulture(); Geography geography = Geography.FromIdentity(geographyId); Geographies geoTree = geography.GetTree(); Organizations orgTree = authData.CurrentOrganization.GetTree(); switch (recipientTypeId) { case 0: // "Select one" personCount = 0; break; case 1: // Regulars personCount = orgTree.GetMemberCountForGeographies(geoTree); break; case 2: // Agents personCount = Activists.GetCountForGeography(geography); break; // TODO: Dynamic membership types case 101: // Officers personCount = orgTree.GetRoleHolderCountForGeographies(geoTree); break; case 102: // Volunteers personCount = 0; // TODO break; default: throw new NotImplementedException(); } string result; string[] resources = Resources.Pages.Comms.SendMassMessage_RecipientCount.Split('|'); switch (personCount) { case 0: result = resources[0]; break; case 1: result = resources[1]; break; default: result = String.Format(resources[2], personCount); break; } return(result); }
protected void Page_Load(object sender, EventArgs e) { divContent.InnerHtml = ""; string geoString = Request.QueryString["GeographyId"]; int geoRootId = 0; if (geoString != null) { int.TryParse(geoString.Trim(), out geoRootId); } Geography geoRoot; if (geoRootId == 0) { Person viewingPerson = Person.FromIdentity(Int32.Parse(HttpContext.Current.User.Identity.Name)); geoRoot = viewingPerson.Geography; } else { geoRoot = Geography.FromIdentity(geoRootId); } Geographies geographies = geoRoot.GetTree(); Geographies upwardsList = new Geographies(); while (geoRoot.GeographyId != Geography.SwedenId) { upwardsList.Insert(0, geoRoot); geoRoot = geoRoot.Parent; } string toPrint = ""; if (geoRootId == Geography.SwedenId) { string cacheDataKey = "SwedenContactList"; toPrint = (string)Cache.Get(cacheDataKey); if (toPrint == null) { toPrint = buildOutput(upwardsList, geographies); Cache.Insert(cacheDataKey, toPrint, null, DateTime.UtcNow.AddMinutes(15), System.Web.Caching.Cache.NoSlidingExpiration); } else { divContent.InnerHtml += (Server.HtmlEncode("Notera! Av belastnings-skäl kan denna lista vara upp till 15 minuter gammal.") + "<br />"); } } else { toPrint = buildOutput(upwardsList, geographies); } divContent.InnerHtml += toPrint; }
protected int GetMemberCount(Organization org, bool recursive, Geography geo, DateTime dateTime) { string cacheDataKey = "ChartData-AllMembershipEvents-5min"; MembershipEvents events = (MembershipEvents)Cache.Get(cacheDataKey); if (events == null) { events = MembershipEvents.LoadAll(); Cache.Insert(cacheDataKey, events, null, DateTime.UtcNow.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration); } DateTime endDateTime = dateTime; Geographies tree = geo.GetTree(); Dictionary <int, bool> treeDict = new Dictionary <int, bool>(); foreach (Geography g in tree) { treeDict.Add(g.GeographyId, true); } int eventIndex = 0; int currentCount = 0; Organizations orgtree = null; if (DropDownListOrg.SelectedValue == Organization.PPSEid.ToString()) { orgtree = Organizations.FromSingle(Organization.PPSE); } else { orgtree = Organization.FromIdentity(Organization.UPSEid).GetTree(); } Dictionary <int, Organization> orgsToInclude = new Dictionary <int, Organization>(); foreach (Organization o in orgtree) { orgsToInclude[o.Identity] = o; } while (eventIndex < events.Count && events[eventIndex].DateTime < endDateTime) { if (orgsToInclude.ContainsKey(events[eventIndex].OrganizationId) && treeDict.ContainsKey(events[eventIndex].GeographyId)) { currentCount += events[eventIndex].DeltaCount; } eventIndex++; } return(currentCount); }
private void Populate() { Geography wasSelectedGeo = this.SelectedGeography; Tree.Nodes.Clear(); if (roots == null) { roots = Geographies.FromSingle(Geography.Root); } RadTreeNode topNode = new RadTreeNode("", ""); foreach (Geography root in roots) { Geographies geos = root.GetTree(); // We need a real f*****g tree structure. Dictionary <int, Geographies> lookup = new Dictionary <int, Geographies>(); foreach (Geography geo in geos) { if (!lookup.ContainsKey(geo.ParentIdentity)) { lookup[geo.ParentIdentity] = new Geographies(); } lookup[geo.ParentIdentity].Add(geo); } topNode.Nodes.Add(RecursiveAdd(lookup, geos[0].ParentIdentity)[0]); } //Re-added selection of first node to avoid crash in alert activists /JL 2010-12-21 if (roots.Count > 1) { //need the dummy root Tree.Nodes.Add(topNode); topNode.Enabled = false; topNode.Expanded = true; topNode.Nodes[0].Selected = true; } else { Tree.Nodes.Add(topNode.Nodes[0]); Tree.Nodes[0].Selected = true; } if (wasSelectedGeo != null) { SelectedGeography = wasSelectedGeo; } Tree.Nodes[0].Expanded = true; }
protected void Page_Load (object sender, EventArgs e) { divContent.InnerHtml = ""; string geoString = Request.QueryString["GeographyId"]; int geoRootId = 0; if (geoString != null) int.TryParse(geoString.Trim(), out geoRootId); Geography geoRoot; if (geoRootId == 0) { Person viewingPerson = Person.FromIdentity(Int32.Parse(HttpContext.Current.User.Identity.Name)); geoRoot = viewingPerson.Geography; } else { geoRoot = Geography.FromIdentity(geoRootId); } Geographies geographies = geoRoot.GetTree(); Geographies upwardsList = new Geographies(); while (geoRoot.GeographyId != Geography.SwedenId) { upwardsList.Insert(0, geoRoot); geoRoot = geoRoot.Parent; } string toPrint = ""; if (geoRootId == Geography.SwedenId) { string cacheDataKey = "SwedenContactList"; toPrint = (string)Cache.Get(cacheDataKey); if (toPrint == null) { toPrint = buildOutput(upwardsList, geographies); Cache.Insert(cacheDataKey, toPrint, null, DateTime.UtcNow.AddMinutes(15), System.Web.Caching.Cache.NoSlidingExpiration); } else { divContent.InnerHtml += (Server.HtmlEncode("Notera! Av belastnings-skäl kan denna lista vara upp till 15 minuter gammal.") + "<br />"); } } else { toPrint = buildOutput(upwardsList, geographies); } divContent.InnerHtml += toPrint; }
protected void Page_Load(object sender, EventArgs e) { this.pagePermissionDefault = new PermissionSet(Permission.CanSendLocalMail); PanelTestSent.Visible = false; if (!Page.IsPostBack) { Geographies geoList = _authority.GetGeographiesForOrganization(Organization.PPSE); // Hack. Should be org agnostic. geoList = geoList.RemoveRedundant(); ViewState["actingOrg"] = Organization.PPSEid; if (geoList.Count == 0) { // Quick Hack for PPFI geoList = _authority.GetGeographiesForOrganization(Organization.FromIdentity(Organization.PPFIid)); geoList = geoList.RemoveRedundant(); if (geoList.Count != 0) { ViewState["actingOrg"] = Organization.PPFIid; } } if (geoList.Count == 0) { ViewState["actingOrg"] = 0; this.LabelGeographies.Text = "You don't have access to any geographic area."; } else { this.GeographyTree.Roots = geoList; } UpdateActivistCount(); UpdateSmsCosts(); if (PhoneMessageTransmitter.CheckServiceStatus() == false) { CheckSms.Enabled = false; CheckSms.Text = "SMS-service not available currently. No reply from server."; } } if (Organization.PPSEid != (int)ViewState["actingOrg"]) { SmsPanel.Visible = false; } TextSms.Attributes["onkeydown"] = "updateSmsLength(this);"; //Add the necessary AJAX setting programmatically -- commented out // RadAjaxManager1.AjaxSettings.AddAjaxSetting(GeographyTree.FindControl("DropGeographies"), this.PanelRestOfPage); // RadAjaxManager1.AjaxSettings.AddAjaxSetting(GeographyTree.FindControl("DropGeographies"), this.LabelGeographies); // Controls_v4_WSGeographyTreeDropDown.EmitScripts(this); }
public static People FromOrganizationAndGeography(Organization organization, Geography geography) { Geographies geoTree = geography.ThisAndBelow(); // First, get list of people in the geography, then filter on memberships BasicPerson[] people = SwarmDb.GetDatabaseForReading().GetPeopleInGeographies(geoTree.Identities); // Filter on memberships return(People.LogicalOr(FilterByMembership(people, organization), FilterByApplicant(people, organization))); }
/// <summary> /// This method visits a KML LineString element /// </summary> /// <param name="elem">KML line string element to be visited</param> /// <param name="isLineRing">True if the line is the ring</param> protected void VisitLineString( XmlElement elem, bool isLineRing = false) { if (elem == null) { return; } XmlNode coordinates = GetFirstChild(elem, "coordinates"); if (coordinates == null || !coordinates.HasChildNodes) { return; } var txt = coordinates.ChildNodes[0]; var allCoordinates = txt.InnerText; var points = ParseCoordinates(allCoordinates); if (points == null || points.Count == 0) { return; } var ls = isLineRing ? new LinearRing() : new LineString(); ls.Points.AddRange(points); var altitudeModeCode = GetAltitudeModeCode(elem); foreach (var p in ls.Points) { p.Measure = altitudeModeCode; } // Extract other non-geographic data VisitGeography(elem, ls); #region Handle tessellate flag ls.StoreTessellateFlag(); #endregion // Sets the geography instance context ls.Context = (elem.ParentNode != null) ? elem.ParentNode.OuterXml : elem.OuterXml; Geographies.Add(ls); }
protected void RecalculatePersonCount() { this.ButtonList.Text = "List "; ButtonDupeList.Enabled = false; try { Organization selectedOrg = Organization.FromIdentity(Convert.ToInt32(this.DropOrganizations.SelectedValue)); Organizations orgTree = selectedOrg.GetTree(); Geography selectedGeo = Geography.FromIdentity(Convert.ToInt32(this.DropGeographies.SelectedValue)); Geographies geoTree = selectedGeo.GetTree(); int memberCount = 0; memberCount = orgTree.GetMemberCountForGeographies(geoTree); this.ButtonList.Text = "List " + memberCount.ToString("#,##0") + " people"; this.ButtonList.Enabled = (memberCount > 0 ? true : false); ButtonDupeList.Enabled = false; ButtonExpiringList.Enabled = false; ButtonDupeList.Enabled = false; ButtonExpiringList.Enabled = false; PanelForwards.Visible = false; PanelBackwards.Visible = false; Literal1.Text = Literal1.Text.Replace("2500", "3500"); if (memberCount <= 3500) { ButtonDupeList.Enabled = true; foreach (int handled in handledOrganizations) { if (selectedOrg.Inherits(handled) || selectedOrg.Identity == handled) { if (_authority.HasPermission(Permission.CanEditMemberships, selectedOrg.Identity, selectedGeo.Identity, Authorization.Flag.Default)) { PanelForwards.Visible = true; } ButtonExpiringList.Enabled = true; if (_authority.HasPermission(Permission.CanSeeExpiredDuringGracePeriod, selectedOrg.Identity, selectedGeo.Identity, Authorization.Flag.Default)) { PanelBackwards.Visible = true; } } } } } catch { } }
/// <summary> /// This method visits a KML LatLonAltBox element /// </summary> /// <param name="element">KML LatLonAltBox element to be visited</param> protected void VisitLatLonAltBox(XmlElement element) { if (element == null) { return; } #region Required properties var north = GetChildElementText <double>(element, "north"); var south = GetChildElementText <double>(element, "south"); var west = GetChildElementText <double>(element, "west"); var east = GetChildElementText <double>(element, "east"); #endregion #region Optional properties double minAltitude = 0; double maxAltitude = 0; var minAltitudeS = GetChildElementText(element, "minAltitude"); if (!string.IsNullOrEmpty(minAltitudeS)) { minAltitude = double.Parse(minAltitudeS); } var maxAltitudeS = GetChildElementText(element, "maxAltitude"); if (!string.IsNullOrEmpty(maxAltitudeS)) { maxAltitude = double.Parse(maxAltitudeS); } var altitudeMode = GetAltitudeMode(element); #endregion var altBox = new LatLonAltBox { North = north, South = south, West = west, East = east, MinAltitude = minAltitude, MaxAltitude = maxAltitude, AltitudeMode = altitudeMode }; Geographies.Add(altBox); }
string buildOutput(Geographies upwardsList, Geographies geographies) { StringBuilder sb = new StringBuilder(); foreach (Geography geo in upwardsList) { sb.Append(PrintGeography(geo)); } for (int geoIndex = 1; geoIndex < geographies.Count; geoIndex++) { sb.Append(PrintGeography(geographies[geoIndex])); } return(sb.ToString()); }
protected void Page_Load(object sender, EventArgs e) { // Populate geo dropdown if (!Page.IsPostBack) { this.DropGeographies.Items.Add(new ListItem("-- V\xE4lj --", "0")); //TODO: Hardcoded Sweden, should maybe be dependent on user Geographies geos = Geographies.FromLevel(Country.FromCode("SE"), GeographyLevel.Municipality); foreach (Geography geo in geos) { this.DropGeographies.Items.Add(new ListItem(geo.Name, geo.Identity.ToString())); } } }
protected void RecalculatePersonCount() { this.ButtonList.Text = "List "; ButtonDupeList.Enabled = false; try { Organization selectedOrg = Organization.FromIdentity(Convert.ToInt32(this.DropOrganizations.SelectedValue)); Organizations orgTree = selectedOrg.GetTree(); Geography selectedGeo = Geography.FromIdentity(Convert.ToInt32(this.DropGeographies.SelectedValue)); Geographies geoTree = selectedGeo.GetTree(); int memberCount = 0; // Optimize a little: if we are at the org's top anchor, do not parse the geography, just select all // Removed, doesnt work if people live in other geo. if (false && selectedGeo.Identity == selectedOrg.AnchorGeographyId) { memberCount = orgTree.GetMemberCount(); } else { memberCount = orgTree.GetMemberCountForGeographies(geoTree); } this.ButtonList.Text = "List " + memberCount.ToString("#,##0") + " people"; this.ButtonList.Enabled = (memberCount > 0 ? true : false); ButtonDupeList.Enabled = false; ButtonExpiringList.Enabled = false; Literal1.Text = Literal1.Text.Replace("2500", "3500"); if (memberCount <= 3500) { ButtonDupeList.Enabled = true; foreach (int handled in handledOrganizations) { if (selectedOrg.Inherits(handled) || selectedOrg.Identity == handled) { ButtonExpiringList.Enabled = true; } } } } catch { } }
protected void PopulateGeographies() { if (DropOrganizationsLocal.SelectedIndex >= 0) { Organization org = Organization.FromIdentity(Convert.ToInt32(DropOrganizationsLocal.SelectedValue)); Geographies geoList = _authority.GetGeographiesForOrganization(org, RoleTypes.AllRoleTypes); geoList = geoList.RemoveRedundant(); geoList = geoList.FilterAbove(Geography.FromIdentity(org.AnchorGeographyId)); if (org.Identity == Organization.SandboxIdentity) { geoList = Geographies.FromSingle(Geography.Root); } this.DropGeographies.Items.Clear(); foreach (Geography nodeRoot in geoList) { Geographies nodeTree = nodeRoot.GetTree(); foreach (Geography node in nodeTree) { string nodeLabel = node.Name; for (int loop = 0; loop < node.Generation; loop++) { nodeLabel = "|-- " + nodeLabel; } if (_authority.HasPermission(Permission.CanEditLocalRoles, org.Identity, node.Identity, Authorization.Flag.Default)) { DropGeographies.Items.Add(new ListItem(nodeLabel, node.GeographyId.ToString())); } } } if (DropGeographies.Items.Count == 0) { AddLocalRolePanel.Visible = false; } else { AddLocalRolePanel.Visible = true; } } }
/// <summary> /// This method visits a KML Model element /// </summary> /// <param name="element">KML model element to be visited</param> protected void VisitModel(XmlElement element) { if (element == null) { return; } var m = new Model(); #region Extract Location var locationElem = GetFirstChild(element, "location"); if (locationElem != null) { VisitLonLatAltElement(locationElem); m.Location = Geographies[Geographies.Count - 1] as Point; Geographies.RemoveAt(Geographies.Count - 1); } #endregion #region Extract other non-geographic data VisitGeography(element, m); var orientationElem = GetFirstChild(element, "orientation"); if (orientationElem != null) { m.OrientationHeading = GetChildElementText <double>(orientationElem, "heading", 0); m.OrientationTilt = GetChildElementText <double>(orientationElem, "tilt", 0); m.OrientationRoll = GetChildElementText <double>(orientationElem, "roll", 0); } var scaleElem = GetFirstChild(element, "scale"); if (scaleElem != null) { m.ScaleX = GetChildElementText <double>(scaleElem, "x", 1); m.ScaleY = GetChildElementText <double>(scaleElem, "y", 1); m.ScaleZ = GetChildElementText <double>(scaleElem, "z", 1); } #endregion Models.Add(m); }
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); }
protected Geographies GetAuthorityArea() { Geographies result = new Geographies(); int currentUserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name); Person currentUser = Person.FromIdentity(currentUserId); Authority authority = currentUser.GetAuthority(); foreach (BasicPersonRole role in authority.LocalPersonRoles) { Geographies roleGeographies = Geography.FromIdentity(role.GeographyId).GetTree(); result = Geographies.LogicalOr(result, roleGeographies); } return(result); }
public static int GetCityLeadCount(int organizationId, int countryId) { Geographies cities = Geographies.FromLevel(countryId, GeographyLevel.Municipality); int leadCount = 0; foreach (Geography city in cities) { RoleLookup roles = RoleLookup.FromGeographyAndOrganization(city.Identity, organizationId); if (roles[RoleType.LocalLead].Count > 0) { leadCount++; } } return(leadCount); }
protected void PopulateGeographies() { Person viewingPerson = Person.FromIdentity(Int32.Parse(HttpContext.Current.User.Identity.Name)); Authority authority = viewingPerson.GetAuthority(); try { Organization org = Organization.FromIdentity(Convert.ToInt32(DropOrganizations.SelectedValue)); Geographies geoList = authority.GetGeographiesForOrganization(org); geoList = geoList.RemoveRedundant(); geoList = geoList.FilterAbove(Geography.FromIdentity(org.AnchorGeographyId)); this.DropGeographies.Items.Clear(); foreach (Geography nodeRoot in geoList) { Geographies nodeTree = nodeRoot.GetTree(); foreach (Geography node in nodeTree) { string nodeLabel = node.Name; for (int loop = 0; loop < node.Generation; loop++) { nodeLabel = "|-- " + nodeLabel; } if (authority.HasPermission(Permission.CanSeePeople, org.Identity, node.Identity, Authorization.Flag.Default)) { DropGeographies.Items.Add(new ListItem(nodeLabel, node.GeographyId.ToString())); } } } if (authority.HasPermission(Permission.CanSeePeople, org.Identity, -1, Authorization.Flag.Default)) { DropGeographies.Items.Add(new ListItem("Any", Geography.RootIdentity.ToString())); } } catch (Exception) { } RecalculatePersonCount(); }
protected People GetDirectReports() { People result = new People(); foreach (BasicPersonRole role in _authority.LocalPersonRoles) { if (role.Type == RoleType.LocalLead || role.Type == RoleType.LocalDeputy || role.Type == RoleType.LocalAdmin) { Geographies geographies = Geography.FromIdentity(role.GeographyId).Children; // HACK: Compensate for current bad tree structure if (role.GeographyId == 34) { //Lägg till Skåne till Södra geographies = geographies.LogicalOr(Geography.FromIdentity(36).Children); } if (role.GeographyId == 32) { //Lägg till Västra Götaland till Västra geographies = geographies.LogicalOr(Geography.FromIdentity(355).Children); } foreach (Geography geography in geographies) { People localLead = new People(); RoleLookup allRoles = RoleLookup.FromGeographyAndOrganization(geography.Identity, role.OrganizationId); Roles leadRoles = allRoles[RoleType.LocalLead]; foreach (PersonRole leadRole in leadRoles) { localLead.Add(leadRole.Person); } result = result.LogicalOr(localLead); } } } return(result); }
/// <summary> /// This method visits a KML Region element /// </summary> /// <param name="element">KML Region element to be visited</param> protected void VisitRegion(XmlElement element) { if (element == null) { return; } var r = new Region(); VisitGeography(element, r); var latLonAltBoxElem = GetFirstChild(element, "LatLonAltBox"); var latLonBoxElem = GetFirstChild(element, "LatLonBox"); var latLonQuadElem = GetFirstChild(element, "gx:LatLonQuad"); var numOfGeographiesBefore = Geographies.Count; if (latLonAltBoxElem != null) { VisitLatLonAltBox(latLonAltBoxElem); } else if (latLonBoxElem != null) { VisitLatLonBox(latLonBoxElem); } else if (latLonQuadElem != null) { VisitLatLonQuad(latLonQuadElem); } var numOfGeographiesAfter = Geographies.Count; if (numOfGeographiesAfter > numOfGeographiesBefore) { // Found region's box r.Box = Geographies[Geographies.Count - 1]; Geographies.RemoveAt(Geographies.Count - 1); } Regions.Add(r); }
/// <summary> /// Gets a list of person IDs that are officers in the org/geography combo. /// </summary> public static int[] GetAllDownwardRoles(int organizationId, int geographyId) { Organizations orgTree = null; Geographies nodeTree = null; int[] nodeIds; orgTree = Organization.FromIdentity(organizationId).ThisAndBelow(); if (geographyId > 0) { nodeTree = Geography.FromIdentity(geographyId).ThisAndBelow(); nodeIds = nodeTree.Identities; } else { nodeIds = new int[0]; } Dictionary <int, bool> peopleTable = new Dictionary <int, bool>(); foreach (Organization org in orgTree) { BasicPersonRole[] downwardPersonRoles = SwarmDb.GetDatabaseForReading().GetRolesForOrganizationGeographies(org.Identity, nodeIds); foreach (BasicPersonRole role in downwardPersonRoles) { peopleTable[role.PersonId] = true; } } // Assemble result List <int> result = new List <int>(); foreach (int personId in peopleTable.Keys) { result.Add(personId); } return(result.ToArray()); }
private void ConstructLine() { // Cut line down to three last nodes Geographies lastThree = geographies; // shallow copy - bad if (lastThree.Count > 3) { lastThree.RemoveRange(0, geographies.Count - 3); } string result = lastThree [0].Name; for (int index = 1; index < lastThree.Count; index++) { result += Server.HtmlEncode(" > " + lastThree[index].Name); } this.LabelGeography.Text = result; }
public void LoadGeographyData(StorageFile dataFile) { var document = new XmlDocument(); document.Load(dataFile.LocalPath); var node = document.SelectSingleNode(@"./Age"); if (node == null) { return; } foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "Age": Geographies.Add(ListDataItem.FromXml(childNode)); break; } } }
/// <summary> /// This method visits a KML Point element /// </summary> /// <param name="elem">KML Point element to be visited</param> protected void VisitPoint(XmlElement elem) { if (elem == null) { return; } // Extracts the point coordinates var coordinates = GetFirstChild(elem, "coordinates"); if (coordinates == null || !coordinates.HasChildNodes) { return; } var coordinatesTextNode = coordinates.ChildNodes[0]; var coordinatesText = coordinatesTextNode.InnerText; var pts = ParseCoordinates(coordinatesText); if (pts.Count == 0) { return; } var point = pts[0]; // Extracts the altitude mode point.Measure = GetAltitudeModeCode(elem); // Extracts the other non-geographic data VisitGeography(elem, point); // Sets the geography instance context point.Context = (elem.ParentNode != null) ? elem.ParentNode.OuterXml : elem.OuterXml; Geographies.Add(point); }
protected void RecalculateRecipientCount() { Organization selectedOrg = Organization.FromIdentity(Convert.ToInt32(this.DropOrganizations.SelectedValue)); Organizations orgTree = selectedOrg.GetTree(); this.LabelRecipientCount.Text = ""; if (this.DropGeographies.SelectedIndex < 0) { return; } Geography selectedGeo = Geography.FromIdentity(Convert.ToInt32(this.DropGeographies.SelectedValue)); Geographies geoTree = selectedGeo.GetTree(); int memberCount = 0; // Optimize a little: if we are at the org's top anchor, do not parse the geography, just select all // doesnt work, people live in other geos switch (this.DropRecipients.SelectedValue) { case "Members": if (false && selectedGeo.Identity == selectedOrg.AnchorGeographyId) { memberCount = orgTree.GetMemberCount(); } else { memberCount = orgTree.GetMemberCountForGeographies(geoTree); } break; case "Officers": memberCount = orgTree.GetRoleHolderCountForGeographies(geoTree); break; } this.LabelRecipientCount.Text = " (" + memberCount.ToString("#,##0") + " recipients)"; }
/// <summary> /// This method visits a KML LatLonBox element /// </summary> /// <param name="element">KML LatLonBox element to be visited</param> protected void VisitLatLonBox(XmlElement element) { if (element == null) { return; } #region Required properties var north = GetChildElementText <double>(element, "north"); var south = GetChildElementText <double>(element, "south"); var west = GetChildElementText <double>(element, "west"); var east = GetChildElementText <double>(element, "east"); #endregion #region Optional properties double rotation = 0; var rotationS = GetChildElementText(element, "rotation"); if (!string.IsNullOrEmpty(rotationS)) { rotation = double.Parse(rotationS); } #endregion var altBox = new LatLonBox { North = north, South = south, West = west, East = east, Rotation = rotation }; Geographies.Add(altBox); }
public static People FromOrganizationAndGeographyWithPattern(Organization organization, Geography geography, string pattern) { Geographies geoTree = geography.GetTree(); pattern = pattern.Trim(); if (pattern.Length == 0) { return(FromOrganizationAndGeography(organization, geography)); } else if (pattern.Length < 3) { // too short pattern! Return empty set. return(new People()); } // First, get list of people in the geography, then filter on memberships BasicPerson[] candidates = SwarmDb.GetDatabaseForReading().GetPeopleInGeographiesWithPattern(geoTree.Identities, pattern); return(FilterByMembership(candidates, organization)); }
public void LoadCombinedData(StorageFile dataFile) { var document = new XmlDocument(); document.Load(dataFile.LocalPath); var node = document.SelectSingleNode(@"/TargetCustomers"); if (node == null) { return; } foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "SlideHeader": Headers.Add(ListDataItem.FromXml(childNode)); break; case "Demo": Demos.Add(ListDataItem.FromXml(childNode)); break; case "HHI": HHIs.Add(ListDataItem.FromXml(childNode)); break; case "Geography": Geographies.Add(ListDataItem.FromXml(childNode)); break; } } CombinedList.AddRange(Demos); CombinedList.AddRange(HHIs); CombinedList.AddRange(Geographies); }
SeriesCollection GetVotingDayRankingData () { GeographyBallotCoverageLookup lookup; lookup= GetLookupFromCache(); Geographies geos = null; string circuitString = Request.QueryString["CircuitId"]; int circuitId = 0; if (String.IsNullOrEmpty(Request.QueryString["CircuitId"])) { geos = Geographies.FromLevel(Country.FromCode("SE"), GeographyLevel.ElectoralCircuit); } else { circuitId = Int32.Parse(circuitString); Geographies candidateGeos = Geography.FromIdentity(circuitId).GetTree(); geos = new Geographies(); foreach (Geography geo in candidateGeos) { if (lookup.ContainsKey(geo.Identity) && geo.Identity != circuitId) { geos.Add(geo); } } } GeographyBallotCoverageData data = new GeographyBallotCoverageData(); foreach (Geography geo in geos) { if (lookup.ContainsKey(geo.Identity)) { data.Add(lookup[geo.Identity]); } } data.Sort( delegate(GeographyBallotCoverageDataPoint p1, GeographyBallotCoverageDataPoint p2) { int i1 = (absoluteMode?p1.VotingStationsTotal: p1.WVotingStationsTotal) - (absoluteMode?p1.VotingStationsDistroSingle: p1.WVotingStationsDistroSingle); int i2 = (absoluteMode?p2.VotingStationsTotal: p2.WVotingStationsTotal) - (absoluteMode?p2.VotingStationsDistroSingle: p2.WVotingStationsDistroSingle); return i1.CompareTo(i2); }); SeriesCollection collection = new SeriesCollection(); Series seriesPositiveSingle = new Series(); seriesPositiveSingle.Name = "Positive, single distro"; Label2.Text = "(I hela Sverige saknar " + (lookup[Geography.SwedenId].VotingStationsTotal - lookup[Geography.SwedenId].VotingStationsDistroSingle).ToString("#,##0") + " väljare Piratpartiets valsedlar.)"; if (circuitId != 0) { AddSingleVotingDayDataPoint(lookup[circuitId], seriesPositiveSingle); } seriesPositiveSingle.Elements.Add(new Element()); foreach (GeographyBallotCoverageDataPoint dataPoint in data) { AddSingleVotingDayDataPoint(dataPoint, seriesPositiveSingle); } seriesPositiveSingle.DefaultElement.Color = System.Drawing.Color.Red; seriesPositiveSingle.DefaultElement.ShowValue = true; SeriesCollection result = new SeriesCollection(); result.Add(seriesPositiveSingle); return result; }
protected Geographies GetAuthorityArea () { Geographies result = new Geographies(); int currentUserId = Convert.ToInt32(HttpContext.Current.User.Identity.Name); Person currentUser = Person.FromIdentity(currentUserId); Authority authority = currentUser.GetAuthority(); foreach (BasicPersonRole role in authority.LocalPersonRoles) { Geographies roleGeographies = Geography.FromIdentity(role.GeographyId).GetTree(); result = Geographies.LogicalOr(result, roleGeographies); } return result; }
string buildOutput (Geographies upwardsList, Geographies geographies) { StringBuilder sb = new StringBuilder(); foreach (Geography geo in upwardsList) { sb.Append(PrintGeography(geo)); } for (int geoIndex = 1; geoIndex < geographies.Count; geoIndex++) { sb.Append(PrintGeography(geographies[geoIndex])); } return sb.ToString(); }
SeriesCollection GetVotingDayRankingData () { GeographyBallotCoverageLookup lookup = GetLookupFromCache(); Geographies geos = null; string circuitString = Request.QueryString["CircuitId"]; int circuitId = 0; if (String.IsNullOrEmpty(circuitString) || Int32.Parse(circuitString) == Geography.SwedenId) { geos = Geographies.FromLevel(Country.FromCode("SE"), GeographyLevel.ElectoralCircuit); } else { circuitId = Int32.Parse(circuitString); Geographies candidateGeos = Geography.FromIdentity(circuitId).GetTree(); geos = new Geographies(); foreach (Geography geo in candidateGeos) { if (lookup.ContainsKey(geo.Identity) && geo.Identity != circuitId) { geos.Add(geo); } } } Dictionary<int, Geography> geoLookup = new Dictionary<int, Geography>(); foreach (Geography geo in geos) geoLookup[geo.Identity] = geo; GeographyBallotCoverageData data = new GeographyBallotCoverageData(); foreach (Geography geo in geos) { if (lookup.ContainsKey(geo.Identity)) { data.Add(lookup[geo.Identity]); } } bool sortByValue = cbSort.Checked; data.Sort( delegate(GeographyBallotCoverageDataPoint p1, GeographyBallotCoverageDataPoint p2) { if (sortByValue) { if (advanceVotingMode) { double i1 = (absoluteMode ? p1.AdvanceVotingCoverage : p1.WWAdvanceVotingCoverage); double i2 = (absoluteMode ? p2.AdvanceVotingCoverage : p2.WWAdvanceVotingCoverage); return i1.CompareTo(i2); } else { double i1 = (absoluteMode ? p1.VotingCoverage : p1.WVotingCoverage); double i2 = (absoluteMode ? p2.VotingCoverage : p2.WVotingCoverage); return i1.CompareTo(i2); } } else { return geoLookup[p2.GeographyId].Name.CompareTo(geoLookup[p1.GeographyId].Name); } }); SeriesCollection collection = new SeriesCollection(); Series seriesPositiveSingle = new Series(); seriesPositiveSingle.Name = "Positive, single distro"; Series seriesPositiveDouble = new Series(); seriesPositiveDouble.Name = "Positive, double distro"; Series seriesPositiveFull = new Series(); seriesPositiveFull.Name = "Positive, full coverage"; Series seriesNegative = new Series(); seriesNegative.Name = "Negative"; // Add empties, then Sweden AddSingleVotingDayDataPoint(lookup[Geography.SwedenId], seriesPositiveSingle, seriesPositiveDouble, seriesPositiveFull, seriesNegative); if (circuitId != 0) { AddSingleVotingDayDataPoint(lookup[circuitId], seriesPositiveSingle, seriesPositiveDouble, seriesPositiveFull, seriesNegative); } seriesPositiveSingle.Elements.Add(new Element()); seriesNegative.Elements.Add(new Element()); foreach (GeographyBallotCoverageDataPoint dataPoint in data) { AddSingleVotingDayDataPoint(dataPoint, seriesPositiveSingle, seriesPositiveDouble, seriesPositiveFull, seriesNegative); } seriesPositiveSingle.DefaultElement.Color = System.Drawing.Color.Yellow; seriesPositiveDouble.DefaultElement.Color = System.Drawing.Color.YellowGreen; seriesPositiveFull.DefaultElement.Color = System.Drawing.Color.Green; seriesPositiveSingle.DefaultElement.ShowValue = true; seriesNegative.DefaultElement.Color = System.Drawing.Color.DarkRed; SeriesCollection result = new SeriesCollection(); result.Add(seriesPositiveSingle); result.Add(seriesPositiveDouble); result.Add(seriesPositiveFull); result.Add(seriesNegative); return result; }