Committing some work before doing other things. Builds but doesn't work

This commit is contained in:
Rick Falkvinge
2014-08-16 09:58:07 +00:00
parent 19d1c38e48
commit 31c8b39260
8 changed files with 145 additions and 4 deletions
+6
View File
@@ -167,6 +167,12 @@ namespace Swarmops.Backend
OutboundComm.CreateNotification(null, NotificationResource.System_Startup);
// Check for existence of installation ID. If not, create one. Warning: has privacy implications when communicated.
if (Persistence.Key["SwarmopsInstallationId"] == string.Empty)
{
Persistence.Key["SwarmopsInstallationId"] = new Guid().ToString();
}
DateTime cycleStartTime = DateTime.Now;
+76
View File
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Swarmops.Logic.Cache
{
/// <summary>
/// This class stores arbitrary objects, keyed by a GUID, for 24 hours. Primarily intended for progress bars and similar data that
/// needs to be stored in a separate, global namespace for accessibility reasons from JavaScript. DO NOT STORE SENSITIVE STUFF here
/// as it's generally accessible, at least not without accompanying access control.
///
/// TODO: Share this data across a web farm some bloody how. Put it in database? Too slow for progress bars... Memcached perhaps?
/// </summary>
public class GuidCache
{
static GuidCache()
{
_cache = new Dictionary<string, CachedObject>();
_nextGarbageCollect = DateTime.MinValue;
}
static public void Set(string guidString, object objectToCache)
{
ConditionalGarbageCollect();
_cache[guidString] = new CachedObject() {StoredDateTime = DateTime.UtcNow, Object = objectToCache};
}
static public object Get(string guidString)
{
if (!_cache.ContainsKey(guidString))
{
return null;
}
return _cache[guidString].Object;
}
static private void ConditionalGarbageCollect()
{
lock (_cache) // thread safety
{
if (_nextGarbageCollect > DateTime.UtcNow)
{
return; // not time yet
}
// Do a garbage collect and set the next one for, say, an hour out
_nextGarbageCollect = DateTime.UtcNow.AddHours(1); // do this first for thread reasons
}
DateTime expired = DateTime.UtcNow.AddHours(-24);
foreach (string key in _cache.Keys.ToList()) // ToList() is crucial - it takes a copy of the list, which may be modified in-loop
{
if (_cache[key].StoredDateTime < expired)
{
_cache.Remove(key);
}
}
}
static private Dictionary<string, CachedObject> _cache;
private static DateTime _nextGarbageCollect;
private class CachedObject
{
public DateTime StoredDateTime { get; set; }
public object Object;
}
}
}
+1
View File
@@ -84,6 +84,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>Logic.Test.resx</DependentUpon>
</Compile>
<Compile Include="Cache\GuidCache.cs" />
<Compile Include="Communications\ICommsRenderer.cs" />
<Compile Include="Communications\ICommsResolver.cs" />
<Compile Include="Communications\ICommsTransmitter.cs" />
+7
View File
@@ -4,7 +4,9 @@ using System.Globalization;
using System.Threading;
using System.Web;
using System.Web.UI;
using Swarmops.Database;
using Swarmops.Logic.Security;
using Swarmops.Logic.Support;
using Swarmops.Logic.Swarm;
using Swarmops.Basic.Enums;
using Swarmops.Logic.Structure;
@@ -195,6 +197,11 @@ public class PageV5Base : System.Web.UI.Page
return result;
}
protected string InstallationId
{
get { return Persistence.Key["SwarmopsInstallationId"]; }
}
}
+1
View File
@@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ByGuid.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_ByGuid" %>
+25
View File
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Logic.Cache;
namespace Swarmops.Frontend.Automation
{
public partial class Json_ByGuid : DataV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
int GetProgress(string guid)
{
return (int) GuidCache.Get(guid + "-Progress"); // suffix because guid may refer to other data too
}
}
}
@@ -29,6 +29,10 @@ namespace Swarmops.Controls.Base
{
this.ClientUploadCompleteCallback = string.Empty;
}
if (this.ClientUploadStartedCallback == null)
{
this.ClientUploadStartedCallback = string.Empty;
}
}
else
{
@@ -41,6 +45,7 @@ namespace Swarmops.Controls.Base
public int DisplayCount { get; set; }
public bool HideTrigger { get; set; }
public string ClientUploadCompleteCallback { get; set; }
public string ClientUploadStartedCallback { get; set; }
public void Reset()
+24 -4
View File
@@ -90,6 +90,19 @@ div.BankUploadInstructionsImage
<script type="text/javascript">
$(document).ready(function() {
$('#<%=DropAccounts.ClientID %>').change(function() {
var selectedAccountId = $('#<%=DropAccounts.ClientID %>').val();
if (selectedAccountId != 0) {
$('#<%=this.UploadFile.ClientID %>_ButtonUploadVisible').fadeIn();
} else {
$('#<%=this.UploadFile.ClientID %>_ButtonUploadVisible').fadeOut();
}
});
});
function uploadCompletedCallback() {
$('#DivStepUpload').slideUp().fadeOut();
$('#DivStepProcessing').fadeIn();
@@ -162,6 +175,7 @@ div.BankUploadInstructionsImage
});
}
var progressReceived = false;
var currentYear = <%=DateTime.Today.Year %>;
@@ -169,16 +183,22 @@ div.BankUploadInstructionsImage
</script>
<div id="DivStepUpload">
<h2>Step 1/4: Upload Bank File</h2>
<div id="DivUploadResults">
</div>
<div id="DivUploadBankFile">
<h2>Upload Bank File</h2>
<div id="DivPrepData">
<div class="entryFields">
<asp:DropDownList runat="server" ID="DropAccounts"/>&nbsp;
<Swarmops5:FileUpload runat="server" ID="UploadFile" Filter="NoFilter" DisplayCount="8" HideTrigger="true" ClientUploadCompleteCallback="uploadCompletedCallback" /></div>
<asp:DropDownList runat="server" ID="DropAccounts"/>
Dropdown<br/>
Instructions<br/>
<Swarmops5:FileUpload runat="server" ID="UploadFile" Filter="NoFilter" DisplayCount="8" HideTrigger="true" ClientUploadStartedCallback="uploadStartedCallback" ClientUploadCompleteCallback="uploadCompletedCallback" /></div>
<div class="entryLabels">
Bank account<br/>
File type<br/>
Instructions<br/>
Upload bank file
</div>
</div>