Skip to content

Commit

Permalink
Merge pull request #21 from FrApp42/dev/main
Browse files Browse the repository at this point in the history
XML deserialization support & CI fixes
  • Loading branch information
sikelio authored Oct 6, 2024
2 parents fbf7e7d + 2f77cac commit 22aa4cd
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
Expand Down
11 changes: 1 addition & 10 deletions Docs/docs/Awake.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,9 @@ Awake.CompleteExit(0, false, "AppName");
Updated version of Power Awake

```C#
using FrApps42.System.Computer.Awake.v1;
using FrApps42.System.Computer.Awake.v2;
...

private static void LogUnexpectedOrCancelledKeepAwakeThreadCompletion(){
Console.WriteLine("The keep-awake thread was terminated early.");
}

private static void LogCompletedKeepAwakeThread(bool result)
{
Console.WriteLine($"Exited keep-awake thread successfully: {result}");
}

// Keep Screen on
Awake..SetIndefiniteKeepAwake(true);
// Keep Screen off
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This repos contains tool classes in C# for multiple types of usage.
* WakeOnLan: Power on a device with it mac address.

* `FrApp42.Web` - [Link](https://www.nuget.org/packages/FrApp42.Web)
* Request: Make API request for any of your C# projects. ⚠️ *SOAP requests are not supported.* ⚠️
* Request: Make API request for any of your C# projects.

## Authors
* [AnthoDingo](https://github.com)
Expand Down
4 changes: 2 additions & 2 deletions System/System.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Title>FrApp42 System</Title>
<Authors>FrenchyApps42, Sikelio, AnthoDingo</Authors>
<Copyright>GPLv3</Copyright>
<PackageProjectUrl>https://github.com/FrApp42/Tools</PackageProjectUrl>
<PackageProjectUrl>https://frapp42.github.io/Tools/api.System/FrApp42.System.Computer.Awake.v1.html</PackageProjectUrl>
<RepositoryUrl>https://github.com/FrApp42/Tools.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
Expand All @@ -22,7 +22,7 @@
<PackageIcon>logo.png</PackageIcon>
<Version>1.1.0</Version>
<AssemblyVersion>1.1.0</AssemblyVersion>
<PackageReleaseNotes>Implement Awake from Microsoft Powertoys</PackageReleaseNotes>
<PackageReleaseNotes>Fix Awake v1 &amp; v2</PackageReleaseNotes>
<FileVersion>1.1.0</FileVersion>
</PropertyGroup>

Expand Down
21 changes: 19 additions & 2 deletions Web/API/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Text;
using System.Xml.Serialization;

namespace FrApp42.Web.API
{
Expand Down Expand Up @@ -392,8 +393,24 @@ private async Task<Result<T>> Process<T>(HttpRequestMessage request)

if (response.IsSuccessStatusCode)
{
Stream ContentResponse = await response.Content?.ReadAsStreamAsync();
result.Value = await System.Text.Json.JsonSerializer.DeserializeAsync<T>(ContentResponse);
string MediaType = response.Content?.Headers?.ContentType?.MediaType.ToLower();

Check warning on line 396 in Web/API/Request.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 396 in Web/API/Request.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
string ContentResponse = await response.Content?.ReadAsStringAsync();

Check warning on line 397 in Web/API/Request.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

switch (true)
{
case bool b when (MediaType.Contains("application/xml")):

Check warning on line 401 in Web/API/Request.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
XmlSerializer xmlSerializer = new(typeof(T));
StringReader reader = new(ContentResponse);

result.Value = (T)xmlSerializer.Deserialize(reader);

Check warning on line 405 in Web/API/Request.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
break;
case bool b when (MediaType.Contains("application/json")):
result.Value = JsonConvert.DeserializeObject<T>(ContentResponse);
break;
default:
result.Value = default;
break;
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Web/Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Title>FrApp42 Web</Title>
<Authors>FrenchyApps42, Sikelio, AnthoDingo</Authors>
<Copyright>GPLv3</Copyright>
<PackageProjectUrl>https://github.com/FrApp42/Tools</PackageProjectUrl>
<PackageProjectUrl>https://frapp42.github.io/Tools/api.Web/FrApp42.Web.API.html</PackageProjectUrl>
<RepositoryUrl>https://github.com/FrApp42/Tools.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
Expand All @@ -20,7 +20,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<Company>FrenchyApps42</Company>
<PackageIcon>logo.png</PackageIcon>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 22aa4cd

Please sign in to comment.