Skip to content

Commit

Permalink
Refactor code formatting and adjust minor style issues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ivandrofly committed Jan 3, 2025
1 parent 333e3f9 commit 2d03495
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
3 changes: 1 addition & 2 deletions Client.Console/Invoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,5 @@ public Task DisplayClient()
//await Task.Delay(1000 * 60);
//var turnOnSign = new TurnOnSignal();
//await turnOnSign.Execute(powerLine);

}
}
}
10 changes: 6 additions & 4 deletions TpLink.Api/Helpers/StringUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")}";
}
}
}
}
49 changes: 26 additions & 23 deletions TpLinkDataRate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Worker>();
//services.AddSingleton<IRestClient, RestClient>();
services.AddSingleton<ITpLinkClient>(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<Worker>();
//services.AddSingleton<IRestClient, RestClient>();
services.AddSingleton<ITpLinkClient>(new TpLinkClient(login, password, $"http://{ip}/"));
});
}
}
}
}

0 comments on commit 2d03495

Please sign in to comment.