Skip to content

Commit a19eef0

Browse files
Dor-blMartyIX
andauthored
refactor: reintroduce the .NET Framework 4.8 target framework (#740)
* refactor: reintroduce the .NET Framework 4.8 target framework into the project * Update if condition so .NET 6+ would be the primary platform Co-authored-by: MartyIX <[email protected]> * chore: Use if condition for all .NET versions not just 6.0 * chore: Use latest LangVersion on Appium.Net.cspoj * chore: update if statements to ignore NET48 and include more .NET versions * Apply suggestions from code review Co-authored-by: MartyIX <[email protected]> * Update method name Co-authored-by: MartyIX <[email protected]> * fix: update method name where we call it * chore: add ConfigureAwait(false) for NET48 --------- Co-authored-by: MartyIX <[email protected]>
1 parent bc23280 commit a19eef0

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

src/Appium.Net/Appium.Net.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net6.0</TargetFrameworks>
3+
<TargetFrameworks>net48;net6.0</TargetFrameworks>
44
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
55
<RootNamespace>OpenQA.Selenium</RootNamespace>
66
<Company>Appium Commiters</Company>
@@ -27,7 +27,7 @@
2727
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2828
</PropertyGroup>
2929
<PropertyGroup>
30-
<LangVersion>8.0</LangVersion>
30+
<LangVersion>latest</LangVersion>
3131
</PropertyGroup>
3232
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
3333
<NoWarn>1701;1702;1591</NoWarn>

src/Appium.Net/Appium/Service/AppiumLocalService.cs

+32-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
using System.IO;
2121
using System.Linq;
2222
using System.Net;
23+
#if NET
2324
using System.Net.Http;
25+
#endif
2426
using System.Runtime.CompilerServices;
2527
using System.Threading.Tasks;
2628

@@ -37,7 +39,9 @@ public class AppiumLocalService : ICommandServer
3739
private readonly int Port;
3840
private readonly TimeSpan InitializationTimeout;
3941
private readonly IDictionary<string, string> EnvironmentForProcess;
42+
#if !NET48
4043
private readonly HttpClient SharedHttpClient;
44+
#endif
4145
private Process Service;
4246
private List<string> ArgsList;
4347

@@ -61,9 +65,12 @@ internal AppiumLocalService(
6165
Port = port;
6266
InitializationTimeout = initializationTimeout;
6367
EnvironmentForProcess = environmentForProcess;
68+
#if !NET48
6469
SharedHttpClient = CreateHttpClientInstance;
70+
#endif
6571
}
6672

73+
#if !NET48
6774
private HttpClient CreateHttpClientInstance
6875
{
6976
get
@@ -75,7 +82,7 @@ private HttpClient CreateHttpClientInstance
7582
return new HttpClient(handler);
7683
}
7784
}
78-
85+
#endif
7986
/// <summary>
8087
/// The base URL for the managed appium server.
8188
/// </summary>
@@ -168,8 +175,9 @@ private void DestroyProcess()
168175
finally
169176
{
170177
Service?.Close();
171-
178+
#if !NET48
172179
SharedHttpClient.Dispose();
180+
#endif
173181
}
174182
}
175183

@@ -288,12 +296,20 @@ private async Task<bool> PingAsync(TimeSpan span)
288296
{
289297
try
290298
{
299+
#if NET48
300+
HttpWebResponse response = await GetHttpResponseAsync(status).ConfigureAwait(false);
301+
if (response.StatusCode == HttpStatusCode.OK)
302+
{
303+
return true;
304+
}
305+
#elif NET
291306
HttpResponseMessage response = await GetHttpResponseAsync(status).ConfigureAwait(false);
292307

293308
if (response.IsSuccessStatusCode)
294309
{
295310
return true;
296311
}
312+
#endif
297313
}
298314
catch
299315
{
@@ -302,11 +318,21 @@ private async Task<bool> PingAsync(TimeSpan span)
302318
}
303319
return pinged;
304320
}
305-
306-
private async Task<HttpResponseMessage> GetHttpResponseAsync(Uri status)
321+
#if NET48
322+
private async Task<HttpWebResponse> GetHttpResponseAsync(Uri status)
307323
{
308-
HttpResponseMessage response = await SharedHttpClient.GetAsync(status).ConfigureAwait(false);
309-
return response;
324+
return await Task.Run(() =>
325+
{
326+
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(status);
327+
return (HttpWebResponse)request.GetResponse();
328+
}).ConfigureAwait(false);
310329
}
330+
#else
331+
private async Task<HttpResponseMessage> GetHttpResponseAsync(Uri status)
332+
{
333+
HttpResponseMessage response = await SharedHttpClient.GetAsync(status).ConfigureAwait(false);
334+
return response;
335+
}
336+
#endif
311337
}
312338
}

test/integration/Android/ClipboardTest.cs

+2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public void WhenSetClipboardContentTypeIsImageSetClipboardShouldReturnNotImpleme
8383
}
8484

8585
[Test]
86+
#if !NET48
8687
[SupportedOSPlatform("windows")]
88+
#endif
8789
public void WhenGetClipboardImageGetClipboardShouldReturnNotImplementedException()
8890
{
8991
Assert.That(() => _driver.GetClipboardImage(),

test/integration/Appium.Net.Integration.Tests.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net6.0</TargetFrameworks>
3+
<TargetFrameworks>net48;net6.0</TargetFrameworks>
4+
<LangVersion>latest</LangVersion>
45
</PropertyGroup>
56
<ItemGroup>
67
<Compile Remove="apps\**" />

0 commit comments

Comments
 (0)