diff --git a/Backend/Program.cs b/Backend/Program.cs index 15b8bce1..ba7e8220 100644 --- a/Backend/Program.cs +++ b/Backend/Program.cs @@ -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; diff --git a/Logic/Cache/GuidCache.cs b/Logic/Cache/GuidCache.cs new file mode 100644 index 00000000..1f67040b --- /dev/null +++ b/Logic/Cache/GuidCache.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Collections; + +namespace Swarmops.Logic.Cache +{ + /// + /// 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? + /// + public class GuidCache + { + static GuidCache() + { + _cache = new Dictionary(); + _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 _cache; + private static DateTime _nextGarbageCollect; + + private class CachedObject + { + public DateTime StoredDateTime { get; set; } + public object Object; + } + } + + +} diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index e9222fbc..fa2fc0b4 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -84,6 +84,7 @@ True Logic.Test.resx + diff --git a/Site5/App_Code/PageV5Base.cs b/Site5/App_Code/PageV5Base.cs index 4e6e4801..c40b27c9 100644 --- a/Site5/App_Code/PageV5Base.cs +++ b/Site5/App_Code/PageV5Base.cs @@ -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"]; } + } } diff --git a/Site5/Automation/Json-ByGuid.aspx b/Site5/Automation/Json-ByGuid.aspx new file mode 100644 index 00000000..8b8a0985 --- /dev/null +++ b/Site5/Automation/Json-ByGuid.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ByGuid.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_ByGuid" %> diff --git a/Site5/Automation/Json-ByGuid.aspx.cs b/Site5/Automation/Json-ByGuid.aspx.cs new file mode 100644 index 00000000..40ec87ba --- /dev/null +++ b/Site5/Automation/Json-ByGuid.aspx.cs @@ -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 + } + } +} \ No newline at end of file diff --git a/Site5/Controls/v5/Base/FileUpload.ascx.cs b/Site5/Controls/v5/Base/FileUpload.ascx.cs index ff502f28..1d88c103 100644 --- a/Site5/Controls/v5/Base/FileUpload.ascx.cs +++ b/Site5/Controls/v5/Base/FileUpload.ascx.cs @@ -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() diff --git a/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx b/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx index eacd9c0a..5a557c8d 100644 --- a/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx +++ b/Site5/Pages/v5/Ledgers/UploadBankFiles.aspx @@ -90,6 +90,19 @@ div.BankUploadInstructionsImage - - Step 1/4: Upload Bank File + + + + Upload Bank File - - + + Dropdown + Instructions + Bank account + File type + Instructions Upload bank file