From 2a0ace0b065e426f58b3a4dc1382045ee3bce41a Mon Sep 17 00:00:00 2001 From: TadisOn <76095383+TadisOn@users.noreply.github.com> Date: Wed, 29 Nov 2023 11:28:31 +0200 Subject: [PATCH] Added proxy Addded proxy so system could count logged info. --- ClientApp/Forms/GameForm.cs | 3 +- ClientApp/ServerLoggerProxy.cs | 52 ++++++++++++++++++++++++ SharedLibrary/Interfaces/ILoggerProxy.cs | 14 +++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 ClientApp/ServerLoggerProxy.cs create mode 100644 SharedLibrary/Interfaces/ILoggerProxy.cs diff --git a/ClientApp/Forms/GameForm.cs b/ClientApp/Forms/GameForm.cs index 687a758..611e9e6 100644 --- a/ClientApp/Forms/GameForm.cs +++ b/ClientApp/Forms/GameForm.cs @@ -34,7 +34,7 @@ public GameForm(Client client, int gameId, string gameLevel) InitializeComponent(); _client = client; - _logger = new ServerLoggerAdapter(client); + _logger = new ServerLoggerProxy(client); this.HandleCreated += GameForm_HandleCreated; @@ -718,5 +718,6 @@ private void SetGroupButtonBorders(int group) } } } + } } \ No newline at end of file diff --git a/ClientApp/ServerLoggerProxy.cs b/ClientApp/ServerLoggerProxy.cs new file mode 100644 index 0000000..2c3bba6 --- /dev/null +++ b/ClientApp/ServerLoggerProxy.cs @@ -0,0 +1,52 @@ +using SharedLibrary.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClientApp +{ + public class ServerLoggerProxy : ILoggerProxy + { + private readonly ServerLoggerAdapter _serverLogger; + private readonly Dictionary _logCounts; + + public ServerLoggerProxy(Client client) + { + _serverLogger = new ServerLoggerAdapter(client); + _logCounts = new Dictionary + { + {"Info",0 }, + {"Warning",0 }, + {"Error",0 } + }; + } + + public void LogInfo(string message) + { + _logCounts["Info"]++; + _serverLogger.LogInfo(message); + + } + + public void LogWarning(string message) + { + _logCounts["Warning"]++; + _serverLogger.LogWarning(message); + } + + public void LogError(string message) + { + _logCounts["Error"]++; + _serverLogger.LogError(message); + } + + public Dictionary GetLogCounts() + { + return new Dictionary(_logCounts); + } + + + } +} diff --git a/SharedLibrary/Interfaces/ILoggerProxy.cs b/SharedLibrary/Interfaces/ILoggerProxy.cs new file mode 100644 index 0000000..406b7e8 --- /dev/null +++ b/SharedLibrary/Interfaces/ILoggerProxy.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SharedLibrary.Interfaces +{ + public interface ILoggerProxy : ILogger + { + Dictionary GetLogCounts(); + + } +}