Skip to content

Commit 8ffc5d9

Browse files
refactor dup code into helper
1 parent 31641ae commit 8ffc5d9

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/GregClient/GregClient.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public IAuthProvider AuthProvider
1818
get { return _authProvider; }
1919
}
2020

21-
public GregClient(IAuthProvider provider, string packageManagerUrl)
21+
private static void SetTLSHelper()
2222
{
2323
// https://stackoverflow.com/questions/2819934/detect-windows-version-in-net
2424
// if the current OS is windows 7 or lower
@@ -28,6 +28,17 @@ public GregClient(IAuthProvider provider, string packageManagerUrl)
2828
{
2929
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
3030
}
31+
}
32+
33+
/// <summary>
34+
/// Initializes a new instance of the <see cref="GregClient"/> class with the specified authentication provider,
35+
/// and package manager URL.
36+
/// </summary>
37+
/// <param name="provider">The authentication provider used for managing authentication tokens.</param>
38+
/// <param name="packageManagerUrl">The base URL of the package manager service.</param>
39+
public GregClient(IAuthProvider provider, string packageManagerUrl)
40+
{
41+
SetTLSHelper();
3142
_authProvider = provider;
3243
_client = new RestClient(packageManagerUrl);
3344
}
@@ -41,14 +52,7 @@ public GregClient(IAuthProvider provider, string packageManagerUrl)
4152
/// <param name="httpClient">An optional HTTP client to use for making requests. If null, a default client is created.</param>
4253
public GregClient(IAuthProvider provider, string packageManagerUrl, HttpClient httpClient)
4354
{
44-
// https://stackoverflow.com/questions/2819934/detect-windows-version-in-net
45-
// if the current OS is windows 7 or lower
46-
// set TLS to 1.2.
47-
// else do nothing and let the OS decide the version of TLS to support. (.net 4.7 required)
48-
if (System.Environment.OSVersion.Version.Major <= 6 && System.Environment.OSVersion.Version.Minor <= 1)
49-
{
50-
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
51-
}
55+
SetTLSHelper();
5256
_authProvider = provider;
5357

5458
var baseUrl = new Uri(packageManagerUrl);

0 commit comments

Comments
 (0)