Made fakemember populator more flexible
This commit is contained in:
+2
-2
@@ -19,7 +19,7 @@ namespace Resources.Pages {
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option or rebuild the Visual Studio project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Web.Application.StronglyTypedResourceProxyBuilder", "11.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Web.Application.StronglyTypedResourceProxyBuilder", "14.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Admin {
|
||||
@@ -214,7 +214,7 @@ namespace Resources.Pages {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to The new organization has been created. You have been given an initial two-year {0} in the organization, so you can work with it and set it up properly. To switch to working with your new organization, use the control panel top right..
|
||||
/// Looks up a localized string similar to The new organization has been created. You have been given an initial ten-year {0} in the organization, so you can work with it and set it up properly. To switch to working with your new organization, use this control panel (available later under Admin / Organization Settings)..
|
||||
/// </summary>
|
||||
internal static string CreateOrganization_Success {
|
||||
get {
|
||||
|
||||
@@ -175,7 +175,7 @@
|
||||
<comment>This can be "members", etc.</comment>
|
||||
</data>
|
||||
<data name="CreateOrganization_Success" xml:space="preserve">
|
||||
<value>The new organization has been created. You have been given an initial two-year {0} in the organization, so you can work with it and set it up properly. To switch to working with your new organization, use the control panel top right.</value>
|
||||
<value>The new organization has been created. You have been given an initial ten-year {0} in the organization, so you can work with it and set it up properly. To switch to working with your new organization, use this control panel (available later under Admin / Organization Settings).</value>
|
||||
<comment>The {0} is membership, employment, citizenship, residence, etc.</comment>
|
||||
</data>
|
||||
<data name="CreateOrganization_Titles" xml:space="preserve">
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
|
||||
Positions.CreateOrganizationDefaultPositions (newOrganization, titleType);
|
||||
|
||||
Participation.Create(CurrentUser, newOrganization, DateTime.MaxValue);
|
||||
Participation.Create(CurrentUser, newOrganization, DateTime.UtcNow.AddYears(10));
|
||||
|
||||
string successMessage = String.Format (Resources.Pages.Admin.CreateOrganization_Success,
|
||||
Participant.Localized (peopleLabel, TitleVariant.Ship));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@@ -64,6 +65,46 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
// Fields:
|
||||
// 0 Firstname
|
||||
// 1 Lastname
|
||||
// 2 Gender
|
||||
// 3 Street
|
||||
// 4 Postal
|
||||
// 5 City
|
||||
// 6 CountryCode
|
||||
// 7 DOB
|
||||
// 8 Phone
|
||||
// 9 NationalID
|
||||
// 10 Longitude
|
||||
// 11 Latitude
|
||||
|
||||
|
||||
// below is an N^2 loop but doesn't matter in such a small context
|
||||
|
||||
Dictionary<FakePersonFields,int> fieldNameLookup = new Dictionary<FakePersonFields, int>();
|
||||
string[] headerParts = lines[0].Split('\t');
|
||||
|
||||
foreach (string fieldName in Enum.GetValues(typeof(FakePersonFields)))
|
||||
{
|
||||
bool found = false;
|
||||
for (int index = 0; index < headerParts.Length; index++)
|
||||
{
|
||||
if (headerParts[index].Trim() == fieldName)
|
||||
{
|
||||
fieldNameLookup[(FakePersonFields) Enum.Parse(typeof(FakePersonFields), fieldName)] = index;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
throw new InvalidOperationException("Field key \"" + fieldName +
|
||||
"\" was not supplied or found in data file");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string lineRaw in lines)
|
||||
{
|
||||
count++;
|
||||
@@ -75,6 +116,12 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
|
||||
continue;
|
||||
}
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
// header line
|
||||
continue;
|
||||
}
|
||||
|
||||
int percent = (count*99)/lines.Length;
|
||||
if (percent == 0)
|
||||
{
|
||||
@@ -82,23 +129,41 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
|
||||
}
|
||||
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]);
|
||||
string name = lineParts[fieldNameLookup[FakePersonFields.GivenName]] + " " + lineParts[fieldNameLookup[FakePersonFields.Surname]];
|
||||
PersonGender gender = lineParts[fieldNameLookup[FakePersonFields.Gender]] == "male" ? PersonGender.Male : PersonGender.Female;
|
||||
DateTime dateOfBirth = DateTime.Parse (lineParts[fieldNameLookup[FakePersonFields.Birthday]], new CultureInfo ("en-US"), DateTimeStyles.None);
|
||||
Country country = Country.FromCode (lineParts[fieldNameLookup[FakePersonFields.Country]]);
|
||||
|
||||
|
||||
Person newPerson = Person.Create (name, string.Empty, string.Empty, lineParts[8], lineParts[3],
|
||||
lineParts[4].Replace (" ", ""), lineParts[5], lineParts[6], dateOfBirth, gender);
|
||||
Person newPerson = Person.Create (name, string.Empty, string.Empty, lineParts[fieldNameLookup[FakePersonFields.TelephoneNumber]], lineParts[fieldNameLookup[FakePersonFields.StreetAddress]],
|
||||
lineParts[fieldNameLookup[FakePersonFields.ZipCode]].Replace (" ", ""), lineParts[fieldNameLookup[FakePersonFields.City]], lineParts[fieldNameLookup[FakePersonFields.Country]], dateOfBirth, gender);
|
||||
|
||||
newPerson.NationalIdNumber = lineParts[9];
|
||||
newPerson.Longitude = lineParts[10];
|
||||
newPerson.Latitude = lineParts[11];
|
||||
newPerson.NationalIdNumber = lineParts[fieldNameLookup[FakePersonFields.NationalID]];
|
||||
newPerson.Longitude = lineParts[fieldNameLookup[FakePersonFields.Longitude]];
|
||||
newPerson.Latitude = lineParts[fieldNameLookup[FakePersonFields.Latitude]];
|
||||
|
||||
newPerson.AddParticipation (Organization.Sandbox, DateTime.Today.AddDays (3650 + random.Next (365)));
|
||||
}
|
||||
|
||||
GuidCache.Set (guid + "-Progress", 100);
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
|
||||
public enum FakePersonFields
|
||||
{
|
||||
GivenName,
|
||||
Surname,
|
||||
Gender,
|
||||
StreetAddress,
|
||||
ZipCode,
|
||||
City,
|
||||
Country,
|
||||
Birthday,
|
||||
TelephoneNumber,
|
||||
NationalID,
|
||||
Longitude,
|
||||
Latitude
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user