From 39e4c6f56cde09a313173d6eb88ed9f4ea3c35b6 Mon Sep 17 00:00:00 2001 From: Falkvinge Date: Fri, 17 Mar 2017 08:24:41 +0100 Subject: [PATCH] Some more work on displaying malfunctions --- FrontSocket/Frontend-Socket.csproj | 1 + FrontSocket/FrontendLoop.cs | 15 +- FrontSocket/FrontendMalfunctions.cs | 15 ++ Logic/Logic.csproj | 10 ++ .../Logic.Support.ErrorMessages.Designer.cs | 153 ++++++++++++++++++ .../Logic.Support.ErrorMessages.resx | 150 +++++++++++++++++ Logic/Resources/SourceResourceFiles.txt | 1 + Logic/Support/ErrorMessages.cs | 29 ++++ 8 files changed, 372 insertions(+), 2 deletions(-) create mode 100644 FrontSocket/FrontendMalfunctions.cs create mode 100644 Logic/Resources/Logic.Support.ErrorMessages.Designer.cs create mode 100644 Logic/Resources/Logic.Support.ErrorMessages.resx create mode 100644 Logic/Support/ErrorMessages.cs diff --git a/FrontSocket/Frontend-Socket.csproj b/FrontSocket/Frontend-Socket.csproj index a89d54fa..3f30becb 100644 --- a/FrontSocket/Frontend-Socket.csproj +++ b/FrontSocket/Frontend-Socket.csproj @@ -60,6 +60,7 @@ + diff --git a/FrontSocket/FrontendLoop.cs b/FrontSocket/FrontendLoop.cs index bd55c6a5..d46075cb 100644 --- a/FrontSocket/FrontendLoop.cs +++ b/FrontSocket/FrontendLoop.cs @@ -203,8 +203,9 @@ namespace Swarmops.Frontend.Socket private static int _sandboxDummy1 = 500; private static int _sandboxDummy2 = 50000; + /* private static int _malfunctionTestCounter = 0; - private static string[] malfunctionStrings = {"One", "Two", "Three", "Four"}; + private static string[] malfunctionStrings = {"One", "Two", "Three", "Four"};*/ private static void OnEveryTenSeconds() { @@ -222,6 +223,7 @@ namespace Swarmops.Frontend.Socket _socketServer.WebSocketServices.Broadcast(data1.ToString()); + /* JArray malfunctionsArray = new JArray(); for (int loop = 0; loop < _malfunctionTestCounter; loop++) { @@ -244,7 +246,7 @@ namespace Swarmops.Frontend.Socket JObject data2 = new JObject(); data2["MessageType"] = "Malfunctions"; data2["MalfunctionsList"] = malfunctionsArray; - _socketServer.WebSocketServices.Broadcast(data2.ToString()); + _socketServer.WebSocketServices.Broadcast(data2.ToString());*/ } } @@ -298,11 +300,15 @@ namespace Swarmops.Frontend.Socket public static void OnBackendClose(object sender, CloseEventArgs args) { Console.WriteLine(" - Backend socket closed: " + args.Code + " " + args.Reason); + + // TODO: Try reconnecting } public static void OnBackendError(object sender, ErrorEventArgs args) { Console.WriteLine(" - Backend socket error: " + args.Message); + + // TODO: Try reconnecting } @@ -319,6 +325,11 @@ namespace Swarmops.Frontend.Socket } + public static void BroadcastMalfunctions() + { + + } + // --------------------------------- LEGACY CODE BELOW THIS MARK ------------------------------- diff --git a/FrontSocket/FrontendMalfunctions.cs b/FrontSocket/FrontendMalfunctions.cs new file mode 100644 index 00000000..89bf0a14 --- /dev/null +++ b/FrontSocket/FrontendMalfunctions.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Swarmops.Frontend.Socket +{ + public enum FrontendMalfunctions + { + Unknown = 0, + BackendConnectionFault, + BackendHeartbeatLost + } +} diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index 5ee14ce2..ff915372 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -156,6 +156,11 @@ True Logic.Structure.Geography.resx + + True + True + Logic.Support.ErrorMessages.resx + True True @@ -191,6 +196,7 @@ + @@ -629,6 +635,10 @@ + + ResXFileCodeGenerator + Logic.Support.ErrorMessages.Designer.cs + diff --git a/Logic/Resources/Logic.Support.ErrorMessages.Designer.cs b/Logic/Resources/Logic.Support.ErrorMessages.Designer.cs new file mode 100644 index 00000000..7fa591ae --- /dev/null +++ b/Logic/Resources/Logic.Support.ErrorMessages.Designer.cs @@ -0,0 +1,153 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Swarmops.Logic.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // 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 your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Logic_Support_ErrorMessages { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Logic_Support_ErrorMessages() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Swarmops.Logic.Resources.Logic.Support.ErrorMessages", typeof(Logic_Support_ErrorMessages).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to The server has lost the connection to the bitcoin blockchain. Bitcoin transactions won't be detected in real time.. + /// + internal static string Backend_BlockchainSocketLost_Text { + get { + return ResourceManager.GetString("Backend_BlockchainSocketLost_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Blockchain Connection Lost. + /// + internal static string Backend_BlockchainSocketLost_Title { + get { + return ResourceManager.GetString("Backend_BlockchainSocketLost_Title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The web browser is unable to hear the server's heartbeat.. + /// + internal static string Client_ServerHeartbeatLost_Text { + get { + return ResourceManager.GetString("Client_ServerHeartbeatLost_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Heartbeat Failure Level 1. + /// + internal static string Client_ServerHeartbeatLost_Title { + get { + return ResourceManager.GetString("Client_ServerHeartbeatLost_Title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unable to connect to the server for real-time updates.. + /// + internal static string Client_SocketConnectionFault_Text { + get { + return ResourceManager.GetString("Client_SocketConnectionFault_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to WebSocket Failure. + /// + internal static string Client_SocketConnectionFault_Title { + get { + return ResourceManager.GetString("Client_SocketConnectionFault_Title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The server is unable to connect to the backend process. Real-time updates will be largely unavailable.. + /// + internal static string Frontend_BackendConnectionFault_Text { + get { + return ResourceManager.GetString("Frontend_BackendConnectionFault_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Backend Connection Failure. + /// + internal static string Frontend_BackendConnectionFault_Title { + get { + return ResourceManager.GetString("Frontend_BackendConnectionFault_Title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The server cannot hear the heartbeat from the backend process.. + /// + internal static string Frontend_BackendHeartbeatLost_Text { + get { + return ResourceManager.GetString("Frontend_BackendHeartbeatLost_Text", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Heartbeat Failure Level 2. + /// + internal static string Frontend_BackendHeartbeatLost_Title { + get { + return ResourceManager.GetString("Frontend_BackendHeartbeatLost_Title", resourceCulture); + } + } + } +} diff --git a/Logic/Resources/Logic.Support.ErrorMessages.resx b/Logic/Resources/Logic.Support.ErrorMessages.resx new file mode 100644 index 00000000..e6131d64 --- /dev/null +++ b/Logic/Resources/Logic.Support.ErrorMessages.resx @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The server has lost the connection to the bitcoin blockchain. Bitcoin transactions won't be detected in real time. + + + Blockchain Connection Lost + + + The web browser is unable to hear the server's heartbeat. + + + Heartbeat Failure Level 1 + + + Unable to connect to the server for real-time updates. + + + WebSocket Failure + + + The server is unable to connect to the backend process. Real-time updates will be largely unavailable. + + + Backend Connection Failure + + + The server cannot hear the heartbeat from the backend process. + + + Heartbeat Failure Level 2 + + \ No newline at end of file diff --git a/Logic/Resources/SourceResourceFiles.txt b/Logic/Resources/SourceResourceFiles.txt index 123a1d43..93931b3a 100644 --- a/Logic/Resources/SourceResourceFiles.txt +++ b/Logic/Resources/SourceResourceFiles.txt @@ -9,3 +9,4 @@ Logic.Structure.Geography.resx Logic.Swarm.DashboardTodos.resx Logic.Swarm.ParticipantTitle.resx Logic.Swarm.Position.resx +Logic.Support.ErrorMessages.resx \ No newline at end of file diff --git a/Logic/Support/ErrorMessages.cs b/Logic/Support/ErrorMessages.cs new file mode 100644 index 00000000..57f27cb5 --- /dev/null +++ b/Logic/Support/ErrorMessages.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Resources; +using System.Text; +using System.Threading.Tasks; +using Swarmops.Logic.Resources; + +namespace Swarmops.Logic.Support +{ + public class ErrorMessages + { + public static string Localize(string errorMessage, string culture = null) + { + if (String.IsNullOrEmpty(culture)) + { + return @"" + Logic_Support_ErrorMessages.ResourceManager.GetString(errorMessage + "_Title") + + @": " + + Logic_Support_ErrorMessages.ResourceManager.GetString(errorMessage + "_Text"); + } + else + { + return @"" + Logic_Support_ErrorMessages.ResourceManager.GetString(errorMessage + "_Title", CultureInfo.CreateSpecificCulture(culture)) + + @": " + + Logic_Support_ErrorMessages.ResourceManager.GetString(errorMessage + "_Text", CultureInfo.CreateSpecificCulture(culture)); + } + } +}