Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML deserialization support & CI fixes #21

Merged
merged 5 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -50,22 +51,22 @@
/// <summary>
/// Gets the JSON body content of the request.
/// </summary>
public object Body { get; private set; } = null;

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

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

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

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

/// <summary>
/// Gets the binary document content of the request.
/// </summary>
public byte[] DocumentBody { get; private set; } = null;

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

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

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

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

/// <summary>
/// Gets the name of the binary document file.
/// </summary>
public string DocumentFileName { get; private set; } = null;

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

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

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

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

/// <summary>
/// Gets the content type of the request.
/// </summary>
public string ContentType { get; private set; } = null;

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

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

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

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
#endregion

#region Constructors
Expand Down Expand Up @@ -392,8 +393,24 @@

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.

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.

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.

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.

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
Loading