generated from JustArchiNET/ASF-PluginTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Redlib for free game discovery, add configurations, strateg…
…ies, error handling, tests and update build process This commit introduces Redlib integration into the ASFFreeGames project, allowing it to fetch free games from Redlib instances. Key changes include: * **Redlib Integration:** * Added support for Redlib as a source for finding free games. * Implemented `RedlibListFreeGamesStrategy` to fetch games from Redlib instances. * Introduced configurations for Redlib proxy and instance URL. * Updated `ListFreeGamesMainStrategy` to handle fetching from Redlib as a fallback strategy. * **Code refactoring:** * Introduced `EListFreeGamesStrategy` enum to represent supported free game listing sources (Reddit, Redlib). * Improved logic for handling successful and failed attempts in `ListFreeGamesMainStrategy`. * Added exception handling for Redlib related issues. * **Testing:** * Added a new unit test (`RedlibInstanceListTests.Test`) to verify Redlib instance listing functionality. * Updated `FreeGamesCommand.Test` to handle Redlib strategy. * **Build:** * Added `Resouces` folder to the project. * Included `redlib_instances.json` as an embedded resource to store Redlib instances.
- Loading branch information
Showing
32 changed files
with
995 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using ASFFreeGames.Configurations; | ||
using Maxisoft.ASF.Redlib; | ||
using Maxisoft.ASF.Redlib.Html; | ||
using Maxisoft.ASF.Redlib.Instances; | ||
using Xunit; | ||
|
||
namespace Maxisoft.ASF.Tests.Redlib; | ||
|
||
public class RedlibInstanceListTests { | ||
[Fact] | ||
public async void Test() { | ||
RedlibInstanceList lister = new(new ASFFreeGamesOptions()); | ||
List<Uri> uris = await RedlibInstanceList.ListFromEmbedded(default(CancellationToken)).ConfigureAwait(false); | ||
|
||
Assert.NotEmpty(uris); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
ASFFreeGames/FreeGames/Strategies/EListFreeGamesStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Maxisoft.ASF.FreeGames.Strategies; | ||
|
||
[Flags] | ||
public enum EListFreeGamesStrategy { | ||
None = 0, | ||
Reddit = 1 << 0, | ||
Redlib = 1 << 1 | ||
} |
15 changes: 15 additions & 0 deletions
15
ASFFreeGames/FreeGames/Strategies/HttpRequestRedlibException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Net; | ||
using Maxisoft.ASF.Redlib; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Maxisoft.ASF.FreeGames.Strategies; | ||
|
||
public class HttpRequestRedlibException : RedlibException { | ||
public required HttpStatusCode? StatusCode { get; init; } | ||
public required Uri? Uri { get; init; } | ||
|
||
public HttpRequestRedlibException() { } | ||
public HttpRequestRedlibException(string message) : base(message) { } | ||
public HttpRequestRedlibException(string message, Exception inner) : base(message, inner) { } | ||
} |
26 changes: 26 additions & 0 deletions
26
ASFFreeGames/FreeGames/Strategies/IListFreeGamesStrategy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Maxisoft.ASF.Reddit; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Maxisoft.ASF.FreeGames.Strategies; | ||
|
||
[SuppressMessage("ReSharper", "RedundantNullableFlowAttribute")] | ||
public interface IListFreeGamesStrategy : IDisposable { | ||
Task<IReadOnlyCollection<RedditGameEntry>> GetGames([NotNull] ListFreeGamesContext context, CancellationToken cancellationToken); | ||
|
||
public static Exception ExceptionFromTask<T>([NotNull] Task<T> task) { | ||
if (task is { IsFaulted: true, Exception: not null }) { | ||
return task.Exception.InnerExceptions.Count == 1 ? task.Exception.InnerExceptions[0] : task.Exception; | ||
} | ||
|
||
if (task.IsCanceled) { | ||
return new TaskCanceledException(); | ||
} | ||
|
||
throw new InvalidOperationException("Unknown task state"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using ASFFreeGames.Configurations; | ||
using Maxisoft.ASF.HttpClientSimple; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Maxisoft.ASF.FreeGames.Strategies; | ||
|
||
public sealed record ListFreeGamesContext(ASFFreeGamesOptions Options, Lazy<SimpleHttpClient> HttpClient, uint Retry = 5) { | ||
public required SimpleHttpClientFactory HttpClientFactory { get; init; } | ||
public EListFreeGamesStrategy PreviousSucessfulStrategy { get; set; } | ||
|
||
public required IListFreeGamesStrategy Strategy { get; init; } | ||
} |
Oops, something went wrong.