using System.IO;
using System.Threading.Tasks;
using Dpz.Core.Service.ObjectStorage;
using Dpz.Core.Service.ObjectStorage.Services;
using Dpz.Core.Service.RepositoryService;
using Hangfire;
using MongoDB.Bson;
namespace Dpz.Core.Web.Library.Activator;
public class SteamActivator : JobActivator
{
private readonly ISteamGameService _steamGameService;
private readonly IObjectStorageOperation _objectStorageService;
public SteamActivator(
ISteamGameService steamGameService,
IObjectStorageOperation objectStorageService)
{
_steamGameService = steamGameService;
_objectStorageService = objectStorageService;
}
[ProlongExpirationTime]
public async Task UpdateLibraryAsync()
{
_steamGameService.OnLogoDownloadComplete += SteamGameServiceOnOnLogoDownloadComplete;
_steamGameService.OnAchievementIconDownloadComplete += SteamGameServiceOnOnAchievementIconDownloadComplete;
_steamGameService.OnAchievementIconGrayDownloadComplete += SteamGameServiceOnOnAchievementIconGrayDownloadComplete;
await _steamGameService.UpdateGamesAsync();
}
private async Task<string> SteamGameServiceOnOnAchievementIconGrayDownloadComplete(Stream stream,int id,string name)
{
if (stream == null)
return "";
var result = await _objectStorageService.UploadAsync(stream, new[] {"images", "steam","gray_icon",id.ToString()}, $"{ObjectId.GenerateNewId()}.jpg");
return result.AccessUrl;
}
private async Task<string> SteamGameServiceOnOnAchievementIconDownloadComplete(Stream stream,int id,string name)
{
if (stream == null)
return "";
var result = await _objectStorageService.UploadAsync(stream, new[] {"images", "steam","icon",id.ToString()}, $"{ObjectId.GenerateNewId()}.jpg");
return result.AccessUrl;
}
private async Task<string> SteamGameServiceOnOnLogoDownloadComplete(Stream stream, int id)
{
if (stream == null)
return "";
var result = await _objectStorageService.UploadAsync(stream, new[] {"images", "steam","logo"}, $"{id}.jpg");
return result.AccessUrl;
}
}