diff --git a/Basic/Types/Financial/BasicFinancialAccount.cs b/Basic/Types/Financial/BasicFinancialAccount.cs index 0cd98a39..383c1623 100644 --- a/Basic/Types/Financial/BasicFinancialAccount.cs +++ b/Basic/Types/Financial/BasicFinancialAccount.cs @@ -3,7 +3,7 @@ using Swarmops.Common.Interfaces; namespace Swarmops.Basic.Types.Financial { - public class BasicFinancialAccount : IHasIdentity + public class BasicFinancialAccount : IHasIdentity, IHasParentIdentity { public BasicFinancialAccount (int financialAccountId, string name, FinancialAccountType accountType, int organizationId, int parentFinancialAccountId, int ownerPersonId, @@ -52,12 +52,10 @@ namespace Swarmops.Basic.Types.Financial public int LinkBackward { protected get; set; } public int LinkForward { protected get; set; } - #region IHasIdentity Members + #region Interface Members - public int Identity - { - get { return FinancialAccountId; } - } + public int Identity { get { return FinancialAccountId; } } + public int ParentIdentity { get { return ParentFinancialAccountId; } } #endregion } diff --git a/Basic/Types/Structure/BasicOrganization.cs b/Basic/Types/Structure/BasicOrganization.cs index a232d7f3..a4f44c16 100644 --- a/Basic/Types/Structure/BasicOrganization.cs +++ b/Basic/Types/Structure/BasicOrganization.cs @@ -2,16 +2,14 @@ using Swarmops.Common.Interfaces; namespace Swarmops.Basic.Types.Structure { - public class BasicOrganization : IHasIdentity + public class BasicOrganization : IHasIdentity, IHasParentIdentity { private string nameShort; - #region IHasIdentity Members + #region Interface Members - public int Identity - { - get { return this.OrganizationId; } - } + public int Identity { get { return this.OrganizationId; } } + public int ParentIdentity { get { return this.ParentOrganizationId; } } #endregion diff --git a/Logic/DataObjects/OrganizationDataObject.cs b/Logic/DataObjects/OrganizationDataObject.cs index bafd8cef..27046035 100644 --- a/Logic/DataObjects/OrganizationDataObject.cs +++ b/Logic/DataObjects/OrganizationDataObject.cs @@ -315,7 +315,7 @@ namespace Swarmops.Logic.DataObjects Geographies line = Geography.FromIdentity (org.AnchorGeographyId).GetLine(); Geography[] arrLine = line.ToArray(); Array.Reverse (arrLine); - Countries countries = Countries.GetAll(); + Countries countries = Countries.All; int foundCntry = 1; //sweden foreach (Geography geo in arrLine) { diff --git a/Logic/Financial/FinancialAccount.cs b/Logic/Financial/FinancialAccount.cs index 0d4acd0e..27b0991c 100644 --- a/Logic/Financial/FinancialAccount.cs +++ b/Logic/Financial/FinancialAccount.cs @@ -2,14 +2,13 @@ using System; using Swarmops.Basic.Types.Financial; using Swarmops.Common.Enums; using Swarmops.Database; -using Swarmops.Logic.Interfaces; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Financial { - public class FinancialAccount : BasicFinancialAccount, ITreeNode, IOwnerSettable + public class FinancialAccount : BasicFinancialAccount, IOwnerSettable { private FinancialAccount (BasicFinancialAccount basic) : base (basic) @@ -214,8 +213,6 @@ namespace Swarmops.Logic.Financial } } - #region ITreeNode Members - private ObjectOptionalData _optionalData; public Geography AssignedGeography @@ -269,18 +266,11 @@ namespace Swarmops.Logic.Financial } } - public int ParentIdentity - { - get { return ParentFinancialAccountId; } - } - public int[] ChildrenIdentities { get { return Children.Identities; } } - #endregion - #region IOwnerSettable members public void SetOwner (Person newOwner) diff --git a/Logic/Interfaces/TreeNode.cs b/Logic/Interfaces/TreeNode.cs deleted file mode 100644 index bc19540c..00000000 --- a/Logic/Interfaces/TreeNode.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections.Generic; - -namespace Swarmops.Logic.Interfaces -{ - internal interface ITreeNode - { - int Identity { get; } - - int ParentIdentity { get; } - - string Name { get; } - - int[] ChildrenIdentities { get; } - } - - public interface ITreeNodeObject - { - int Identity { get; } - - int ParentIdentity { get; } - - string Name { get; } - - int[] ChildrenIdentities { get; } - - ITreeNodeObject ParentObject { get; } - - List ChildObjects { get; } - } -} \ No newline at end of file diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index 4c8a303c..ee126495 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -202,7 +202,6 @@ - diff --git a/Logic/Structure/Countries.cs b/Logic/Structure/Countries.cs index 7027d758..f9b2242a 100644 --- a/Logic/Structure/Countries.cs +++ b/Logic/Structure/Countries.cs @@ -2,12 +2,31 @@ using System.Collections.Generic; using Swarmops.Basic.Types; using Swarmops.Basic.Types.Structure; using Swarmops.Database; +using Swarmops.Logic.Cache; +using Swarmops.Logic.Support; namespace Swarmops.Logic.Structure { - public class Countries : List + public class Countries : PluralBase { - public static Countries GetAll() + public static Countries All + { + get + { + // Cached - the list of countries doesn't change that much + + Countries result = (Countries) GuidCache.Get ("Countries.All"); + if (result == null) + { + result = Countries.GetAll(); + GuidCache.Set ("Countries.All", result); + } + + return result; + } + } + + private static Countries GetAll() // private - uncached version shouldn't be used outside this class { return FromArray (SwarmDb.GetDatabaseForReading().GetAllCountries()); } @@ -17,16 +36,5 @@ namespace Swarmops.Logic.Structure return FromArray (SwarmDb.GetDatabaseForReading().GetCountriesInUse()); } - public static Countries FromArray (BasicCountry[] basicArray) - { - Countries result = new Countries {Capacity = (basicArray.Length*11/10)}; - - foreach (BasicCountry basic in basicArray) - { - result.Add (Country.FromBasic (basic)); - } - - return result; - } } } \ No newline at end of file diff --git a/Logic/Structure/Geography.cs b/Logic/Structure/Geography.cs index 375dd3ee..6b703e0a 100644 --- a/Logic/Structure/Geography.cs +++ b/Logic/Structure/Geography.cs @@ -7,12 +7,11 @@ using Swarmops.Common.Enums; using Swarmops.Common.Generics; using Swarmops.Database; using Swarmops.Logic.Cache; -using Swarmops.Logic.Interfaces; namespace Swarmops.Logic.Structure { [Serializable] - public class Geography : BasicGeography, ITreeNode, ITreeNodeObject + public class Geography : BasicGeography { #region Construction and Creation @@ -64,45 +63,8 @@ namespace Swarmops.Logic.Structure public static readonly int RootIdentity = 1; // The identity of the root geography (i.e., "World") - public static readonly int SwedenId = 30; - public static readonly int DenmarkId = 357; - public static readonly int FinlandId = 358; - public static readonly int IgnoreGeography = -1; // Used as parameter to methods where geography is optional - #region ITreeNode Members - - public int ParentIdentity - { - get { return ParentGeographyId; } - } - - public int[] ChildrenIdentities - { - get { return Children.Identities; } - } - - [XmlIgnore] // interface cannot be serialized - [SoapIgnore] - public ITreeNodeObject ParentObject - { - get { return Parent; } - } - - [XmlIgnore] // interface cannot be serialized - [SoapIgnore] - public List ChildObjects - { - get - { - List retVal = new List(); - foreach (Geography child in Children) - retVal.Add (child); - return retVal; - } - } - - #endregion public Geographies Children { diff --git a/Logic/Structure/Organization.cs b/Logic/Structure/Organization.cs index 8761cda4..3d9bb2ca 100644 --- a/Logic/Structure/Organization.cs +++ b/Logic/Structure/Organization.cs @@ -12,13 +12,12 @@ using Swarmops.Database; using Swarmops.Logic.Cache; using Swarmops.Logic.Communications; using Swarmops.Logic.Financial; -using Swarmops.Logic.Interfaces; using Swarmops.Logic.Support; using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Structure { - public class Organization : BasicOrganization, ITreeNode, IComparable, ITreeNodeObject + public class Organization : BasicOrganization, IComparable { #region Creation and Construction @@ -132,36 +131,6 @@ namespace Swarmops.Logic.Structure #endregion - #region ITreeNode Members - - public int ParentIdentity - { - get { return ParentOrganizationId; } - } - - - public int[] ChildrenIdentities - { - get { return Children.Identities; } - } - - public ITreeNodeObject ParentObject - { - get { return Parent; } - } - - public List ChildObjects - { - get - { - List retVal = new List(); - foreach (Organization child in Children) - retVal.Add (child); - return retVal; - } - } - - #endregion private ObjectOptionalData OptionalData { diff --git a/Site5/Automation/GetGeographyData.asmx b/Site5/Automation/GetGeographyData.asmx index f08466b8..1165d0e9 100644 --- a/Site5/Automation/GetGeographyData.asmx +++ b/Site5/Automation/GetGeographyData.asmx @@ -13,7 +13,7 @@ public class GetGeographyData : System.Web.Services.WebService [WebMethod] public Countries GetCountries() { - return Countries.GetAll(); + return Countries.All; } [WebMethod] diff --git a/Site5/Automation/Json-GeographiesTree.aspx.cs b/Site5/Automation/Json-GeographiesTree.aspx.cs index b21afb32..b8c65b24 100644 --- a/Site5/Automation/Json-GeographiesTree.aspx.cs +++ b/Site5/Automation/Json-GeographiesTree.aspx.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.Threading; using Resources; using Swarmops.Common.Generics; +using Swarmops.Logic.Cache; using Swarmops.Logic.Structure; namespace Swarmops.Frontend.Automation @@ -48,15 +49,21 @@ namespace Swarmops.Frontend.Automation // Not in cache. Construct. _geoTree = Geographies.Tree; - Countries countries = Countries.GetAll(); - _countryLookup = new Dictionary(); + _countryLookup = (Dictionary) GuidCache.Get ("Json-GeographiesTree._countryLookup"); - foreach (Country country in countries) + if (_countryLookup == null) { - if (country.GeographyId > Geography.RootIdentity) + Countries countries = Countries.All; + _countryLookup = new Dictionary(); + + foreach (Country country in countries) { - _countryLookup[country.GeographyId] = country; + if (country.GeographyId > Geography.RootIdentity) + { + _countryLookup[country.GeographyId] = country; + } } + GuidCache.Set("Json-GeographiesTree._countryLookup", _countryLookup); } List> rootNodes = _geoTree.RootNodes; @@ -66,7 +73,7 @@ namespace Swarmops.Frontend.Automation rootNodes = _geoTree[parentGeographyId].Children; } - accountsJson = RecurseTreeMap (rootNodes, false); + accountsJson = RecurseTreeMap (rootNodes, initialExpand); Cache.Insert (cacheKey, accountsJson, null, DateTime.Now.AddMinutes (15), TimeSpan.Zero); // cache lasts for fifteen minutes, no sliding expiration @@ -86,8 +93,27 @@ namespace Swarmops.Frontend.Automation { Geography geography = geographyNode.Data; + string geoName = TestLocalization (geography.Name); + + if (_countryLookup.ContainsKey (geography.Identity)) + { + // Special case for country nodes: "[NativeName] ([LocalizedName])", e.g. "Deutschland (Tyskland)" for Germany when in Swedish + + string localizedCountryName = GeographyNames.ResourceManager.GetString("Country_" + _countryLookup[geography.Identity].Code); + string nativeCountryName = geography.Name.Split ('(')[0].Trim(); + + if (localizedCountryName != nativeCountryName) + { + geoName = nativeCountryName + " (" + localizedCountryName + ")"; + } + else + { + geoName = nativeCountryName; + } + } + string element = string.Format ("\"id\":{0},\"text\":\"{1}\"", geography.Identity, - JsonSanitize (TestLocalization (geography.Name))); + JsonSanitize (TestLocalization (geoName))); if (_countryLookup.ContainsKey (geography.Identity)) { diff --git a/Site5/Pages/v5/Swarm/AddPerson.aspx.cs b/Site5/Pages/v5/Swarm/AddPerson.aspx.cs index 00d92706..cadf9986 100644 --- a/Site5/Pages/v5/Swarm/AddPerson.aspx.cs +++ b/Site5/Pages/v5/Swarm/AddPerson.aspx.cs @@ -42,7 +42,7 @@ namespace Swarmops.Frontend.Pages.v5.Swarm private void Populate() { - Countries allCountries = Countries.GetAll(); + Countries allCountries = Countries.All; this.DropCountries.Items.Clear(); foreach (Country country in allCountries)