diff --git a/Backend/BackendLoop.cs b/Backend/BackendLoop.cs index f53aae97..31c0ad07 100644 --- a/Backend/BackendLoop.cs +++ b/Backend/BackendLoop.cs @@ -17,6 +17,7 @@ using Swarmops.Logic.Communications.Resolution; using Swarmops.Logic.Financial; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; +using Swarmops.Logic.Support.SocketMessages; using Swarmops.Utility; using Swarmops.Utility.BotCode; using Swarmops.Utility.Communications; diff --git a/Backend/SocketServices/BackendServices.cs b/Backend/SocketServices/BackendServices.cs index ca141758..5125ff3a 100644 --- a/Backend/SocketServices/BackendServices.cs +++ b/Backend/SocketServices/BackendServices.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json.Linq; using Swarmops.Logic; using Swarmops.Logic.Security; using Swarmops.Logic.Support; +using Swarmops.Logic.Support.SocketMessages; using Swarmops.Utility.BotCode; using WebSocketSharp; using WebSocketSharp.Server; diff --git a/FrontSocket/FrontendLoop.cs b/FrontSocket/FrontendLoop.cs index 39b8267a..31840f3c 100644 --- a/FrontSocket/FrontendLoop.cs +++ b/FrontSocket/FrontendLoop.cs @@ -18,6 +18,7 @@ using Swarmops.Logic.Security; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; using Swarmops.Logic.Financial; +using Swarmops.Logic.Support.SocketMessages; using WebSocketSharp; using WebSocketSharp.Server; using ErrorEventArgs = WebSocketSharp.ErrorEventArgs; diff --git a/FrontSocket/FrontendServices.cs b/FrontSocket/FrontendServices.cs index 2e2539fe..1542701d 100644 --- a/FrontSocket/FrontendServices.cs +++ b/FrontSocket/FrontendServices.cs @@ -15,6 +15,7 @@ using Swarmops.Logic.Security; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; using Swarmops.Logic.Support.BackendServices; +using Swarmops.Logic.Support.SocketMessages; using Swarmops.Logic.Swarm; using WebSocketSharp; using WebSocketSharp.Server; @@ -51,10 +52,6 @@ namespace Swarmops.Frontend.Socket case "Metapackage": ProcessMetapackage((string) json["XmlData"]); break; - case "BroadcastProgress": - Sessions.Broadcast("{\"messageType\":\"ProgressUpdate\",\"Guid\":\"" + json["Guid"] + - "\",\"Progress\":\"" + json["Progress"] + "\"}"); - break; case "Ping": // TODO: Request heartbeat from backend // Sessions.Broadcast("{\"messageType\":\"Heartbeat\"}"); @@ -110,13 +107,17 @@ namespace Swarmops.Frontend.Socket switch (message.MessageType) { - case "...": - // some future to-be-defined processing + case "BroadcastProgress": + JObject progressBroadcast = new JObject(); + progressBroadcast["messageType"] = "ProgressUpdate"; + progressBroadcast["Guid"] = message.Guid.Replace("-", "_"); // enables JS tokens from Guid + progressBroadcast["Progress"] = message.Progress; + + Sessions.Broadcast(progressBroadcast.ToString()); break; default: // we're not handling here, send to backend - Console.WriteLine(" - sending " + message.MessageType + " upstream"); FrontendLoop.SendMessageUpstream(message); break; } diff --git a/Logic/Financial/FinancialTransaction.cs b/Logic/Financial/FinancialTransaction.cs index 7ff1bf60..9e275ed7 100644 --- a/Logic/Financial/FinancialTransaction.cs +++ b/Logic/Financial/FinancialTransaction.cs @@ -6,6 +6,7 @@ using Swarmops.Common.Interfaces; using Swarmops.Database; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; +using Swarmops.Logic.Support.SocketMessages; using Swarmops.Logic.Swarm; namespace Swarmops.Logic.Financial diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index 60e03ed5..223b325a 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -223,7 +223,7 @@ - + diff --git a/Logic/Support/ProgressBarBackend.cs b/Logic/Support/ProgressBarBackend.cs index 49a9af9b..39d5468b 100644 --- a/Logic/Support/ProgressBarBackend.cs +++ b/Logic/Support/ProgressBarBackend.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using NUnit.Framework.Constraints; using Swarmops.Logic.Cache; +using Swarmops.Logic.Support.SocketMessages; namespace Swarmops.Logic.Support { @@ -18,7 +19,13 @@ namespace Swarmops.Logic.Support public void Set (int progress) { GuidCache.Set(this.Guid + "-Progress", progress); - + SocketMessage message = new SocketMessage + { + MessageType = "BroadcastProgress", + Guid = this.Guid, + Progress = progress + }; + message.SendUpstream(); } public string Guid { get; private set; } diff --git a/Logic/SocketMessage.cs b/Logic/Support/SocketMessages/SocketMessageBase.cs similarity index 95% rename from Logic/SocketMessage.cs rename to Logic/Support/SocketMessages/SocketMessageBase.cs index 3903130a..5d2192f1 100644 --- a/Logic/SocketMessage.cs +++ b/Logic/Support/SocketMessages/SocketMessageBase.cs @@ -1,17 +1,12 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; -using System.Threading.Tasks; -using Swarmops.Logic.Support; using System.Xml.Serialization; using Newtonsoft.Json.Linq; using Swarmops.Logic.Security; using WebSocketSharp; - -namespace Swarmops.Logic +namespace Swarmops.Logic.Support.SocketMessages { [Serializable] public class SocketMessage : SocketMessageBase @@ -94,6 +89,8 @@ namespace Swarmops.Logic public int FinancialAccountId { get; set; } public int GeographyId { get; set; } public int PersonId { get; set; } + public string Guid { get; set; } + public int Progress { get; set; } public string XmlData { get; set; } } diff --git a/Site/Controls/v5/Base/ProgressBar.ascx b/Site/Controls/v5/Base/ProgressBar.ascx index 8301240d..3ebbd361 100644 --- a/Site/Controls/v5/Base/ProgressBar.ascx +++ b/Site/Controls/v5/Base/ProgressBar.ascx @@ -35,10 +35,14 @@ if (newProgress > <%=this.ClientID%>_lastProgress) { - $("#Div_<%=this.ClientID %>_ProgressBar .progressbar-value").animate( + if (newProgress < 100) { + // The 100% complete case is dealt with later + + $("#Div_<%=this.ClientID %>_ProgressBar .progressbar-value").animate( { width: newProgress + "%" }, { queue: false }); + } if (<%=this.ClientID%>_lastProgress < 50 && newProgress >= 50) { // check for halfway callback @@ -52,11 +56,10 @@ if (<%=this.ClientID%>_lastProgress < 100 && newProgress >= 100) { - $("#Div_<%=this.ClientID %>_ProgressBar .progressbar-value").animate( - { - width: "100%" - }, { queue: false }); - + $("#Div_<%=this.ClientID %>_ProgressBar .progressbar-value").animate( + { + width: "100%" + }, { queue: false }); // check for completion callback