From 2d03495ee32d700b48bb07b231c7619ffdde119e Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Fri, 3 Jan 2025 20:13:31 +0000 Subject: [PATCH] Refactor code formatting and adjust minor style issues Improved code readability by refactoring formatting in multiple files, standardizing indentation, and removing unnecessary blank lines. The changes also ensure consistent use of private modifiers and corrected newline endings where missing. --- Client.Console/Invoker.cs | 3 +- TpLink.Api/Helpers/StringUtils.cs | 10 ++++--- TpLinkDataRate/Program.cs | 49 ++++++++++++++++--------------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Client.Console/Invoker.cs b/Client.Console/Invoker.cs index 59e258d..17760b7 100644 --- a/Client.Console/Invoker.cs +++ b/Client.Console/Invoker.cs @@ -79,6 +79,5 @@ public Task DisplayClient() //await Task.Delay(1000 * 60); //var turnOnSign = new TurnOnSignal(); //await turnOnSign.Execute(powerLine); - } -} +} \ No newline at end of file diff --git a/TpLink.Api/Helpers/StringUtils.cs b/TpLink.Api/Helpers/StringUtils.cs index 332f500..14e69fe 100644 --- a/TpLink.Api/Helpers/StringUtils.cs +++ b/TpLink.Api/Helpers/StringUtils.cs @@ -12,10 +12,12 @@ public static string HashPassword(string password) // A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value; for example, "7F-2C-4A-00" return BitConverter.ToString(hashBuffer).Replace("-", string.Empty).ToLowerInvariant(); } - + //System.Net.WebUtility.HtmlEncode() //System.Uri.EscapeDataString() - public static string GetAuthorization(string login, string password) => $"{Uri.EscapeDataString($"Basic {login}:{HashPassword(password)}")}"; - + public static string GetAuthorization(string login, string password) + { + return $"{Uri.EscapeDataString($"Basic {login}:{HashPassword(password)}")}"; + } } -} +} \ No newline at end of file diff --git a/TpLinkDataRate/Program.cs b/TpLinkDataRate/Program.cs index fe7196a..ef68778 100644 --- a/TpLinkDataRate/Program.cs +++ b/TpLinkDataRate/Program.cs @@ -15,30 +15,33 @@ public static void Main(string[] args) Console.ReadLine(); } - public static IHostBuilder CreateHostBuilder(string[] args) + private static IHostBuilder CreateHostBuilder(string[] args) { return Host.CreateDefaultBuilder(args) - .ConfigureServices(/*async*/ (hostContext, services) => - { - string login = Environment.GetEnvironmentVariable("tplink_powerline_login", EnvironmentVariableTarget.User); - string password = Environment.GetEnvironmentVariable("tplink_powerline_pwd", EnvironmentVariableTarget.User); - - // note: ensure the vpn is turned off / net - // can also be checked here: Control Panel\Network and Internet\Network Connections - - // find ip of the powerline | if you have vpn or several adapter, make sure this is sending dicovery packet to - // the network where powerline is connected to - string ip = TpLinkClient.DiscoveryAsync().GetAwaiter().GetResult(); // NOTE: using async here may break the DI pattern and throw CreateHostBuilder(args).Build().Run(); - - // won't work (thread problem) - //string ip = await TpLinkClient.DiscoveryAsync(); - - Console.WriteLine($"found ip: {ip}"); - - services.AddHostedService(); - //services.AddSingleton(); - services.AddSingleton(new TpLinkClient(login, password, $"http://{ip}/")); - }); + .ConfigureServices( /*async*/ (hostContext, services) => + { + string login = + Environment.GetEnvironmentVariable("tplink_powerline_login", EnvironmentVariableTarget.User); + string password = + Environment.GetEnvironmentVariable("tplink_powerline_pwd", EnvironmentVariableTarget.User); + + // note: ensure the vpn is turned off / net + // can also be checked here: Control Panel\Network and Internet\Network Connections + + // find ip of the powerline | if you have vpn or several adapter, make sure this is sending dicovery packet to + // the network where powerline is connected to + var ip = TpLinkClient.DiscoveryAsync().GetAwaiter() + .GetResult(); // NOTE: using async here may break the DI pattern and throw CreateHostBuilder(args).Build().Run(); + + // won't work (thread problem) + //string ip = await TpLinkClient.DiscoveryAsync(); + + Console.WriteLine($"found ip: {ip}"); + + services.AddHostedService(); + //services.AddSingleton(); + services.AddSingleton(new TpLinkClient(login, password, $"http://{ip}/")); + }); } } -} +} \ No newline at end of file