From 2e9c0739308e9a5a1b505dc757d507d0060eda74 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Fri, 1 May 2015 18:00:34 +0200 Subject: [PATCH] Added real trees to Geo, Org --- Console/Console.cs | 6 +++--- Logic/DataObjects/GeographyWithPeopleDataObject.cs | 6 +++--- Logic/Financial/FinancialAccount.cs | 4 ++-- Logic/Security/Authority.cs | 4 ++-- Logic/Structure/Geography.cs | 10 +++++++++- Logic/Structure/Organization.cs | 9 +++++++++ Logic/Structure/Organizations.cs | 2 +- Logic/Swarm/Roles.cs | 12 ++++++------ Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs | 2 +- Utility/BotCode/RosterHousekeeping.cs | 2 +- 10 files changed, 37 insertions(+), 20 deletions(-) diff --git a/Console/Console.cs b/Console/Console.cs index 9572e40c..fe4148d7 100644 --- a/Console/Console.cs +++ b/Console/Console.cs @@ -342,7 +342,7 @@ namespace Swarmops writer.WriteLine("Förening,Namn (medlemsnr),kön,födelsedatum,bidragsgrund,email,telefon"); - Organizations orgTree = Organization.FromIdentity(2).GetAllBelow(); + Organizations orgTree = Organization.FromIdentity(2).ThisAndBelow(); foreach (Organization org in orgTree) { @@ -905,11 +905,11 @@ namespace Swarmops { // For each suborg to UP, - Organizations orgs = Organization.FromIdentity (2).GetAllBelow(); + Organizations orgs = Organization.FromIdentity (2).ThisAndBelow(); foreach (Organization org in orgs) { - // For each membership in this suborg, + // For each membership in this suborg,§ Memberships memberships = org.GetMemberships(); diff --git a/Logic/DataObjects/GeographyWithPeopleDataObject.cs b/Logic/DataObjects/GeographyWithPeopleDataObject.cs index db8efd9d..1db8377e 100644 --- a/Logic/DataObjects/GeographyWithPeopleDataObject.cs +++ b/Logic/DataObjects/GeographyWithPeopleDataObject.cs @@ -15,10 +15,10 @@ namespace Swarmops.Logic.DataObjects #endif public static GeographyWithPeople[] SelectSortedStatic (int orgId) { - Organizations orgs = Organization.FromIdentity (orgId).GetAllBelow(); + Organizations orgs = Organization.FromIdentity (orgId).ThisAndBelow(); List resList = new List(); - Geographies tree = Geography.Root.GetAllBelow(); + Geographies tree = Geography.Root.ThisAndBelow(); foreach (Geography geo in tree) { GeographyWithPeople row = new GeographyWithPeople(); @@ -29,7 +29,7 @@ namespace Swarmops.Logic.DataObjects row.LeadContent = ""; row.SecondsContent = ""; row.OrgId = orgId; - Geographies gTree = geo.GetAllBelow(); + Geographies gTree = geo.ThisAndBelow(); int[] members = SwarmDb.GetDatabaseForReading() .GetMembersForOrganizationsAndGeographies (orgs.Identities, gTree.Identities); } diff --git a/Logic/Financial/FinancialAccount.cs b/Logic/Financial/FinancialAccount.cs index 553f920b..da0e35e4 100644 --- a/Logic/Financial/FinancialAccount.cs +++ b/Logic/Financial/FinancialAccount.cs @@ -418,9 +418,9 @@ namespace Swarmops.Logic.Financial return FromIdentityAggressive (accountId); } - public FinancialAccounts GetAllBelow() + public FinancialAccounts ThisAndBelow() { - return FinancialAccounts.GetAllBelow (this); + return FinancialAccounts.ThisAndBelow (this); } } } \ No newline at end of file diff --git a/Logic/Security/Authority.cs b/Logic/Security/Authority.cs index 320744ad..b8a08bd5 100644 --- a/Logic/Security/Authority.cs +++ b/Logic/Security/Authority.cs @@ -329,7 +329,7 @@ namespace Swarmops.Logic.Security // Org lookup will always be needed. Geo lookup may be needed for case 3. - Organizations orgStructure = this.Organization.GetAllBelow(); + Organizations orgStructure = this.Organization.ThisAndBelow(); int[] orgIds = orgStructure.Identities; foreach (int orgId in orgIds) { @@ -395,7 +395,7 @@ namespace Swarmops.Logic.Security return new People(); // also return empty list } - Geographies geoStructure = this.Position.Geography.GetAllBelow(); + Geographies geoStructure = this.Position.Geography.ThisAndBelow(); int[] geoIds = geoStructure.Identities; foreach (int geoId in geoIds) { diff --git a/Logic/Structure/Geography.cs b/Logic/Structure/Geography.cs index d3e45708..39efe1e0 100644 --- a/Logic/Structure/Geography.cs +++ b/Logic/Structure/Geography.cs @@ -65,6 +65,14 @@ namespace Swarmops.Logic.Structure public static readonly int IgnoreGeography = -1; // Used as parameter to methods where geography is optional + public Tree Tree + { + get + { + Geographies geographies = this.ThisAndBelow(); + return Tree.FromCollection (geographies); + } + } public Geographies Children { @@ -87,7 +95,7 @@ namespace Swarmops.Logic.Structure get { return FromIdentity (ParentIdentity); } } - public Geographies GetAllBelow() + public Geographies ThisAndBelow() { return Geographies.FromArray (GeographyCache.GetGeographyTree (Identity)); // return Geographies.FromArray(SwarmDb.GetDatabaseForReading().GetGeographyTree(Identity)); diff --git a/Logic/Structure/Organization.cs b/Logic/Structure/Organization.cs index 200e3a14..bd1e2761 100644 --- a/Logic/Structure/Organization.cs +++ b/Logic/Structure/Organization.cs @@ -8,6 +8,7 @@ using Swarmops.Basic.Types; using Swarmops.Basic.Types.Structure; using Swarmops.Basic.Types.Swarm; using Swarmops.Common.Enums; +using Swarmops.Common.Generics; using Swarmops.Database; using Swarmops.Logic.Cache; using Swarmops.Logic.Communications; @@ -191,6 +192,14 @@ namespace Swarmops.Logic.Structure get { return Organizations.FromArray (OrganizationCache.GetOrganizationChildren (Identity)); } } + public Tree Tree + { + get + { + Organizations orgs = this.ThisAndBelow(); + return Tree.FromCollection (orgs); + } + } public OrganizationFinancialAccounts FinancialAccounts { diff --git a/Logic/Structure/Organizations.cs b/Logic/Structure/Organizations.cs index cbca6b64..f01ea567 100644 --- a/Logic/Structure/Organizations.cs +++ b/Logic/Structure/Organizations.cs @@ -143,7 +143,7 @@ namespace Swarmops.Logic.Structure foreach (Organization orgMajor in this) { - Organizations orgTree = orgMajor.GetAllBelow(); + Organizations orgTree = orgMajor.ThisAndBelow(); foreach (Organization orgMinor in orgTree) { diff --git a/Logic/Swarm/Roles.cs b/Logic/Swarm/Roles.cs index 001182aa..b0a6401c 100644 --- a/Logic/Swarm/Roles.cs +++ b/Logic/Swarm/Roles.cs @@ -92,10 +92,10 @@ namespace Swarmops.Logic.Swarm Organizations orgTree = null; Geographies nodeTree = null; int[] nodeIds; - orgTree = Organization.FromIdentity (organizationId).GetAllBelow(); + orgTree = Organization.FromIdentity (organizationId).ThisAndBelow(); if (geographyId > 0) { - nodeTree = Geography.FromIdentity (geographyId).GetAllBelow(); + nodeTree = Geography.FromIdentity (geographyId).ThisAndBelow(); nodeIds = nodeTree.Identities; } else @@ -137,12 +137,12 @@ namespace Swarmops.Logic.Swarm int[] nodeIds; int[] orgIds; - orgTree = Organization.FromIdentity (organizationId).GetAllBelow(); + orgTree = Organization.FromIdentity (organizationId).ThisAndBelow(); orgIds = orgTree.Identities; if (geographyId > 0) { - nodeTree = Geography.FromIdentity (geographyId).GetAllBelow(); + nodeTree = Geography.FromIdentity (geographyId).ThisAndBelow(); nodeIds = nodeTree.Identities; } else @@ -235,8 +235,8 @@ namespace Swarmops.Logic.Swarm // Expensive op: BasicPersonRole[] basicPersonRoles = - SwarmDb.GetDatabaseForReading().GetRolesForOrganizationsGeographies (organization.GetAllBelow().Identities, - geography.GetAllBelow().Identities); + SwarmDb.GetDatabaseForReading().GetRolesForOrganizationsGeographies (organization.ThisAndBelow().Identities, + geography.ThisAndBelow().Identities); Dictionary lookup = new Dictionary(); foreach (BasicPersonRole basicRole in basicPersonRoles) diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs index d5db77bc..f023602b 100644 --- a/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs +++ b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs @@ -129,7 +129,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks geoNameLookup[countryCode] = countryGeoId; } - Geographies countryGeographies = Geography.FromIdentity(countryGeoId).GetAllBelow(); + Geographies countryGeographies = Geography.FromIdentity(countryGeoId).ThisAndBelow(); foreach (Geography geography in countryGeographies) { diff --git a/Utility/BotCode/RosterHousekeeping.cs b/Utility/BotCode/RosterHousekeeping.cs index 84adb71e..314c4d12 100644 --- a/Utility/BotCode/RosterHousekeeping.cs +++ b/Utility/BotCode/RosterHousekeeping.cs @@ -19,7 +19,7 @@ namespace Swarmops.Utility.BotCode public static string ExportMemberList (int organizationIdRoot, DateTime membersAfter, DateTime membersBefore) { - Organizations orgs = Organization.FromIdentity (organizationIdRoot).GetAllBelow(); + Organizations orgs = Organization.FromIdentity (organizationIdRoot).ThisAndBelow(); StringBuilder result = new StringBuilder(); result.Append (