PopulateData now takes tens of thousands of bogus people

This commit is contained in:
Rick Falkvinge
2014-09-30 09:44:14 +02:00
parent 4a6d385fb7
commit f41e1cf713
3 changed files with 119 additions and 14 deletions
+75 -5
View File
@@ -14,21 +14,91 @@
<script type="text/javascript">
$(document).ready(function () {
});
function uploadCompletedCallback() {
$('#DivProcessing').slideDown().fadeIn();
$('#DivProgressProcessing').progressbar({ value: 0, max: 100 });
$.ajax({
type: "POST",
url: "PopulateData.aspx/InitializeProcessing",
data: "{'guid': '<%= this.UploadFile.GuidString %>'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
setTimeout('updateProgressProcessing();', 1000);
}
});
}
function updateProgressProcessing() {
$.ajax({
type: "POST",
url: "/Automation/Json-ByGuid.aspx/GetProgress",
data: "{'guid': '<%= this.UploadFile.GuidString %>'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (msg.d > 99) {
$("#DivProgressProcessing .progressbar-value").animate(
{
width: "100%"
}, { queue: false });
this.document.location = '/';
} else {
// We're not done yet. Keep the progress bar on-screen and keep re-checking.
if (msg.d == 1) {
$('#DivProgressProcessing').progressbar({ value: 1 });
} else {
$("#DivProgressProcessing .progressbar-value").animate(
{
width: msg.d + "%"
}, { queue: false });
}
if (msg.d > 0 && !progressReceived) {
progressReceived = true;
}
setTimeout('updateProgressProcessing();', 1000);
}
},
error: function (msg) {
// Retry on call error, too
setTimeout('updateProgressProcessing();', 1000);
}
});
}
var progressReceived = false;
</script>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<asp:TextBox runat="server" ID="TextData" TextMode="MultiLine" Rows="20" Width="100%" />
<asp:Button ID="ButtonProcess" runat="server" CssClass="buttonAccentColor NoInputFocus" OnClick="ButtonProcess_Click" Text="Process"/>
<div style="clear:both"></div>
<div class="DivEntry">
<div class="entryFields">
<Swarmops5:FileUpload runat="server" ID="UploadFile" Filter="NoFilter" DisplayCount="8" ClientUploadCompleteCallback="uploadCompletedCallback" />
</div>
<div class="entryLabels">
Upload file for processing<br/><br/>
</div>
</div>
<div clear="both"></div>
<div id="Processing">
<div id="DivProgressProcessing"></div>
</div>
</asp:Content>
@@ -1,12 +1,17 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Basic.Enums;
using Swarmops.Logic.Cache;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
using Swarmops.Logic.Swarm;
@@ -29,10 +34,34 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
}
protected void ButtonProcess_Click(object sender, EventArgs e)
[WebMethod(true)]
public static void InitializeProcessing(string guid)
{
// Start an async thread that does all the work, then return
string data = this.TextData.Text;
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);
}
static private 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');
@@ -40,6 +69,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
foreach (string lineRaw in lines)
{
count++;
string line = lineRaw.Trim();
string[] lineParts = line.Split('\t');
@@ -48,6 +78,13 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
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);
@@ -64,13 +101,7 @@ namespace Swarmops.Frontend.Pages.v5.Admin.Hacks
newPerson.AddMembership(1, DateTime.Today.AddDays(random.Next(365)));
}
Response.AppendCookie(new HttpCookie("DashboardMessage", "Data was successfully processed."));
// Redirect to dashboard
Response.Redirect("/", true);
GuidCache.Set(guid + "-Progress", 100);
}
}
@@ -21,6 +21,10 @@ using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
// TODO: There are significant remnants in this file from the old Telerik-based upload code. When Account Automation is complete and the user can select a bank profile
// for an account, uploading payment files as well as bank statements, remove that dead code as its templates won't be needed after that.
// ReSharper disable CheckNamespace
namespace Swarmops.Site.Pages.Ledgers
// ReSharper restore CheckNamespace