-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New random packages support + remove "No content found" message
- Loading branch information
1 parent
720cb1e
commit eca5453
Showing
21 changed files
with
167 additions
and
192 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
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
23 changes: 0 additions & 23 deletions
23
src/SIGame/SIGame.ViewModel/PackageSources/RandomServerPackageSource.cs
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
src/SIGame/SIGame.ViewModel/PackageSources/RandomStoragePackageSource.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,64 @@ | ||
using SIGame.ViewModel.Properties; | ||
using SIStorage.Service.Contract; | ||
using SIStorage.Service.Contract.Requests; | ||
using System.Net; | ||
|
||
namespace SIGame.ViewModel.PackageSources; | ||
|
||
/// <summary> | ||
/// Represents random storage package source. | ||
/// </summary> | ||
public sealed class RandomStoragePackageSource : PackageSource | ||
{ | ||
private readonly ISIStorageServiceClient _storageServiceClient; | ||
private Uri? _packageUri; | ||
|
||
public override PackageSourceKey Key => new() { Type = PackageSourceTypes.RandomServer }; | ||
|
||
public override string Source => Resources.RandomServerThemes; | ||
|
||
public override bool RandomSpecials => true; | ||
|
||
public RandomStoragePackageSource(ISIStorageServiceClient storageServiceClient) => _storageServiceClient = storageServiceClient; | ||
|
||
public override Task<(string, bool)> GetPackageFileAsync(CancellationToken cancellationToken = default) => | ||
throw new NotImplementedException(); | ||
|
||
public override async Task<byte[]> GetPackageHashAsync(CancellationToken cancellationToken = default) | ||
{ | ||
if (_packageUri == null) | ||
{ | ||
_packageUri = await CreateRandomPackageAsync(cancellationToken); | ||
} | ||
|
||
return Array.Empty<byte>(); | ||
} | ||
|
||
public override string GetPackageName() => ""; | ||
|
||
public override Uri? GetPackageUri() => _packageUri; | ||
|
||
private async Task<Uri> CreateRandomPackageAsync(CancellationToken cancellationToken = default) | ||
{ | ||
try | ||
{ | ||
var package = await _storageServiceClient.Packages.GetRandomPackageAsync( | ||
new RandomPackageParameters | ||
{ | ||
RestrictionIds = new int[] { -1 } | ||
}, | ||
cancellationToken); | ||
|
||
if (package.DirectContentUri == null) | ||
{ | ||
throw new Exception("Random package generation failed"); | ||
} | ||
|
||
return package.DirectContentUri; | ||
} | ||
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.TooManyRequests) | ||
{ | ||
throw new Exception(Resources.TooMuchRandomPackages, ex); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.