From bb5590aeb9ed090251c38382f01b487bbf53cacb Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 8 Oct 2020 08:47:52 -0400 Subject: [PATCH] ensure UI can get the current log level of the service so the user can be shown what it's at currently add/refine debug output --- DesktopEdge/MainWindow.xaml.cs | 28 +++++++++++++-------- DesktopEdge/ServiceClient/DataStructures.cs | 24 +++++++++++++++--- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/DesktopEdge/MainWindow.xaml.cs b/DesktopEdge/MainWindow.xaml.cs index a69a9ae5..e92300d0 100644 --- a/DesktopEdge/MainWindow.xaml.cs +++ b/DesktopEdge/MainWindow.xaml.cs @@ -4,21 +4,11 @@ using System.Windows; using System.Windows.Input; using System.IO; using ZitiDesktopEdge.Models; -using System.IO.Compression; - using ZitiDesktopEdge.ServiceClient; using System.ServiceProcess; using System.Linq; -using System.Runtime.Remoting.Messaging; using System.Diagnostics; -using System.Security.Principal; -using System.Net; using System.Windows.Controls; -using System.Threading.Tasks; -using System.Threading; -using System.Text; -using System.Runtime.InteropServices; -using System.Windows.Interop; namespace ZitiDesktopEdge { @@ -250,6 +240,7 @@ namespace ZitiDesktopEdge { private void ServiceClient_OnTunnelStatusEvent(object sender, TunnelStatusEvent e) { if (e == null) return; //just skip it for now... Debug.WriteLine($"==== TunnelStatusEvent: "); + e.Status.Dump(Console.Out); this.Dispatcher.Invoke(() => { if(e.ApiVersion != Client.EXPECTED_API_VERSION) { SetCantDisplay("Version mismatch!", "The version of the Service is not compatible"); @@ -543,5 +534,22 @@ namespace ZitiDesktopEdge { private void Label_MouseDoubleClick(object sender, MouseButtonEventArgs e) { Placement(); } + + private void Button_Click(object sender, RoutedEventArgs e) + { + serviceClient.SetLogLevel(NextLevel()); + } + + int cur = 0; + LogLevelEnum[] levels = new LogLevelEnum[] { LogLevelEnum.FATAL, LogLevelEnum.ERROR, LogLevelEnum.WARN, LogLevelEnum.INFO, LogLevelEnum.DEBUG, LogLevelEnum.TRACE, LogLevelEnum.VERBOSE }; + public LogLevelEnum NextLevel() + { + cur++; + if (cur > 6) + { + cur = 0; + } + return levels[cur]; + } } } diff --git a/DesktopEdge/ServiceClient/DataStructures.cs b/DesktopEdge/ServiceClient/DataStructures.cs index b49e47f8..a3329785 100644 --- a/DesktopEdge/ServiceClient/DataStructures.cs +++ b/DesktopEdge/ServiceClient/DataStructures.cs @@ -180,15 +180,19 @@ namespace ZitiDesktopEdge.ServiceClient public IpInfo IpInfo { get; set; } + public string LogLevel { get; set; } + public void Dump(System.IO.TextWriter writer) { writer.WriteLine($"Tunnel Active: {Active}"); + writer.WriteLine($" LogLevel : {LogLevel}"); + writer.WriteLine($" EvaluatedLogLevel: {EvaluateLogLevel()}"); foreach (Identity id in Identities) { writer.WriteLine($" FingerPrint: {id.FingerPrint}"); - writer.WriteLine($" Name: {id.Name}"); - writer.WriteLine($" Active: {id.Active}"); - writer.WriteLine($" Status: {id.Status}"); + writer.WriteLine($" Name : {id.Name}"); + writer.WriteLine($" Active : {id.Active}"); + writer.WriteLine($" Status : {id.Status}"); writer.WriteLine($" Services:"); foreach (Service s in id.Services) { @@ -197,6 +201,20 @@ namespace ZitiDesktopEdge.ServiceClient writer.WriteLine("============================================="); } } + + public LogLevelEnum EvaluateLogLevel() + { + try + { + LogLevelEnum l = (LogLevelEnum) Enum.Parse(typeof(LogLevelEnum), LogLevel.ToUpper()); + return l; + } + catch + { + System.Diagnostics.Debug.WriteLine("Could not parse response LogLevel from sevice - guessing INFO? " + LogLevel); + return LogLevelEnum.INFO; + } + } } public class ServiceException : System.Exception