diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt index 3730ea6a..2aaf9886 100644 --- a/Database/Schemata/revisions.txt +++ b/Database/Schemata/revisions.txt @@ -4,4 +4,4 @@ 0004 - Added BankProfile tables and stored procs to insert/update. [Rick Falkvinge] 0005 - Changed PostalCodeLength for NO DK to 4; for GH to zero; added Country.Currency. [Rick Falkvinge] 0006 - Added Memberships.LocalNumber and .FamilyNumber; added CurrencyExchangeRate tables/procs. [Rick Falkvinge] - +0007 - NL update; added Lat/Long to PostalCodes and to People, indexed [RF] diff --git a/Database/Schemata/upgrade-0007.sql b/Database/Schemata/upgrade-0007.sql new file mode 100644 index 00000000..1a4c590f --- /dev/null +++ b/Database/Schemata/upgrade-0007.sql @@ -0,0 +1,15 @@ +UPDATE `Countries` SET `CurrencyCode`='EUR', `PostalCodeLength`='6' WHERE `CountryCode`='NL' + +# + +ALTER TABLE `PostalCodes` +CHANGE COLUMN `Lat` `Latitude` DOUBLE NOT NULL DEFAULT 0.0 , +CHANGE COLUMN `Long` `Longitude` DOUBLE NOT NULL DEFAULT 0.0 + +# + +ALTER TABLE `People` +ADD COLUMN `Latitude` DOUBLE NOT NULL DEFAULT 0.0 AFTER `GeographyId`, +ADD COLUMN `Longitude` DOUBLE NOT NULL DEFAULT 0.0 AFTER `Latitude`, +ADD INDEX `Index_Latitude` (`Latitude` ASC), +ADD INDEX `Index_Longitude` (`Longitude` ASC) diff --git a/Site5/Controls/v5/UI/ExternalScripts.ascx.cs b/Site5/Controls/v5/UI/ExternalScripts.ascx.cs index 419db476..39b5e3e6 100644 --- a/Site5/Controls/v5/UI/ExternalScripts.ascx.cs +++ b/Site5/Controls/v5/UI/ExternalScripts.ascx.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Text; +using System.Web.UI; using Swarmops.Logic.Support; namespace Swarmops.Frontend.Controls.v5.UI @@ -38,9 +39,14 @@ namespace Swarmops.Frontend.Controls.v5.UI string[] controlNames = Controls.Split (','); foreach (string controlName in controlNames) { - scriptRef.AppendFormat ("\r\n", - controlName.Trim().ToLowerInvariant()); + string controlNameLower = controlName.Trim().ToLowerInvariant(); + if (controlNameLower != "unknown") + { + scriptRef.AppendFormat ( + "\r\n", + controlNameLower); + } } this.LiteralReference.Text = scriptRef.ToString(); diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx new file mode 100644 index 00000000..79df27db --- /dev/null +++ b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx @@ -0,0 +1,106 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="PopulateCountry1.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Admin.Hacks.PopulateCountry1" %> +<%@ Register src="~/Controls/v5/Base/FileUpload.ascx" tagname="FileUpload" tagprefix="Swarmops5" %> +<%@ Register TagPrefix="Swarmops5" TagName="ExternalScripts" Src="~/Controls/v5/UI/ExternalScripts.ascx" %> +<%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %> + + + + + + + + + + + + +
+
+ +
+ + +
+
+
+
+
+ +
+ + + + + + diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs new file mode 100644 index 00000000..259f42dc --- /dev/null +++ b/Site5/Pages/v5/Admin/Hacks/PopulateCountry1.aspx.cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Threading; +using System.Web.Services; +using Swarmops.Basic.Enums; +using Swarmops.Database; +using Swarmops.Logic.Cache; +using Swarmops.Logic.Security; +using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Frontend.Pages.v5.Admin.Hacks +{ + public partial class PopulateCountry1 : PageV5Base + { + protected void Page_Load (object sender, EventArgs e) + { + PageTitle = "Populate Country 1 - Geotree"; + PageIcon = "iconshock-battery-drill"; + InfoBoxLiteral = "You've taken a wrong turn if you're even seeing this page. It's for development purposes."; + } + + + private void Localize() + { + } + + + [WebMethod (true)] + public static void InitializeProcessing (string guid) + { + // Start an async thread that does all the work, then return + + + // FORMAT OF FILE + // + // Tab separated fields + // + // [countrycode] [tab] [geo1] .. [geo_n] + // + // example: + // + // NL [Tab] Greater Amsterdam + // NL [Tab] Greater Amsterdam [Tab] Amsterdam + // NL [Tab] Greater Amsterdam [Tab] Amsterdam [Tab] Wallen + // + // To populate all four nodes, only the last line is necessary, but all three lines are valid. + // + // Nodes are not re-populated on repetition. Node names within a country scope are required to + // be unique. + + + if (!PilotInstallationIds.IsPilot (PilotInstallationIds.SwarmopsLive) && !Debugger.IsAttached) + { + throw new UnauthorizedAccessException("This may only run on Swarmops Master"); + } + + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + if ( + !authData.CurrentUser.HasAccess (new Access (authData.CurrentOrganization, AccessAspect.Unknown, + AccessType.Write))) + { + throw new UnauthorizedAccessException(); + } + + Thread initThread = new Thread (ProcessUploadThread); + initThread.Start (guid); + } + + private static void ProcessUploadThread (object guidObject) + { + string guid = (string) guidObject; + Documents documents = Documents.RecentFromDescription (guid); + Document uploadedDoc = documents[0]; + string data = string.Empty; + int count = 0; + + using (StreamReader reader = uploadedDoc.GetReader (1252)) + { + data = reader.ReadToEnd(); + } + + string[] lines = data.Split ('\n'); + + Random random = new Random(); + + Dictionary geoNameLookup = new Dictionary(); + + foreach (string lineRaw in lines) + { + count++; + string line = lineRaw.Trim(); + string[] lineParts = line.Split ('\t'); + + if (lineParts.Length < 2) + { + continue; // at least country and one geo required + } + + // set progress + + int percent = (count*99)/lines.Length; + if (percent == 0) + { + percent = 1; + } + GuidCache.Set (guid + "-Progress", percent); + + // process + + string countryCode = lineParts[0].Trim().ToUpperInvariant(); + + int countryGeoId = Geography.RootIdentity; + if (geoNameLookup.ContainsKey (countryCode)) + { + countryGeoId = geoNameLookup[countryCode]; + } + else + { + Country country = Country.FromCode (countryCode); + if (countryGeoId == Geography.RootIdentity) // country not initialized as node + { + countryGeoId = + SwarmDb.GetDatabaseForWriting().CreateGeography (country.Name + " (" + country.Name + ")", + Geography.RootIdentity); // TODO: Locate country + SwarmDb.GetDatabaseForWriting().SetCountryGeographyId (country.Identity, countryGeoId); + geoNameLookup[countryCode] = countryGeoId; + } + + Geographies countryGeographies = Geography.FromIdentity(countryGeoId).GetTree(); + + foreach (Geography geography in countryGeographies) + { + geoNameLookup[countryCode + geography.Name] = geography.Identity; + } + } + + int lastGeoId = countryGeoId; + for (int partIndex = 1; partIndex < lineParts.Length; partIndex++) + { + if (geoNameLookup.ContainsKey (countryCode + lineParts[partIndex])) + { + // geography exists + lastGeoId = geoNameLookup[countryCode + lineParts[partIndex]]; + } + else + { + // geography does not exist yet: create + + int newGeoId = SwarmDb.GetDatabaseForWriting().CreateGeography (lineParts[partIndex], lastGeoId); + geoNameLookup[countryCode + lineParts[partIndex]] = newGeoId; + lastGeoId = newGeoId; + } + + } + + } + + GuidCache.Set (guid + "-Progress", 100); + } + } +} \ No newline at end of file diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx b/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx new file mode 100644 index 00000000..43cd962b --- /dev/null +++ b/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx @@ -0,0 +1,106 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="PopulateCountry2.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Admin.Hacks.PopulateCountry2" %> +<%@ Register src="~/Controls/v5/Base/FileUpload.ascx" tagname="FileUpload" tagprefix="Swarmops5" %> +<%@ Register TagPrefix="Swarmops5" TagName="ExternalScripts" Src="~/Controls/v5/UI/ExternalScripts.ascx" %> +<%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %> + + + + + + + + + + + + +
+
+ +
+ + +
+
+
+
+
+ +
+ + + + + + diff --git a/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx.cs b/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx.cs new file mode 100644 index 00000000..9f336ef4 --- /dev/null +++ b/Site5/Pages/v5/Admin/Hacks/PopulateCountry2.aspx.cs @@ -0,0 +1,110 @@ +using System; +using System.Diagnostics; +using System.Globalization; +using System.IO; +using System.Threading; +using System.Web.Services; +using Swarmops.Basic.Enums; +using Swarmops.Logic.Cache; +using Swarmops.Logic.Security; +using Swarmops.Logic.Structure; +using Swarmops.Logic.Support; +using Swarmops.Logic.Swarm; + +namespace Swarmops.Frontend.Pages.v5.Admin.Hacks +{ + public partial class PopulateCountry2 : PageV5Base + { + protected void Page_Load (object sender, EventArgs e) + { + PageTitle = "Populate Country - Postal Codes, Cities"; + PageIcon = "iconshock-battery-drill"; + InfoBoxLiteral = "You've taken a wrong turn if you're even seeing this page. It's for development purposes."; + } + + + private void Localize() + { + } + + + [WebMethod (true)] + public static void InitializeProcessing (string guid) + { + // Start an async thread that does all the work, then return + + if (!PilotInstallationIds.IsPilot(PilotInstallationIds.SwarmopsLive) && !Debugger.IsAttached) + { + throw new UnauthorizedAccessException("This may only run on Swarmops Master"); + } + + + + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + if ( + !authData.CurrentUser.HasAccess (new Access (authData.CurrentOrganization, AccessAspect.Unknown, + AccessType.Write))) + { + throw new UnauthorizedAccessException(); + } + + Thread initThread = new Thread (ProcessUploadThread); + initThread.Start (guid); + } + + private static void ProcessUploadThread (object guidObject) + { + string guid = (string) guidObject; + Documents documents = Documents.RecentFromDescription (guid); + Document uploadedDoc = documents[0]; + string data = string.Empty; + int count = 0; + + using (StreamReader reader = uploadedDoc.GetReader (1252)) + { + data = reader.ReadToEnd(); + } + + string[] lines = data.Split ('\n'); + + Random random = new Random(); + + foreach (string lineRaw in lines) + { + count++; + string line = lineRaw.Trim(); + string[] lineParts = line.Split ('\t'); + + if (lineParts.Length < 12) + { + continue; + } + + int percent = (count*99)/lines.Length; + if (percent == 0) + { + percent = 1; + } + GuidCache.Set (guid + "-Progress", percent); + + string name = lineParts[0] + " " + lineParts[1]; + PersonGender gender = lineParts[2] == "male" ? PersonGender.Male : PersonGender.Female; + DateTime dateOfBirth = DateTime.Parse (lineParts[7], new CultureInfo ("en-US"), DateTimeStyles.None); + Country country = Country.FromCode (lineParts[6]); + + + Person newPerson = Person.Create (name, string.Empty, string.Empty, lineParts[8], lineParts[3], + lineParts[4].Replace (" ", ""), lineParts[5], lineParts[6], dateOfBirth, gender); + + newPerson.NationalIdNumber = lineParts[9]; + newPerson.Longitude = lineParts[10]; + newPerson.Latitude = lineParts[11]; + + newPerson.AddMembership (1, DateTime.Today.AddDays (random.Next (365))); + } + + GuidCache.Set (guid + "-Progress", 100); + } + } +} \ No newline at end of file diff --git a/Site5/Pages/v5/Comms/SendMassMessage.aspx.cs b/Site5/Pages/v5/Comms/SendMassMessage.aspx.cs index d7e99365..269f5bd7 100644 --- a/Site5/Pages/v5/Comms/SendMassMessage.aspx.cs +++ b/Site5/Pages/v5/Comms/SendMassMessage.aspx.cs @@ -23,6 +23,8 @@ namespace Swarmops.Frontend.Pages.Comms this.TextMessage.Style[HtmlTextWriterStyle.Width] = "674px"; this.TextMessage.Style["resize"] = "none"; + + EasyUIControlsUsed = EasyUIControl.Tree; } private void Localize() diff --git a/Site5/Pages/v5/Init/Default.aspx.cs b/Site5/Pages/v5/Init/Default.aspx.cs index 2bcaaf38..f7e988d8 100644 --- a/Site5/Pages/v5/Init/Default.aspx.cs +++ b/Site5/Pages/v5/Init/Default.aspx.cs @@ -170,28 +170,6 @@ public partial class Pages_v5_Init_Default : Page } - private string GetBuildIdentity() - { - // Read build number if not loaded, or set to "Private" if none - - if (_buildIdentity == null) - { - try - { - using (StreamReader reader = File.OpenText (HttpContext.Current.Request.MapPath ("~/BuildIdentity.txt")) - ) - { - _buildIdentity = "Build " + reader.ReadLine(); - } - } - catch (Exception) - { - _buildIdentity = "Private Build"; - } - } - - return _buildIdentity; - } [WebMethod] public static PermissionsAnalysis FirstCredentialsTest