Skip to content

Commit

Permalink
New random packages support + remove "No content found" message
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirKhil committed Feb 22, 2024
1 parent 720cb1e commit eca5453
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<None Include="key.snk" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="VKhil.SIStorage.Client" Version="1.0.1" />
<PackageReference Include="VKhil.SIStorage.Client" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SIPackages\SIPackages.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="VKhil.SIStorage.Client" Version="1.0.1" />
<PackageReference Include="VKhil.SIStorage.Client" Version="1.1.0" />
</ItemGroup>

</Project>
10 changes: 3 additions & 7 deletions src/SIGame/SIGame.ViewModel/Helpers/GameResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ public static GameReport ToGameReport(this GameResult gameResult)

return new GameReport
{
Info = new GameResultInfo
Info = new GameResultInfo(
new PackageInfo(gameResult.PackageName, gameResult.PackageHash, gameResult.PackageAuthors, gameResult.PackageAuthorsContacts),
gameResult.Language)
{
FinishTime = DateTimeOffset.UtcNow,
Duration = gameResult.Duration,
Name = gameResult.Name,
Package = new PackageInfo
{
Authors = gameResult.PackageAuthors,
Hash = gameResult.PackageHash,
Name = gameResult.PackageName
},
Platform = GamePlatforms.Local,
Results = gameResult.Results,
Reviews = gameResult.Reviews
Expand Down

This file was deleted.

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);
}
}
}
9 changes: 9 additions & 0 deletions src/SIGame/SIGame.ViewModel/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/SIGame/SIGame.ViewModel/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,7 @@
<data name="UnknownError" xml:space="preserve">
<value>Unknown error</value>
</data>
<data name="TooMuchRandomPackages" xml:space="preserve">
<value>You created too much random pakages. Please try again later</value>
</data>
</root>
3 changes: 3 additions & 0 deletions src/SIGame/SIGame.ViewModel/Properties/Resources.ru-RU.resx
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,7 @@
<data name="UnknownError" xml:space="preserve">
<value>Неизвестная ошибка</value>
</data>
<data name="TooMuchRandomPackages" xml:space="preserve">
<value>Вы создали слишком много случайных пакетов. Попробуйте ещё раз позже</value>
</data>
</root>
4 changes: 2 additions & 2 deletions src/SIGame/SIGame.ViewModel/SIGame.ViewModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="VKhil.SIContentService.Client" Version="1.0.10" />
<PackageReference Include="VKhil.SIStatisticsService.Client" Version="1.0.2" />
<PackageReference Include="VKhil.SIContentService.Client" Version="1.1.1" />
<PackageReference Include="VKhil.SIStatisticsService.Client" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\Notions\Notions.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SICore;
using Microsoft.Extensions.DependencyInjection;
using SICore;
using SICore.BusinessLogic;
using SICore.Clients;
using SICore.Contracts;
Expand All @@ -14,6 +15,7 @@
using SIGame.ViewModel.Properties;
using SIGame.ViewModel.Web;
using SIPackages;
using SIStorage.Service.Contract;
using SIStorageService.ViewModel;
using SIUI.ViewModel;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -440,7 +442,7 @@ public GameSettingsViewModel(
break;

case PackageSourceTypes.RandomServer:
Package = new RandomServerPackageSource();
Package = new RandomStoragePackageSource(PlatformManager.Instance.ServiceProvider!.GetRequiredService<ISIStorageServiceClient>());
break;

case PackageSourceTypes.Local:
Expand Down Expand Up @@ -524,7 +526,7 @@ private async Task SelectPackage_Executed(object? arg)
break;

case PackageSourceTypes.RandomServer:
Package = new RandomServerPackageSource();
Package = new RandomStoragePackageSource(PlatformManager.Instance.ServiceProvider!.GetRequiredService<ISIStorageServiceClient>());
break;

case PackageSourceTypes.Local:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,6 @@ public void OnContent(string[] mparams)

if (content.Count == 0)
{
OnSpecialReplic("No content found");
return;
}

Expand Down
Loading

0 comments on commit eca5453

Please sign in to comment.