diff --git a/CShocker/Devices/Abstract/Api.cs b/CShocker/Devices/Abstract/Api.cs index 22cc552..c26a8ee 100644 --- a/CShocker/Devices/Abstract/Api.cs +++ b/CShocker/Devices/Abstract/Api.cs @@ -42,7 +42,7 @@ public abstract class Api : IDisposable } foreach (Shocker shocker in shockers) { - this.Logger?.Log(LogLevel.Debug, $"Enqueueing {action} {intensity} {duration}"); + this.Logger?.Log(LogLevel.Debug, $"Enqueueing {action} Intensity: {intensity} Duration: {duration}\nShocker:\n{shocker}"); _queue.Enqueue(new(action, shocker, intensity, duration)); } } @@ -64,7 +64,7 @@ public abstract class Api : IDisposable while (_workOnQueue) if (_queue.Count > 0 && _queue.Dequeue() is { } action) { - this.Logger?.Log(LogLevel.Information, $"{action.Item1} {action.Item2} {action.Item3} {action.Item4}"); + this.Logger?.Log(LogLevel.Information, $"Executing: {Enum.GetName(action.Item1)} Intensity: {action.Item3} Duration: {action.Item4}\nShocker:\n{action.Item2.ToString()}"); ControlInternal(action.Item1, action.Item2, action.Item3, action.Item4); Thread.Sleep(action.Item4 + CommandDelay); } diff --git a/CShocker/Devices/Additional/ApiHttpClient.cs b/CShocker/Devices/Additional/ApiHttpClient.cs index 7d04cd7..93645c8 100644 --- a/CShocker/Devices/Additional/ApiHttpClient.cs +++ b/CShocker/Devices/Additional/ApiHttpClient.cs @@ -26,18 +26,19 @@ public static class ApiHttpClient new StringContent(jsonContent, Encoding.UTF8, new MediaTypeHeaderValue("application/json")); foreach ((string, string) customHeader in customHeaders) request.Headers.Add(customHeader.Item1, customHeader.Item2); - logger?.Log(LogLevel.Debug, $"Request: \n" + - $"-URI: {request.RequestUri}\n" + - $"-Headers: \n\t{string.Join("\n\t", request.Headers.Select(h => $"{h.Key} {string.Join(", ", h.Value)}"))}\n" + - $"-Content: {request.Content?.ReadAsStringAsync().Result}"); + logger?.Log(LogLevel.Debug, string.Join("\n\t", + "Request:", + $"\u251c\u2500\u2500 URI: {request.RequestUri}", + $"\u251c\u2500\u2510 Headers: {string.Concat(request.Headers.Select(h => $"\n\t\u2502 {(request.Headers.Last().Key.Equals(h.Key) ? "\u2514" : "\u251c")} {h.Key}: {string.Join(", ", h.Value)}"))}", + $"\u2514\u2500\u2500 Content: {request.Content?.ReadAsStringAsync().Result}")); HttpClient httpClient = new(); HttpResponseMessage response = httpClient.Send(request); - logger?.Log(!response.IsSuccessStatusCode ? LogLevel.Error : LogLevel.Debug, - $"Response: \n" + - $"-URI: {request.RequestUri}\n" + - $"-Headers: \n\t{string.Join("\n\t", response.Headers.Select(h => $"{h.Key} {string.Join(", ", h.Value)}"))}\n" + - $"-Content: {response.Content?.ReadAsStringAsync().Result}"); + logger?.Log(!response.IsSuccessStatusCode ? LogLevel.Error : LogLevel.Debug, string.Join("\n\t", + "Request:", + $"\u251c\u2500\u2500 URI: {request.RequestUri}", + $"\u251c\u2500\u2510 Headers: {string.Concat(response.Headers.Select(h => $"\n\t\u2502 {(response.Headers.Last().Key.Equals(h.Key) ? "\u2514" : "\u251c")} {h.Key}: {string.Join(", ", h.Value)}"))}", + $"\u2514\u2500\u2500 Content: {response.Content?.ReadAsStringAsync().Result}")); httpClient.Dispose(); return response; } diff --git a/CShocker/Shockers/OpenShockShocker.cs b/CShocker/Shockers/OpenShockShocker.cs index 504eb98..8439468 100644 --- a/CShocker/Shockers/OpenShockShocker.cs +++ b/CShocker/Shockers/OpenShockShocker.cs @@ -32,14 +32,15 @@ public class OpenShockShocker : Shocker public override string ToString() { - return $"{string.Join("\n\t", - $"{GetType().Name}", - $"Name: {Name}", - $"ID: {ID}", - $"RF-ID: {RfId}", - $"Model: {Enum.GetName(Model)}", - $"Created On: {CreatedOn}", - $"Paused: {IsPaused}")}" + + const int tabWidth = -12; + return $"\t{string.Join("\n\t", + $"\u251c {"Type",tabWidth}: {GetType().Name}", + $"\u251c {"Name",tabWidth}: {Name}", + $"\u251c {"ID",tabWidth}: {ID}", + $"\u251c {"RF-ID",tabWidth}: {RfId}", + $"\u251c {"Model",tabWidth}: {Enum.GetName(Model)}", + $"\u251c {"Created On",tabWidth}: {CreatedOn}", + $"\u2514 {"Paused",tabWidth}: {IsPaused}")}" + $"\n\r"; } diff --git a/CShocker/Shockers/PiShockShocker.cs b/CShocker/Shockers/PiShockShocker.cs index 3774723..cd10d9a 100644 --- a/CShocker/Shockers/PiShockShocker.cs +++ b/CShocker/Shockers/PiShockShocker.cs @@ -7,6 +7,13 @@ public class PiShockShocker : Shocker { public readonly string Code; + public PiShockShocker(Api api, string code) : base(api) + { + if (api is not PiShockApi) + throw new Exception($"API-Type {api.GetType().FullName} is not usable with Shocker {this.GetType().FullName}"); + Code = code; + } + public override bool Equals(object? obj) { return obj is PiShockShocker pss && Equals(pss); @@ -21,11 +28,13 @@ public class PiShockShocker : Shocker { return Code.GetHashCode(); } - - public PiShockShocker(Api api, string code) : base(api) + + public override string ToString() { - if (api is not PiShockApi) - throw new Exception($"API-Type {api.GetType().FullName} is not usable with Shocker {this.GetType().FullName}"); - Code = code; + const int tabWidth = -5; + return $"{string.Join("\n\t", + $"\u251c {"Type",tabWidth}: {GetType().Name}", + $"\u2514 {"Code",tabWidth}: {Code}")}" + + $"\n\r"; } } \ No newline at end of file