Fixed issue with "UNIQUE" appid in cache during initialization.

Adjusted async code to new changes.
This commit is contained in:
Jeddunk 2021-03-24 10:21:59 +01:00
parent c823aa15fb
commit b2cdd34cf8
2 changed files with 17 additions and 17 deletions

View File

@ -20,9 +20,9 @@ namespace GoldbergGUI.Core.Services
public interface ISteamService public interface ISteamService
{ {
public Task Initialize(IMvxLog log); public Task Initialize(IMvxLog log);
public IEnumerable<SteamApp> GetListOfAppsByName(string name); public Task<IEnumerable<SteamApp>> GetListOfAppsByName(string name);
public SteamApp GetAppByName(string name); public Task<SteamApp> GetAppByName(string name);
public SteamApp GetAppById(int appid); public Task<SteamApp> GetAppById(int appid);
public Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb); public Task<List<SteamApp>> GetListOfDlc(SteamApp steamApp, bool useSteamDb);
} }
@ -78,7 +78,6 @@ namespace GoldbergGUI.Core.Services
private const string UserAgent = private const string UserAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " +
"Chrome/87.0.4280.88 Safari/537.36"; "Chrome/87.0.4280.88 Safari/537.36";
private const string AppTypeGame = "game"; private const string AppTypeGame = "game";
private const string AppTypeDlc = "dlc"; private const string AppTypeDlc = "dlc";
private const string Database = "steamapps.cache"; private const string Database = "steamapps.cache";
@ -134,36 +133,37 @@ namespace GoldbergGUI.Core.Services
cache.Add(steamApp); cache.Add(steamApp);
} }
await _db.InsertAllAsync(cache).ConfigureAwait(false); await _db.InsertAllAsync(cache, "OR IGNORE").ConfigureAwait(false);
} }
} }
} }
public IEnumerable<SteamApp> GetListOfAppsByName(string name) public async Task<IEnumerable<SteamApp>> GetListOfAppsByName(string name)
{ {
var query = _db.Table<SteamApp>() var query = await _db.Table<SteamApp>()
.Where(x => x.type == AppTypeGame).ToListAsync().Result; .Where(x => x.type == AppTypeGame).ToListAsync().ConfigureAwait(false);
var listOfAppsByName = query.Search(x => x.Name) var listOfAppsByName = query.Search(x => x.Name)
.SetCulture(StringComparison.OrdinalIgnoreCase) .SetCulture(StringComparison.OrdinalIgnoreCase)
.ContainingAll(name.Split(' ')); .ContainingAll(name.Split(' '));
return listOfAppsByName; return listOfAppsByName;
} }
public SteamApp GetAppByName(string name) public async Task<SteamApp> GetAppByName(string name)
{ {
_log.Info($"Trying to get app {name}"); _log.Info($"Trying to get app {name}");
var comparableName = PrepareStringToCompare(name); var comparableName = PrepareStringToCompare(name);
var app = _db.Table<SteamApp>() var app = await _db.Table<SteamApp>()
.FirstOrDefaultAsync(x => x.type == AppTypeGame && x.ComparableName.Equals(comparableName)).Result; .FirstOrDefaultAsync(x => x.type == AppTypeGame && x.ComparableName.Equals(comparableName))
.ConfigureAwait(false);
if (app != null) _log.Info($"Successfully got app {app}"); if (app != null) _log.Info($"Successfully got app {app}");
return app; return app;
} }
public SteamApp GetAppById(int appid) public async Task<SteamApp> GetAppById(int appid)
{ {
_log.Info($"Trying to get app with ID {appid}"); _log.Info($"Trying to get app with ID {appid}");
var app = _db.Table<SteamApp>().Where(x => x.type == AppTypeGame) var app = await _db.Table<SteamApp>().Where(x => x.type == AppTypeGame)
.FirstOrDefaultAsync(x => x.AppId.Equals(appid)).Result; .FirstOrDefaultAsync(x => x.AppId.Equals(appid)).ConfigureAwait(false);
if (app != null) _log.Info($"Successfully got app {app}"); if (app != null) _log.Info($"Successfully got app {app}");
return app; return app;
} }

View File

@ -321,7 +321,7 @@ namespace GoldbergGUI.Core.ViewModels
MainWindowEnabled = false; MainWindowEnabled = false;
StatusText = "Trying to find AppID..."; StatusText = "Trying to find AppID...";
var appByName = _steam.GetAppByName(_gameName); var appByName = await _steam.GetAppByName(_gameName).ConfigureAwait(false);
if (appByName != null) if (appByName != null)
{ {
GameName = appByName.Name; GameName = appByName.Name;
@ -329,7 +329,7 @@ namespace GoldbergGUI.Core.ViewModels
} }
else else
{ {
var list = _steam.GetListOfAppsByName(GameName); var list = await _steam.GetListOfAppsByName(GameName).ConfigureAwait(false);
var steamApps = list as SteamApp[] ?? list.ToArray(); var steamApps = list as SteamApp[] ?? list.ToArray();
if (steamApps.Length == 1) if (steamApps.Length == 1)
{ {
@ -364,7 +364,7 @@ namespace GoldbergGUI.Core.ViewModels
return; return;
} }
var steamApp = await Task.Run(() => _steam.GetAppById(AppId)).ConfigureAwait(false); var steamApp = await _steam.GetAppById(AppId).ConfigureAwait(false);
if (steamApp != null) GameName = steamApp.Name; if (steamApp != null) GameName = steamApp.Name;
} }