WIP
This commit is contained in:
@@ -677,6 +677,14 @@ namespace gaseous_server.Classes
|
||||
|
||||
public class MetadataAPI
|
||||
{
|
||||
public static string _HasheousClientAPIKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Pna5SRcbJ6R8aasytab_6vZD0aBKDGNZKRz4WY4xArpfZ-3mdZq0hXIGyy0AD43b";
|
||||
}
|
||||
}
|
||||
|
||||
private static HasheousClient.Models.MetadataModel.MetadataSources _MetadataSource
|
||||
{
|
||||
get
|
||||
@@ -749,6 +757,9 @@ namespace gaseous_server.Classes
|
||||
|
||||
public string HasheousAPIKey = _HasheousAPIKey;
|
||||
|
||||
[JsonIgnore]
|
||||
public string HasheousClientAPIKey = _HasheousClientAPIKey;
|
||||
|
||||
public int MaxLibraryScanWorkers = _MaxLibraryScanWorkers;
|
||||
|
||||
public string HasheousHost = _HasheousHost;
|
||||
|
@@ -197,7 +197,11 @@ namespace gaseous_server.Classes
|
||||
libraryRootPath += Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
bool GetLastThreeElements = (bool)row["DefaultLibrary"];
|
||||
bool GetLastThreeElements = false;
|
||||
if ((int)row["DefaultLibrary"] == 1)
|
||||
{
|
||||
GetLastThreeElements = true;
|
||||
}
|
||||
|
||||
foreach (DataRow romRow in romData.Rows)
|
||||
{
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
using IGDB;
|
||||
@@ -7,9 +8,9 @@ using Microsoft.CodeAnalysis.Classification;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class AgeRatings
|
||||
public class AgeRatings
|
||||
{
|
||||
const string fieldList = "fields category,checksum,content_descriptions,rating,rating_cover_url,synopsis;";
|
||||
public const string fieldList = "fields category,checksum,content_descriptions,rating,rating_cover_url,synopsis;";
|
||||
|
||||
public AgeRatings()
|
||||
{
|
||||
@@ -23,61 +24,33 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<AgeRating> RetVal = _GetAgeRatings(SearchUsing.id, Id);
|
||||
Task<AgeRating> RetVal = _GetAgeRatings((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static AgeRating GetAgeRatings(string Slug)
|
||||
{
|
||||
Task<AgeRating> RetVal = _GetAgeRatings(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<AgeRating> _GetAgeRatings(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<AgeRating> _GetAgeRatings(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("AgeRating", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("AgeRating", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("AgeRating", (long)searchValue);
|
||||
|
||||
AgeRating returnValue = new AgeRating();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
UpdateSubClasses(returnValue);
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<AgeRating>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -102,17 +75,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<AgeRating> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<AgeRating> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get AgeRatings metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<AgeRating>(IGDBClient.Endpoints.AgeRating, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<AgeRating>(Communications.MetadataEndpoint.AgeRating, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
@@ -157,7 +124,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
db.ExecuteNonQuery(sql);
|
||||
|
||||
// loop all age groups
|
||||
foreach(KeyValuePair<AgeGroups.AgeRestrictionGroupings, AgeGroups.AgeGroupItem> ageGrouping in AgeGroups.AgeGroupingsFlat)
|
||||
foreach (KeyValuePair<AgeGroups.AgeRestrictionGroupings, AgeGroups.AgeGroupItem> ageGrouping in AgeGroups.AgeGroupingsFlat)
|
||||
{
|
||||
AgeGroups.AgeGroupItem ageGroupItem = ageGrouping.Value;
|
||||
var properties = ageGroupItem.GetType().GetProperties();
|
||||
@@ -170,7 +137,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
AgeRatingCategory ageRatingCategory = (AgeRatingCategory)Enum.Parse(typeof(AgeRatingCategory), prop.Name);
|
||||
List<AgeRatingTitle> ageRatingTitles = (List<AgeRatingTitle>)prop.GetValue(ageGroupItem);
|
||||
|
||||
|
||||
foreach (AgeRatingTitle ageRatingTitle in ageRatingTitles)
|
||||
{
|
||||
dbDict.Clear();
|
||||
@@ -186,6 +153,6 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,9 +5,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class AgeRatingContentDescriptions
|
||||
public class AgeRatingContentDescriptions
|
||||
{
|
||||
const string fieldList = "fields category,checksum,description;";
|
||||
public const string fieldList = "fields category,checksum,description;";
|
||||
|
||||
public AgeRatingContentDescriptions()
|
||||
{
|
||||
@@ -21,60 +21,32 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<AgeRatingContentDescription> RetVal = _GetAgeRatingContentDescriptions(SearchUsing.id, Id);
|
||||
Task<AgeRatingContentDescription> RetVal = _GetAgeRatingContentDescriptions((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static AgeRatingContentDescription GetAgeRatingContentDescriptions(string Slug)
|
||||
{
|
||||
Task<AgeRatingContentDescription> RetVal = _GetAgeRatingContentDescriptions(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<AgeRatingContentDescription> _GetAgeRatingContentDescriptions(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<AgeRatingContentDescription> _GetAgeRatingContentDescriptions(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("AgeRatingContentDescription", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("AgeRatingContentDescription", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("AgeRatingContentDescription", searchValue);
|
||||
|
||||
AgeRatingContentDescription returnValue = new AgeRatingContentDescription();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<AgeRatingContentDescription>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -88,21 +60,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<AgeRatingContentDescription> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<AgeRatingContentDescription> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get AgeRatingContentDescriptionContentDescriptions metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<AgeRatingContentDescription>(IGDBClient.Endpoints.AgeRatingContentDescriptions, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<AgeRatingContentDescription>(Communications.MetadataEndpoint.AgeRatingContentDescription, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,9 +5,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class AlternativeNames
|
||||
public class AlternativeNames
|
||||
{
|
||||
const string fieldList = "fields checksum,comment,game,name;";
|
||||
public const string fieldList = "fields checksum,comment,game,name;";
|
||||
|
||||
public AlternativeNames()
|
||||
{
|
||||
@@ -21,60 +21,32 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<AlternativeName> RetVal = _GetAlternativeNames(SearchUsing.id, Id);
|
||||
Task<AlternativeName> RetVal = _GetAlternativeNames((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static AlternativeName GetAlternativeNames(string Slug)
|
||||
{
|
||||
Task<AlternativeName> RetVal = _GetAlternativeNames(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<AlternativeName> _GetAlternativeNames(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<AlternativeName> _GetAlternativeNames(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("AlternativeName", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("AlternativeName", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("AlternativeName", searchValue);
|
||||
|
||||
AlternativeName returnValue = new AlternativeName();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<AlternativeName>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -88,21 +60,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<AlternativeName> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<AlternativeName> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get AlternativeNames metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<AlternativeName>(IGDBClient.Endpoints.AlternativeNames, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<AlternativeName>(Communications.MetadataEndpoint.AlternativeName, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Artworks
|
||||
{
|
||||
const string fieldList = "fields alpha_channel,animated,checksum,game,height,image_id,url,width;";
|
||||
public const string fieldList = "fields alpha_channel,animated,checksum,game,height,image_id,url,width;";
|
||||
|
||||
public Artworks()
|
||||
{
|
||||
@@ -21,43 +21,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Artwork> RetVal = _GetArtwork(SearchUsing.id, Id, ImagePath, GetImages);
|
||||
Task<Artwork> RetVal = _GetArtwork((long)Id, ImagePath, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Artwork GetArtwork(string Slug, string ImagePath, bool GetImages)
|
||||
{
|
||||
Task<Artwork> RetVal = _GetArtwork(SearchUsing.slug, Slug, ImagePath, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<Artwork> _GetArtwork(SearchUsing searchUsing, object searchValue, string ImagePath, bool GetImages = true)
|
||||
private static async Task<Artwork> _GetArtwork(long searchValue, string ImagePath, bool GetImages = true)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Artwork", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Artwork", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("Artwork", searchValue);
|
||||
|
||||
Artwork returnValue = new Artwork();
|
||||
bool forceImageDownload = false;
|
||||
@@ -65,14 +37,14 @@ namespace gaseous_server.Classes.Metadata
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
forceImageDownload = true;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
|
||||
// check if old value is different from the new value - only download if it's different
|
||||
@@ -84,7 +56,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<Artwork>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -111,17 +83,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<Artwork> GetObjectFromServer(string WhereClause, string ImagePath)
|
||||
private static async Task<Artwork> GetObjectFromServer(long searchValue, string ImagePath)
|
||||
{
|
||||
// get Artwork metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Artwork>(IGDBClient.Endpoints.Artworks, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Artwork>(Communications.MetadataEndpoint.Artwork, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -5,9 +5,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Collections
|
||||
public class Collections
|
||||
{
|
||||
const string fieldList = "fields as_child_relations,as_parent_relations,checksum,created_at,games,name,slug,type,updated_at,url;";
|
||||
public const string fieldList = "fields as_child_relations,as_parent_relations,checksum,created_at,games,name,slug,type,updated_at,url;";
|
||||
|
||||
public Collections()
|
||||
{
|
||||
@@ -21,60 +21,32 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Collection> RetVal = _GetCollections(SearchUsing.id, Id);
|
||||
Task<Collection> RetVal = _GetCollections((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Collection GetCollections(string Slug)
|
||||
{
|
||||
Task<Collection> RetVal = _GetCollections(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<Collection> _GetCollections(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<Collection> _GetCollections(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Collection", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Collection", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("Collection", searchValue);
|
||||
|
||||
Collection returnValue = new Collection();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<Collection>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -88,21 +60,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<Collection> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<Collection> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get Collections metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Collection>(IGDBClient.Endpoints.Collections, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Collection>(Communications.MetadataEndpoint.Collection, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,8 @@ using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Net;
|
||||
using System.Security.Policy;
|
||||
using HasheousClient.Models.Metadata.IGDB;
|
||||
using Humanizer;
|
||||
using IGDB;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
@@ -24,12 +26,17 @@ namespace gaseous_server.Classes.Metadata
|
||||
client.DefaultRequestHeaders.Add("Accept-Encoding", "deflate");
|
||||
}
|
||||
|
||||
// configure the IGDB client
|
||||
private static IGDBClient igdb = new IGDBClient(
|
||||
// Found in Twitch Developer portal for your app
|
||||
Config.IGDB.ClientId,
|
||||
Config.IGDB.Secret
|
||||
);
|
||||
|
||||
// provide the hasheous client
|
||||
private static HasheousClient.Hasheous hasheous = new HasheousClient.Hasheous();
|
||||
|
||||
|
||||
private static HttpClient client = new HttpClient();
|
||||
|
||||
/// <summary>
|
||||
@@ -57,6 +64,18 @@ namespace gaseous_server.Classes.Metadata
|
||||
RateLimitRecoveryWaitTime = 10000;
|
||||
|
||||
break;
|
||||
|
||||
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
||||
// set rate limiter avoidance values
|
||||
RateLimitAvoidanceWait = 1500;
|
||||
RateLimitAvoidanceThreshold = 3;
|
||||
RateLimitAvoidancePeriod = 1;
|
||||
|
||||
// set rate limiter recovery values
|
||||
RateLimitRecoveryWaitTime = 10000;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
// leave all values at default
|
||||
break;
|
||||
@@ -159,8 +178,248 @@ namespace gaseous_server.Classes.Metadata
|
||||
private int RetryAttempts = 0;
|
||||
private int RetryAttemptsMax = 3;
|
||||
|
||||
public enum MetadataEndpoint
|
||||
{
|
||||
AgeGroup,
|
||||
AgeRating,
|
||||
AgeRatingContentDescription,
|
||||
AlternativeName,
|
||||
Artwork,
|
||||
Collection,
|
||||
Company,
|
||||
CompanyLogo,
|
||||
Cover,
|
||||
ExternalGame,
|
||||
Franchise,
|
||||
GameMode,
|
||||
Game,
|
||||
GameVideo,
|
||||
Genre,
|
||||
InvolvedCompany,
|
||||
MultiplayerMode,
|
||||
PlatformLogo,
|
||||
Platform,
|
||||
PlatformVersion,
|
||||
PlayerPerspective,
|
||||
ReleaseDate,
|
||||
Search,
|
||||
Screenshot,
|
||||
Theme
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request data from the metadata API
|
||||
/// Request data from the metadata API using a slug
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// The type of object to return
|
||||
/// </typeparam>
|
||||
/// <param name="Endpoint">
|
||||
/// The endpoint to access - can only be either Platform or Game
|
||||
/// </param>
|
||||
/// <param name="Slug">
|
||||
/// The slug to query for
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The object requested
|
||||
/// </returns>
|
||||
public async Task<T[]?> APIComm<T>(MetadataEndpoint Endpoint, string Slug)
|
||||
{
|
||||
switch (_MetadataSource)
|
||||
{
|
||||
case HasheousClient.Models.MetadataModel.MetadataSources.None:
|
||||
return null;
|
||||
case HasheousClient.Models.MetadataModel.MetadataSources.IGDB:
|
||||
string fieldList = "";
|
||||
string query = "where slug = \"" + Slug + "\"";
|
||||
string EndpointString = "";
|
||||
|
||||
switch (Endpoint)
|
||||
{
|
||||
case MetadataEndpoint.Platform:
|
||||
fieldList = Platforms.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Platforms;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Game:
|
||||
fieldList = Games.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Games;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception("Endpoint must be either Platform or Game");
|
||||
|
||||
}
|
||||
|
||||
return await IGDBAPI<T>(EndpointString, fieldList, query);
|
||||
|
||||
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
||||
return null;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request data from the metadata API using an id
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// The type of object to return
|
||||
/// </typeparam>
|
||||
/// <param name="Endpoint">
|
||||
/// The endpoint to access
|
||||
/// </param>
|
||||
/// <param name="Id">
|
||||
/// The Id to query for
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The object requested
|
||||
/// </returns>
|
||||
public async Task<T[]> APIComm<T>(MetadataEndpoint Endpoint, long Id)
|
||||
{
|
||||
switch (_MetadataSource)
|
||||
{
|
||||
case HasheousClient.Models.MetadataModel.MetadataSources.None:
|
||||
return null;
|
||||
case HasheousClient.Models.MetadataModel.MetadataSources.IGDB:
|
||||
string fieldList = "";
|
||||
string query = "where id = " + Id;
|
||||
string EndpointString = "";
|
||||
|
||||
switch (Endpoint)
|
||||
{
|
||||
case MetadataEndpoint.AgeRating:
|
||||
fieldList = AgeRatings.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.AgeRating;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.AgeRatingContentDescription:
|
||||
fieldList = AgeRatingContentDescriptions.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.AgeRatingContentDescriptions;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.AlternativeName:
|
||||
fieldList = AlternativeNames.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.AlternativeNames;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Artwork:
|
||||
fieldList = Artworks.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Artworks;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Collection:
|
||||
fieldList = Collections.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Collections;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Company:
|
||||
fieldList = Companies.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Companies;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.CompanyLogo:
|
||||
fieldList = CompanyLogos.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.CompanyLogos;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Cover:
|
||||
fieldList = Covers.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Covers;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.ExternalGame:
|
||||
fieldList = ExternalGames.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.ExternalGames;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Franchise:
|
||||
fieldList = Franchises.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Franchies;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.GameMode:
|
||||
fieldList = GameModes.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.GameModes;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Game:
|
||||
fieldList = Games.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Games;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.GameVideo:
|
||||
fieldList = GamesVideos.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.GameVideos;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Genre:
|
||||
fieldList = Genres.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Genres;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.InvolvedCompany:
|
||||
fieldList = InvolvedCompanies.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.InvolvedCompanies;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.MultiplayerMode:
|
||||
fieldList = MultiplayerModes.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.MultiplayerModes;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.PlatformLogo:
|
||||
fieldList = PlatformLogos.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.PlatformLogos;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Platform:
|
||||
fieldList = Platforms.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Platforms;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.PlatformVersion:
|
||||
fieldList = PlatformVersions.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.PlatformVersions;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.PlayerPerspective:
|
||||
fieldList = PlayerPerspectives.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.PlayerPerspectives;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.ReleaseDate:
|
||||
fieldList = ReleaseDates.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.ReleaseDates;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Screenshot:
|
||||
fieldList = Screenshots.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Screenshots;
|
||||
break;
|
||||
|
||||
case MetadataEndpoint.Theme:
|
||||
fieldList = Themes.fieldList;
|
||||
EndpointString = IGDBClient.Endpoints.Themes;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception("Endpoint must be either Platform or Game");
|
||||
|
||||
}
|
||||
|
||||
return await IGDBAPI<T>(EndpointString, fieldList, query);
|
||||
|
||||
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
||||
return null;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Request data from the metadata API - this is only valid for IGDB
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of object to return</typeparam>
|
||||
/// <param name="Endpoint">API endpoint segment to use</param>
|
||||
@@ -175,6 +434,33 @@ namespace gaseous_server.Classes.Metadata
|
||||
return null;
|
||||
case HasheousClient.Models.MetadataModel.MetadataSources.IGDB:
|
||||
return await IGDBAPI<T>(Endpoint, Fields, Query);
|
||||
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
||||
// configure the Hasheous client
|
||||
hasheous = new HasheousClient.Hasheous();
|
||||
|
||||
// set the base URI
|
||||
string HasheousHost = "";
|
||||
if (Config.MetadataConfiguration.HasheousHost == null)
|
||||
{
|
||||
HasheousHost = "https://hasheous.org/";
|
||||
}
|
||||
else
|
||||
{
|
||||
HasheousHost = Config.MetadataConfiguration.HasheousHost;
|
||||
}
|
||||
|
||||
// set the client API key
|
||||
HasheousClient.WebApp.HttpHelper.ClientKey = Config.MetadataConfiguration.HasheousClientAPIKey;
|
||||
|
||||
// set the client secret
|
||||
if (Config.MetadataConfiguration.HasheousAPIKey != null)
|
||||
{
|
||||
HasheousClient.WebApp.HttpHelper.APIKey = Config.MetadataConfiguration.HasheousAPIKey;
|
||||
}
|
||||
|
||||
// return from Hasheous
|
||||
return await HasheousAPI<T>(Endpoint, Fields, Query);
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -200,7 +486,8 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
|
||||
// perform the actual API call
|
||||
var results = await igdb.QueryAsync<T>(Endpoint, query: Fields + " " + Query + ";");
|
||||
string queryString = Fields + " " + Query + ";";
|
||||
var results = await igdb.QueryAsync<T>(Endpoint, query: queryString);
|
||||
|
||||
// increment rate limiter avoidance call count
|
||||
RateLimitAvoidanceCallCount += 1;
|
||||
@@ -253,6 +540,145 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access the HasheousAPI
|
||||
/// </summary>
|
||||
/// <typeparam name="T">
|
||||
/// The type of object to return
|
||||
/// </typeparam>
|
||||
/// <param name="Endpoint">
|
||||
/// The endpoint to access
|
||||
/// </param>
|
||||
/// <param name="Fields">
|
||||
/// Can be either "slug" or "id" - note not all endpoints support slug
|
||||
/// </param>
|
||||
/// <param name="Query">
|
||||
/// The "slug" or "id" to query for
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The object requested
|
||||
/// </returns>
|
||||
private async Task<T[]> HasheousAPI<T>(string Endpoint, string Fields, string Query)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Debug, "API Connection", "Accessing API for endpoint: " + Endpoint);
|
||||
|
||||
if (RateLimitResumeTime > DateTime.UtcNow)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Information, "API Connection", "IGDB rate limit hit. Pausing API communications until " + RateLimitResumeTime.ToString() + ". Attempt " + RetryAttempts + " of " + RetryAttemptsMax + " retries.");
|
||||
Thread.Sleep(RateLimitRecoveryWaitTime);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (InRateLimitAvoidanceMode == true)
|
||||
{
|
||||
// sleep for a moment to help avoid hitting the rate limiter
|
||||
Logging.Log(Logging.LogType.Information, "API Connection: Endpoint:" + Endpoint, "IGDB rate limit hit. Pausing API communications for " + RateLimitAvoidanceWait + " milliseconds to avoid rate limiter.");
|
||||
Thread.Sleep(RateLimitAvoidanceWait);
|
||||
}
|
||||
|
||||
// perform the actual API call
|
||||
//var results = await igdb.QueryAsync<T>(Endpoint, query: Fields + " " + Query + ";");
|
||||
|
||||
T result1;
|
||||
if (Fields == "slug")
|
||||
{
|
||||
result1 = hasheous.GetMetadataProxy<T>(HasheousClient.Hasheous.MetadataProvider.IGDB, Query);
|
||||
}
|
||||
else if (Fields == "id")
|
||||
{
|
||||
result1 = hasheous.GetMetadataProxy<T>(HasheousClient.Hasheous.MetadataProvider.IGDB, Query);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Fields must be either 'slug' or 'id'");
|
||||
}
|
||||
|
||||
var results1 = new T[] { result1 };
|
||||
|
||||
// increment rate limiter avoidance call count
|
||||
RateLimitAvoidanceCallCount += 1;
|
||||
|
||||
return results1;
|
||||
}
|
||||
catch (ApiException apiEx)
|
||||
{
|
||||
switch (apiEx.StatusCode)
|
||||
{
|
||||
case HttpStatusCode.TooManyRequests:
|
||||
if (RetryAttempts >= RetryAttemptsMax)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "API Connection", "IGDB rate limiter attempts expired. Aborting.", apiEx);
|
||||
throw;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Log(Logging.LogType.Information, "API Connection", "IGDB API rate limit hit while accessing endpoint " + Endpoint, apiEx);
|
||||
|
||||
RetryAttempts += 1;
|
||||
|
||||
T result2;
|
||||
if (Fields == "slug")
|
||||
{
|
||||
result2 = hasheous.GetMetadataProxy<T>(HasheousClient.Hasheous.MetadataProvider.IGDB, Query);
|
||||
}
|
||||
else if (Fields == "id")
|
||||
{
|
||||
result2 = hasheous.GetMetadataProxy<T>(HasheousClient.Hasheous.MetadataProvider.IGDB, Query);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Fields must be either 'slug' or 'id'");
|
||||
}
|
||||
|
||||
var results2 = new T[] { result2 };
|
||||
|
||||
return results2;
|
||||
}
|
||||
|
||||
case HttpStatusCode.Unauthorized:
|
||||
Logging.Log(Logging.LogType.Information, "API Connection", "IGDB API unauthorised error while accessing endpoint " + Endpoint + ". Waiting " + RateLimitAvoidanceWait + " milliseconds and resetting IGDB client.", apiEx);
|
||||
|
||||
Thread.Sleep(RateLimitAvoidanceWait);
|
||||
|
||||
igdb = new IGDBClient(
|
||||
// Found in Twitch Developer portal for your app
|
||||
Config.IGDB.ClientId,
|
||||
Config.IGDB.Secret
|
||||
);
|
||||
|
||||
RetryAttempts += 1;
|
||||
|
||||
T result3;
|
||||
if (Fields == "slug")
|
||||
{
|
||||
result3 = hasheous.GetMetadataProxy<T>(HasheousClient.Hasheous.MetadataProvider.IGDB, Query);
|
||||
}
|
||||
else if (Fields == "id")
|
||||
{
|
||||
result3 = hasheous.GetMetadataProxy<T>(HasheousClient.Hasheous.MetadataProvider.IGDB, Query);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Fields must be either 'slug' or 'id'");
|
||||
}
|
||||
|
||||
var results3 = new T[] { result3 };
|
||||
|
||||
return results3;
|
||||
|
||||
default:
|
||||
Logging.Log(Logging.LogType.Warning, "API Connection", "Exception when accessing endpoint " + Endpoint, apiEx);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "API Connection", "Exception when accessing endpoint " + Endpoint, ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download from the specified uri
|
||||
/// </summary>
|
||||
|
@@ -4,9 +4,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Companies
|
||||
{
|
||||
const string fieldList = "fields change_date,change_date_category,changed_company_id,checksum,country,created_at,description,developed,logo,name,parent,published,slug,start_date,start_date_category,updated_at,url,websites;";
|
||||
public class Companies
|
||||
{
|
||||
public const string fieldList = "fields change_date,change_date_category,changed_company_id,checksum,country,created_at,description,developed,logo,name,parent,published,slug,start_date,start_date_category,updated_at,url,websites;";
|
||||
|
||||
public Companies()
|
||||
{
|
||||
@@ -20,61 +20,33 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Company> RetVal = _GetCompanies(SearchUsing.id, Id);
|
||||
Task<Company> RetVal = _GetCompanies((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Company GetCompanies(string Slug)
|
||||
{
|
||||
Task<Company> RetVal = _GetCompanies(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<Company> _GetCompanies(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<Company> _GetCompanies(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Company", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Company", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("Company", searchValue);
|
||||
|
||||
Company returnValue = new Company();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
if (returnValue != null) { Storage.NewCacheValue(returnValue); }
|
||||
UpdateSubClasses(returnValue);
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<Company>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -96,17 +68,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<Company> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<Company> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get Companies metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Company>(IGDBClient.Endpoints.Companies, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Company>(Communications.MetadataEndpoint.Company, searchValue);
|
||||
if (results.Length > 0)
|
||||
{
|
||||
var result = results.First();
|
||||
@@ -117,7 +83,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class CompanyLogos
|
||||
{
|
||||
const string fieldList = "fields alpha_channel,animated,checksum,height,image_id,url,width;";
|
||||
public const string fieldList = "fields alpha_channel,animated,checksum,height,image_id,url,width;";
|
||||
|
||||
public CompanyLogos()
|
||||
{
|
||||
@@ -21,50 +21,22 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<CompanyLogo> RetVal = _GetCompanyLogo(SearchUsing.id, Id, ImagePath);
|
||||
Task<CompanyLogo> RetVal = _GetCompanyLogo((long)Id, ImagePath);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static CompanyLogo GetCompanyLogo(string Slug, string ImagePath)
|
||||
{
|
||||
Task<CompanyLogo> RetVal = _GetCompanyLogo(SearchUsing.slug, Slug, ImagePath);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<CompanyLogo> _GetCompanyLogo(SearchUsing searchUsing, object searchValue, string ImagePath)
|
||||
private static async Task<CompanyLogo> _GetCompanyLogo(long searchValue, string ImagePath)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("CompanyLogo", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("CompanyLogo", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("CompanyLogo", searchValue);
|
||||
|
||||
CompanyLogo returnValue = new CompanyLogo();
|
||||
bool forceImageDownload = false;
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
if (returnValue != null)
|
||||
{
|
||||
Storage.NewCacheValue(returnValue);
|
||||
@@ -74,7 +46,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
|
||||
// check if old value is different from the new value - only download if it's different
|
||||
@@ -86,7 +58,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<CompanyLogo>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -110,17 +82,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<CompanyLogo> GetObjectFromServer(string WhereClause, string ImagePath)
|
||||
private static async Task<CompanyLogo> GetObjectFromServer(long searchValue, string ImagePath)
|
||||
{
|
||||
// get Artwork metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<CompanyLogo>(IGDBClient.Endpoints.CompanyLogos, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<CompanyLogo>(Communications.MetadataEndpoint.CompanyLogo, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -9,7 +9,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Covers
|
||||
{
|
||||
const string fieldList = "fields alpha_channel,animated,checksum,game,game_localization,height,image_id,url,width;";
|
||||
public const string fieldList = "fields alpha_channel,animated,checksum,game,game_localization,height,image_id,url,width;";
|
||||
|
||||
public Covers()
|
||||
{
|
||||
@@ -23,43 +23,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Cover> RetVal = _GetCover(SearchUsing.id, Id, ImagePath, GetImages);
|
||||
Task<Cover> RetVal = _GetCover((long)Id, ImagePath, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Cover GetCover(string Slug, string ImagePath, bool GetImages)
|
||||
{
|
||||
Task<Cover> RetVal = _GetCover(SearchUsing.slug, Slug, ImagePath, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<Cover> _GetCover(SearchUsing searchUsing, object searchValue, string ImagePath, bool GetImages = true)
|
||||
private static async Task<Cover> _GetCover(long searchValue, string ImagePath, bool GetImages = true)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Cover", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Cover", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("Cover", searchValue);
|
||||
|
||||
Cover returnValue = new Cover();
|
||||
bool forceImageDownload = false;
|
||||
@@ -67,14 +39,14 @@ namespace gaseous_server.Classes.Metadata
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
forceImageDownload = true;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
|
||||
// check if old value is different from the new value - only download if it's different
|
||||
@@ -86,7 +58,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<Cover>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -126,17 +98,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<Cover> GetObjectFromServer(string WhereClause, string ImagePath)
|
||||
private static async Task<Cover> GetObjectFromServer(long searchValue, string ImagePath)
|
||||
{
|
||||
// get Cover metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Cover>(IGDBClient.Endpoints.Covers, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Cover>(Communications.MetadataEndpoint.Cover, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -5,9 +5,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class ExternalGames
|
||||
public class ExternalGames
|
||||
{
|
||||
const string fieldList = "fields category,checksum,countries,created_at,game,media,name,platform,uid,updated_at,url,year;";
|
||||
public const string fieldList = "fields category,checksum,countries,created_at,game,media,name,platform,uid,updated_at,url,year;";
|
||||
|
||||
public ExternalGames()
|
||||
{
|
||||
@@ -21,63 +21,35 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<ExternalGame> RetVal = _GetExternalGames(SearchUsing.id, Id);
|
||||
Task<ExternalGame> RetVal = _GetExternalGames((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static ExternalGame GetExternalGames(string Slug)
|
||||
{
|
||||
Task<ExternalGame> RetVal = _GetExternalGames(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<ExternalGame> _GetExternalGames(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<ExternalGame> _GetExternalGames(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("ExternalGame", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("ExternalGame", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("ExternalGame", searchValue);
|
||||
|
||||
ExternalGame returnValue = new ExternalGame();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
if (returnValue != null)
|
||||
{
|
||||
Storage.NewCacheValue(returnValue);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<ExternalGame>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -91,17 +63,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<ExternalGame?> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<ExternalGame?> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get ExternalGames metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<ExternalGame>(IGDBClient.Endpoints.ExternalGames, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<ExternalGame>(Communications.MetadataEndpoint.ExternalGame, searchValue);
|
||||
if (results.Length > 0)
|
||||
{
|
||||
var result = results.First();
|
||||
@@ -113,6 +79,6 @@ namespace gaseous_server.Classes.Metadata
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5,9 +5,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Franchises
|
||||
public class Franchises
|
||||
{
|
||||
const string fieldList = "fields checksum,created_at,games,name,slug,updated_at,url;";
|
||||
public const string fieldList = "fields checksum,created_at,games,name,slug,updated_at,url;";
|
||||
|
||||
public Franchises()
|
||||
{
|
||||
@@ -21,60 +21,32 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Franchise> RetVal = _GetFranchises(SearchUsing.id, Id);
|
||||
Task<Franchise> RetVal = _GetFranchises((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Franchise GetFranchises(string Slug)
|
||||
{
|
||||
Task<Franchise> RetVal = _GetFranchises(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<Franchise> _GetFranchises(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<Franchise> _GetFranchises(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Franchise", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Franchise", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("Franchise", searchValue);
|
||||
|
||||
Franchise returnValue = new Franchise();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<Franchise>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -88,21 +60,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<Franchise> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<Franchise> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get FranchiseContentDescriptions metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Franchise>(IGDBClient.Endpoints.Franchies, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Franchise>(Communications.MetadataEndpoint.Franchise, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class GameModes
|
||||
{
|
||||
const string fieldList = "fields checksum,created_at,name,slug,updated_at,url;";
|
||||
public const string fieldList = "fields checksum,created_at,name,slug,updated_at,url;";
|
||||
|
||||
public GameModes()
|
||||
{
|
||||
@@ -21,60 +21,32 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<GameMode> RetVal = _GetGame_Modes(SearchUsing.id, Id);
|
||||
Task<GameMode> RetVal = _GetGame_Modes((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static GameMode GetGame_Modes(string Slug)
|
||||
{
|
||||
Task<GameMode> RetVal = _GetGame_Modes(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<GameMode> _GetGame_Modes(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<GameMode> _GetGame_Modes(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("GameMode", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("GameMode", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("GameMode", searchValue);
|
||||
|
||||
GameMode returnValue = new GameMode();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<GameMode>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -88,17 +60,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<GameMode> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<GameMode> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get Game_Modes metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<GameMode>(IGDBClient.Endpoints.GameModes, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<GameMode>(Communications.MetadataEndpoint.GameMode, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -5,9 +5,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class GamesVideos
|
||||
public class GamesVideos
|
||||
{
|
||||
const string fieldList = "fields checksum,game,name,video_id;";
|
||||
public const string fieldList = "fields checksum,game,name,video_id;";
|
||||
|
||||
public GamesVideos()
|
||||
{
|
||||
@@ -21,60 +21,32 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<GameVideo> RetVal = _GetGame_Videos(SearchUsing.id, Id);
|
||||
Task<GameVideo> RetVal = _GetGame_Videos((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static GameVideo GetGame_Videos(string Slug)
|
||||
{
|
||||
Task<GameVideo> RetVal = _GetGame_Videos(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<GameVideo> _GetGame_Videos(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<GameVideo> _GetGame_Videos(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("GameVideo", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("GameVideo", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("GameVideo", searchValue);
|
||||
|
||||
GameVideo returnValue = new GameVideo();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<GameVideo>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -88,21 +60,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<GameVideo> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<GameVideo> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get Game_Videos metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<GameVideo>(IGDBClient.Endpoints.GameVideos, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<GameVideo>(Communications.MetadataEndpoint.GameVideo, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Games
|
||||
{
|
||||
const string fieldList = "fields age_ratings,aggregated_rating,aggregated_rating_count,alternative_names,artworks,bundles,category,checksum,collections,cover,created_at,dlcs,expanded_games,expansions,external_games,first_release_date,follows,forks,franchise,franchises,game_engines,game_localizations,game_modes,genres,hypes,involved_companies,keywords,language_supports,multiplayer_modes,name,parent_game,platforms,player_perspectives,ports,rating,rating_count,release_dates,remakes,remasters,screenshots,similar_games,slug,standalone_expansions,status,storyline,summary,tags,themes,total_rating,total_rating_count,updated_at,url,version_parent,version_title,videos,websites;";
|
||||
public const string fieldList = "fields age_ratings,aggregated_rating,aggregated_rating_count,alternative_names,artworks,bundles,category,checksum,collections,cover,created_at,dlcs,expanded_games,expansions,external_games,first_release_date,follows,forks,franchise,franchises,game_engines,game_localizations,game_modes,genres,hypes,involved_companies,keywords,language_supports,multiplayer_modes,name,parent_game,platforms,player_perspectives,ports,rating,rating_count,release_dates,remakes,remasters,screenshots,similar_games,slug,standalone_expansions,status,storyline,summary,tags,themes,total_rating,total_rating_count,updated_at,url,version_parent,version_title,videos,websites;";
|
||||
|
||||
public Games()
|
||||
{
|
||||
@@ -45,14 +45,14 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Game> RetVal = _GetGame(SearchUsing.id, Id, getAllMetadata, followSubGames, forceRefresh);
|
||||
Task<Game> RetVal = _GetGame(SearchUsing.Id, Id, getAllMetadata, followSubGames, forceRefresh);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Game GetGame(string Slug, bool getAllMetadata, bool followSubGames, bool forceRefresh)
|
||||
{
|
||||
Task<Game> RetVal = _GetGame(SearchUsing.slug, Slug, getAllMetadata, followSubGames, forceRefresh);
|
||||
Task<Game> RetVal = _GetGame(SearchUsing.Slug, Slug, getAllMetadata, followSubGames, forceRefresh);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
if (searchUsing == SearchUsing.Id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Game", (long)searchValue);
|
||||
}
|
||||
@@ -79,45 +79,43 @@ namespace gaseous_server.Classes.Metadata
|
||||
if (cacheStatus == Storage.CacheStatus.Current) { cacheStatus = Storage.CacheStatus.Expired; }
|
||||
}
|
||||
|
||||
string WhereClause = "";
|
||||
string searchField = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
searchField = "id";
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = \"" + searchValue + "\"";
|
||||
searchField = "slug";
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
|
||||
Game returnValue = new Game();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
if (searchUsing == SearchUsing.Id)
|
||||
{
|
||||
returnValue = await GetObjectFromServer((long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = await GetObjectFromServer((string)searchValue);
|
||||
}
|
||||
Storage.NewCacheValue(returnValue);
|
||||
UpdateSubClasses(returnValue, getAllMetadata, followSubGames, forceRefresh);
|
||||
return returnValue;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
if (searchUsing == SearchUsing.Id)
|
||||
{
|
||||
returnValue = await GetObjectFromServer((long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = await GetObjectFromServer((string)searchValue);
|
||||
}
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
UpdateSubClasses(returnValue, getAllMetadata, followSubGames, forceRefresh);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
returnValue = Storage.GetCacheValue<Game>(returnValue, searchField, searchValue);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id/Slug: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<Game>(returnValue, searchUsing.ToString(), searchValue);
|
||||
}
|
||||
return returnValue;
|
||||
case Storage.CacheStatus.Current:
|
||||
returnValue = Storage.GetCacheValue<Game>(returnValue, searchField, searchValue);
|
||||
returnValue = Storage.GetCacheValue<Game>(returnValue, searchUsing.ToString(), searchValue);
|
||||
UpdateSubClasses(returnValue, false, false, false);
|
||||
return returnValue;
|
||||
default:
|
||||
@@ -309,17 +307,36 @@ namespace gaseous_server.Classes.Metadata
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
Id,
|
||||
Slug
|
||||
}
|
||||
|
||||
private static async Task<Game> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<Game> GetObjectFromServer(string Slug)
|
||||
{
|
||||
// get Game metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Game>(IGDBClient.Endpoints.Games, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Game>(Communications.MetadataEndpoint.Game, Slug);
|
||||
var result = results.First();
|
||||
|
||||
result = MassageResult(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static async Task<Game> GetObjectFromServer(long Id)
|
||||
{
|
||||
// get Game metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Game>(Communications.MetadataEndpoint.Game, Id);
|
||||
var result = results.First();
|
||||
|
||||
result = MassageResult(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Game MassageResult(Game result)
|
||||
{
|
||||
// add artificial unknown platform mapping
|
||||
List<long> platformIds = new List<long>();
|
||||
platformIds.Add(0);
|
||||
|
@@ -7,7 +7,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Genres
|
||||
{
|
||||
const string fieldList = "fields checksum,created_at,name,slug,updated_at,url;";
|
||||
public const string fieldList = "fields checksum,created_at,name,slug,updated_at,url;";
|
||||
|
||||
public Genres()
|
||||
{
|
||||
@@ -21,60 +21,32 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Genre> RetVal = _GetGenres(SearchUsing.id, Id);
|
||||
Task<Genre> RetVal = _GetGenres((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Genre GetGenres(string Slug)
|
||||
{
|
||||
Task<Genre> RetVal = _GetGenres(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<Genre> _GetGenres(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<Genre> _GetGenres(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Genre", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Genre", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("Genre", searchValue);
|
||||
|
||||
Genre returnValue = new Genre();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<Genre>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -88,17 +60,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<Genre> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<Genre> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get Genres metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Genre>(IGDBClient.Endpoints.Genres, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Genre>(Communications.MetadataEndpoint.Genre, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -4,9 +4,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class InvolvedCompanies
|
||||
{
|
||||
const string fieldList = "fields *;";
|
||||
public class InvolvedCompanies
|
||||
{
|
||||
public const string fieldList = "fields *;";
|
||||
|
||||
public InvolvedCompanies()
|
||||
{
|
||||
@@ -20,61 +20,33 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<InvolvedCompany> RetVal = _GetInvolvedCompanies(SearchUsing.id, Id);
|
||||
Task<InvolvedCompany> RetVal = _GetInvolvedCompanies((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static InvolvedCompany GetInvolvedCompanies(string Slug)
|
||||
{
|
||||
Task<InvolvedCompany> RetVal = _GetInvolvedCompanies(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<InvolvedCompany> _GetInvolvedCompanies(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<InvolvedCompany> _GetInvolvedCompanies(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("InvolvedCompany", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("InvolvedCompany", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("InvolvedCompany", searchValue);
|
||||
|
||||
InvolvedCompany returnValue = new InvolvedCompany();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
UpdateSubClasses(returnValue);
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<InvolvedCompany>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -96,31 +68,14 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
private static async Task<InvolvedCompany> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
// get Genres metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<InvolvedCompany>(Communications.MetadataEndpoint.InvolvedCompany, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
private static async Task<InvolvedCompany> GetObjectFromServer(string WhereClause)
|
||||
{
|
||||
// get InvolvedCompanies metadata
|
||||
try
|
||||
{
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<InvolvedCompany>(IGDBClient.Endpoints.InvolvedCompanies, fieldList, WhereClause);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Critical, "Involved Companies", "Failure when requesting involved companies.");
|
||||
Logging.Log(Logging.LogType.Critical, "Involved Companies", "Field list: " + fieldList);
|
||||
Logging.Log(Logging.LogType.Critical, "Involved Companies", "Where clause: " + WhereClause);
|
||||
Logging.Log(Logging.LogType.Critical, "Involved Companies", "Error", ex);
|
||||
throw;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class MultiplayerModes
|
||||
{
|
||||
const string fieldList = "fields campaigncoop,checksum,dropin,game,lancoop,offlinecoop,offlinecoopmax,offlinemax,onlinecoop,onlinecoopmax,onlinemax,platform,splitscreen,splitscreenonline;";
|
||||
public const string fieldList = "fields campaigncoop,checksum,dropin,game,lancoop,offlinecoop,offlinecoopmax,offlinemax,onlinecoop,onlinecoopmax,onlinemax,platform,splitscreen,splitscreenonline;";
|
||||
|
||||
public MultiplayerModes()
|
||||
{
|
||||
@@ -21,60 +21,32 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<MultiplayerMode> RetVal = _GetGame_MultiplayerModes(SearchUsing.id, Id);
|
||||
Task<MultiplayerMode> RetVal = _GetGame_MultiplayerModes((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static MultiplayerMode GetGame_MultiplayerModes(string Slug)
|
||||
{
|
||||
Task<MultiplayerMode> RetVal = _GetGame_MultiplayerModes(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<MultiplayerMode> _GetGame_MultiplayerModes(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<MultiplayerMode> _GetGame_MultiplayerModes(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("MultiplayerMode", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("MultiplayerMode", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("MultiplayerMode", searchValue);
|
||||
|
||||
MultiplayerMode returnValue = new MultiplayerMode();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<MultiplayerMode>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -88,17 +60,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<MultiplayerMode> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<MultiplayerMode> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get Game_MultiplayerModes metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<MultiplayerMode>(IGDBClient.Endpoints.MultiplayerModes, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<MultiplayerMode>(Communications.MetadataEndpoint.MultiplayerMode, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -5,9 +5,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class PlatformLogos
|
||||
public class PlatformLogos
|
||||
{
|
||||
const string fieldList = "fields alpha_channel,animated,checksum,height,image_id,url,width;";
|
||||
public const string fieldList = "fields alpha_channel,animated,checksum,height,image_id,url,width;";
|
||||
|
||||
public PlatformLogos()
|
||||
{
|
||||
@@ -21,62 +21,34 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<PlatformLogo> RetVal = _GetPlatformLogo(SearchUsing.id, Id, ImagePath);
|
||||
Task<PlatformLogo> RetVal = _GetPlatformLogo((long)Id, ImagePath);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static PlatformLogo GetPlatformLogo(string Slug, string ImagePath)
|
||||
{
|
||||
Task<PlatformLogo> RetVal = _GetPlatformLogo(SearchUsing.slug, Slug, ImagePath);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<PlatformLogo> _GetPlatformLogo(SearchUsing searchUsing, object searchValue, string ImagePath)
|
||||
private static async Task<PlatformLogo> _GetPlatformLogo(long searchValue, string ImagePath)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("PlatformLogo", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("PlatformLogo", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("PlatformLogo", searchValue);
|
||||
|
||||
PlatformLogo returnValue = new PlatformLogo();
|
||||
bool forceImageDownload = false;
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
if (returnValue != null)
|
||||
{
|
||||
Storage.NewCacheValue(returnValue);
|
||||
forceImageDownload = true;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
|
||||
|
||||
// check if old value is different from the new value - only download if it's different
|
||||
PlatformLogo oldImage = Storage.GetCacheValue<PlatformLogo>(returnValue, "id", (long)searchValue);
|
||||
if (oldImage.ImageId != returnValue.ImageId)
|
||||
@@ -86,10 +58,10 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<PlatformLogo>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Current:
|
||||
returnValue = Storage.GetCacheValue<PlatformLogo>(returnValue, "id", (long)searchValue);
|
||||
break;
|
||||
@@ -113,21 +85,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<PlatformLogo> GetObjectFromServer(string WhereClause, string ImagePath)
|
||||
private static async Task<PlatformLogo> GetObjectFromServer(long searchValue, string ImagePath)
|
||||
{
|
||||
// get Artwork metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<PlatformLogo>(IGDBClient.Endpoints.PlatformLogos, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<PlatformLogo>(Communications.MetadataEndpoint.PlatformLogo, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class PlatformVersions
|
||||
{
|
||||
const string fieldList = "fields checksum,companies,connectivity,cpu,graphics,main_manufacturer,media,memory,name,online,os,output,platform_logo,platform_version_release_dates,resolutions,slug,sound,storage,summary,url;";
|
||||
public const string fieldList = "fields checksum,companies,connectivity,cpu,graphics,main_manufacturer,media,memory,name,online,os,output,platform_logo,platform_version_release_dates,resolutions,slug,sound,storage,summary,url;";
|
||||
|
||||
public PlatformVersions()
|
||||
{
|
||||
@@ -21,49 +21,21 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<PlatformVersion> RetVal = _GetPlatformVersion(SearchUsing.id, Id, ParentPlatform, GetImages);
|
||||
Task<PlatformVersion> RetVal = _GetPlatformVersion((long)Id, ParentPlatform, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static PlatformVersion GetPlatformVersion(string Slug, Platform ParentPlatform, bool GetImages = false)
|
||||
{
|
||||
Task<PlatformVersion> RetVal = _GetPlatformVersion(SearchUsing.slug, Slug, ParentPlatform, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<PlatformVersion> _GetPlatformVersion(SearchUsing searchUsing, object searchValue, Platform ParentPlatform, bool GetImages)
|
||||
private static async Task<PlatformVersion> _GetPlatformVersion(long searchValue, Platform ParentPlatform, bool GetImages)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("PlatformVersion", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("PlatformVersion", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("PlatformVersion", searchValue);
|
||||
|
||||
PlatformVersion returnValue = new PlatformVersion();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
if (returnValue != null)
|
||||
{
|
||||
Storage.NewCacheValue(returnValue);
|
||||
@@ -73,13 +45,13 @@ namespace gaseous_server.Classes.Metadata
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
UpdateSubClasses(ParentPlatform, returnValue, GetImages);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<PlatformVersion>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
return returnValue;
|
||||
@@ -108,17 +80,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<PlatformVersion?> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<PlatformVersion?> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get PlatformVersion metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<PlatformVersion>(IGDBClient.Endpoints.PlatformVersions, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<PlatformVersion>(Communications.MetadataEndpoint.PlatformVersion, searchValue);
|
||||
if (results.Length > 0)
|
||||
{
|
||||
var result = results.First();
|
||||
|
@@ -8,7 +8,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Platforms
|
||||
{
|
||||
const string fieldList = "fields abbreviation,alternative_name,category,checksum,created_at,generation,name,platform_family,platform_logo,slug,summary,updated_at,url,versions,websites;";
|
||||
public const string fieldList = "fields abbreviation,alternative_name,category,checksum,created_at,generation,name,platform_family,platform_logo,slug,summary,updated_at,url,versions,websites;";
|
||||
|
||||
public Platforms()
|
||||
{
|
||||
@@ -41,7 +41,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
try
|
||||
{
|
||||
Task<Platform> RetVal = _GetPlatform(SearchUsing.id, Id, forceRefresh, GetImages);
|
||||
Task<Platform> RetVal = _GetPlatform(SearchUsing.Id, Id, forceRefresh, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -54,7 +54,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
|
||||
public static Platform GetPlatform(string Slug, bool forceRefresh = false, bool GetImages = false)
|
||||
{
|
||||
Task<Platform> RetVal = _GetPlatform(SearchUsing.slug, Slug, forceRefresh, GetImages);
|
||||
Task<Platform> RetVal = _GetPlatform(SearchUsing.Slug, Slug, forceRefresh, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
if (searchUsing == SearchUsing.Id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Platform", (long)searchValue);
|
||||
}
|
||||
@@ -76,28 +76,18 @@ namespace gaseous_server.Classes.Metadata
|
||||
if (cacheStatus == Storage.CacheStatus.Current) { cacheStatus = Storage.CacheStatus.Expired; }
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
string searchField = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
searchField = "id";
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = \"" + searchValue + "\"";
|
||||
searchField = "slug";
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
|
||||
Platform returnValue = new Platform();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
if (searchUsing == SearchUsing.Id)
|
||||
{
|
||||
returnValue = await GetObjectFromServer((long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = await GetObjectFromServer((string)searchValue);
|
||||
}
|
||||
Storage.NewCacheValue(returnValue);
|
||||
UpdateSubClasses(returnValue, GetImages);
|
||||
AddPlatformMapping(returnValue);
|
||||
@@ -105,7 +95,14 @@ namespace gaseous_server.Classes.Metadata
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
if (searchUsing == SearchUsing.Id)
|
||||
{
|
||||
returnValue = await GetObjectFromServer((long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = await GetObjectFromServer((string)searchValue);
|
||||
}
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
UpdateSubClasses(returnValue, GetImages);
|
||||
AddPlatformMapping(returnValue);
|
||||
@@ -113,11 +110,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
return Storage.GetCacheValue<Platform>(returnValue, searchField, searchValue);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id/Slug: " + searchValue, ex);
|
||||
return Storage.GetCacheValue<Platform>(returnValue, searchUsing.ToString(), searchValue);
|
||||
}
|
||||
case Storage.CacheStatus.Current:
|
||||
return Storage.GetCacheValue<Platform>(returnValue, searchField, searchValue);
|
||||
return Storage.GetCacheValue<Platform>(returnValue, searchUsing.ToString(), searchValue);
|
||||
default:
|
||||
throw new Exception("How did you get here?");
|
||||
}
|
||||
@@ -177,15 +174,25 @@ namespace gaseous_server.Classes.Metadata
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
Id,
|
||||
Slug
|
||||
}
|
||||
|
||||
private static async Task<Platform> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<Platform> GetObjectFromServer(string Slug)
|
||||
{
|
||||
// get platform metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Platform>(IGDBClient.Endpoints.Platforms, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Platform>(Communications.MetadataEndpoint.Platform, Slug);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static async Task<Platform> GetObjectFromServer(long Id)
|
||||
{
|
||||
// get platform metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Platform>(Communications.MetadataEndpoint.Platform, Id);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -7,7 +7,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class PlayerPerspectives
|
||||
{
|
||||
const string fieldList = "fields checksum,created_at,name,slug,updated_at,url;";
|
||||
public const string fieldList = "fields checksum,created_at,name,slug,updated_at,url;";
|
||||
|
||||
public PlayerPerspectives()
|
||||
{
|
||||
@@ -21,62 +21,34 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<PlayerPerspective> RetVal = _GetGame_PlayerPerspectives(SearchUsing.id, Id);
|
||||
Task<PlayerPerspective> RetVal = _GetGame_PlayerPerspectives((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static PlayerPerspective GetGame_PlayerPerspectives(string Slug)
|
||||
{
|
||||
Task<PlayerPerspective> RetVal = _GetGame_PlayerPerspectives(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<PlayerPerspective> _GetGame_PlayerPerspectives(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<PlayerPerspective> _GetGame_PlayerPerspectives(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("PlayerPerspective", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("PlayerPerspective", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("PlayerPerspective", searchValue);
|
||||
|
||||
PlayerPerspective returnValue = new PlayerPerspective();
|
||||
bool forceImageDownload = false;
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
forceImageDownload = true;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<PlayerPerspective>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -90,17 +62,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<PlayerPerspective> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<PlayerPerspective> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get Game_PlayerPerspectives metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<PlayerPerspective>(IGDBClient.Endpoints.PlayerPerspectives, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<PlayerPerspective>(Communications.MetadataEndpoint.PlayerPerspective, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -5,9 +5,9 @@ using IGDB.Models;
|
||||
|
||||
namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class ReleaseDates
|
||||
public class ReleaseDates
|
||||
{
|
||||
const string fieldList = "fields category,checksum,created_at,date,game,human,m,platform,region,status,updated_at,y;";
|
||||
public const string fieldList = "fields category,checksum,created_at,date,game,human,m,platform,region,status,updated_at,y;";
|
||||
|
||||
public ReleaseDates()
|
||||
{
|
||||
@@ -21,60 +21,32 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<ReleaseDate> RetVal = _GetReleaseDates(SearchUsing.id, Id);
|
||||
Task<ReleaseDate> RetVal = _GetReleaseDates((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static ReleaseDate GetReleaseDates(string Slug)
|
||||
{
|
||||
Task<ReleaseDate> RetVal = _GetReleaseDates(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<ReleaseDate> _GetReleaseDates(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<ReleaseDate> _GetReleaseDates(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("ReleaseDate", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("ReleaseDate", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("ReleaseDate", searchValue);
|
||||
|
||||
ReleaseDate returnValue = new ReleaseDate();
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
break;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<ReleaseDate>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -88,21 +60,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<ReleaseDate> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<ReleaseDate> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get ReleaseDates metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<ReleaseDate>(IGDBClient.Endpoints.ReleaseDates, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<ReleaseDate>(Communications.MetadataEndpoint.ReleaseDate, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Screenshots
|
||||
{
|
||||
const string fieldList = "fields alpha_channel,animated,checksum,game,height,image_id,url,width;";
|
||||
public const string fieldList = "fields alpha_channel,animated,checksum,game,height,image_id,url,width;";
|
||||
|
||||
public Screenshots()
|
||||
{
|
||||
@@ -21,43 +21,15 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Screenshot> RetVal = _GetScreenshot(SearchUsing.id, Id, ImagePath, GetImages);
|
||||
Task<Screenshot> RetVal = _GetScreenshot((long)Id, ImagePath, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Screenshot GetScreenshot(string Slug, string ImagePath, bool GetImages)
|
||||
{
|
||||
Task<Screenshot> RetVal = _GetScreenshot(SearchUsing.slug, Slug, ImagePath, GetImages);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<Screenshot> _GetScreenshot(SearchUsing searchUsing, object searchValue, string ImagePath, bool GetImages = true)
|
||||
private static async Task<Screenshot> _GetScreenshot(long searchValue, string ImagePath, bool GetImages = true)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Screenshot", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Screenshot", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("Screenshot", searchValue);
|
||||
|
||||
Screenshot returnValue = new Screenshot();
|
||||
bool forceImageDownload = false;
|
||||
@@ -65,14 +37,14 @@ namespace gaseous_server.Classes.Metadata
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
forceImageDownload = true;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause, ImagePath);
|
||||
returnValue = await GetObjectFromServer(searchValue, ImagePath);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
|
||||
// check if old value is different from the new value - only download if it's different
|
||||
@@ -84,7 +56,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
returnValue = Storage.GetCacheValue<Screenshot>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
break;
|
||||
@@ -111,17 +83,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<Screenshot> GetObjectFromServer(string WhereClause, string ImagePath)
|
||||
private static async Task<Screenshot> GetObjectFromServer(long searchValue, string ImagePath)
|
||||
{
|
||||
// get Screenshot metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Screenshot>(IGDBClient.Endpoints.Screenshots, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Screenshot>(Communications.MetadataEndpoint.Screenshot, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -7,7 +7,7 @@ namespace gaseous_server.Classes.Metadata
|
||||
{
|
||||
public class Themes
|
||||
{
|
||||
const string fieldList = "fields checksum,created_at,name,slug,updated_at,url;";
|
||||
public const string fieldList = "fields checksum,created_at,name,slug,updated_at,url;";
|
||||
|
||||
public Themes()
|
||||
{
|
||||
@@ -21,63 +21,35 @@ namespace gaseous_server.Classes.Metadata
|
||||
}
|
||||
else
|
||||
{
|
||||
Task<Theme> RetVal = _GetGame_Themes(SearchUsing.id, Id);
|
||||
Task<Theme> RetVal = _GetGame_Themes((long)Id);
|
||||
return RetVal.Result;
|
||||
}
|
||||
}
|
||||
|
||||
public static Theme GetGame_Themes(string Slug)
|
||||
{
|
||||
Task<Theme> RetVal = _GetGame_Themes(SearchUsing.slug, Slug);
|
||||
return RetVal.Result;
|
||||
}
|
||||
|
||||
private static async Task<Theme> _GetGame_Themes(SearchUsing searchUsing, object searchValue)
|
||||
private static async Task<Theme> _GetGame_Themes(long searchValue)
|
||||
{
|
||||
// check database first
|
||||
Storage.CacheStatus? cacheStatus = new Storage.CacheStatus();
|
||||
if (searchUsing == SearchUsing.id)
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Theme", (long)searchValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
cacheStatus = Storage.GetCacheStatus("Theme", (string)searchValue);
|
||||
}
|
||||
|
||||
// set up where clause
|
||||
string WhereClause = "";
|
||||
switch (searchUsing)
|
||||
{
|
||||
case SearchUsing.id:
|
||||
WhereClause = "where id = " + searchValue;
|
||||
break;
|
||||
case SearchUsing.slug:
|
||||
WhereClause = "where slug = " + searchValue;
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid search type");
|
||||
}
|
||||
Storage.CacheStatus? cacheStatus = Storage.GetCacheStatus("Theme", searchValue);
|
||||
|
||||
Theme returnValue = new Theme();
|
||||
bool forceImageDownload = false;
|
||||
switch (cacheStatus)
|
||||
{
|
||||
case Storage.CacheStatus.NotPresent:
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue);
|
||||
forceImageDownload = true;
|
||||
break;
|
||||
case Storage.CacheStatus.Expired:
|
||||
try
|
||||
{
|
||||
returnValue = await GetObjectFromServer(WhereClause);
|
||||
returnValue = await GetObjectFromServer(searchValue);
|
||||
Storage.NewCacheValue(returnValue, true);
|
||||
return returnValue;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. WhereClause: " + WhereClause, ex);
|
||||
Logging.Log(Logging.LogType.Warning, "Metadata: " + returnValue.GetType().Name, "An error occurred while connecting to IGDB. Id: " + searchValue, ex);
|
||||
return Storage.GetCacheValue<Theme>(returnValue, "id", (long)searchValue);
|
||||
}
|
||||
case Storage.CacheStatus.Current:
|
||||
@@ -90,17 +62,11 @@ namespace gaseous_server.Classes.Metadata
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private enum SearchUsing
|
||||
{
|
||||
id,
|
||||
slug
|
||||
}
|
||||
|
||||
private static async Task<Theme> GetObjectFromServer(string WhereClause)
|
||||
private static async Task<Theme> GetObjectFromServer(long searchValue)
|
||||
{
|
||||
// get Game_Themes metadata
|
||||
Communications comms = new Communications();
|
||||
var results = await comms.APIComm<Theme>(IGDBClient.Endpoints.Themes, fieldList, WhereClause);
|
||||
var results = await comms.APIComm<Theme>(Communications.MetadataEndpoint.Theme, searchValue);
|
||||
var result = results.First();
|
||||
|
||||
return result;
|
||||
|
@@ -202,7 +202,8 @@ namespace gaseous_server.Classes
|
||||
}
|
||||
}
|
||||
|
||||
HasheousClient.WebApp.HttpHelper.AddHeader("X-API-Key", Config.MetadataConfiguration.HasheousAPIKey);
|
||||
HasheousClient.WebApp.HttpHelper.APIKey = Config.MetadataConfiguration.HasheousAPIKey;
|
||||
HasheousClient.WebApp.HttpHelper.ClientKey = Config.MetadataConfiguration.HasheousClientAPIKey;
|
||||
HasheousClient.Hasheous hasheousClient = new HasheousClient.Hasheous();
|
||||
List<MetadataMatch> metadataMatchList = new List<MetadataMatch>();
|
||||
metadataMatchList.Add(new MetadataMatch(HasheousClient.Models.MetadataSources.IGDB, platform.Slug, game.Slug));
|
||||
|
@@ -73,6 +73,7 @@ namespace gaseous_server.Controllers
|
||||
[HttpGet]
|
||||
[Route("Version")]
|
||||
[ProducesResponseType(typeof(Dictionary<string, object>), StatusCodes.Status200OK)]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetSystemVersion()
|
||||
{
|
||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
|
@@ -20,7 +20,7 @@
|
||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||
<PackageReference Include="gaseous-signature-parser" Version="2.2.1" />
|
||||
<PackageReference Include="gaseous.IGDB" Version="1.0.2" />
|
||||
<PackageReference Include="hasheous-client" Version="1.0.4.4" />
|
||||
<PackageReference Include="hasheous-client" Version="1.1.0" />
|
||||
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="13.8.0" />
|
||||
<PackageReference Include="sharpcompress" Version="0.37.2" />
|
||||
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.2.24" />
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<div id="gamepage">
|
||||
<div style="padding-top: 20px;">
|
||||
<div id="gamehome" style="display: inline-block; max-width: 820px; margin-right: 20px; vertical-align: top;">
|
||||
<div id="gamehome"
|
||||
style="display: inline-block; max-width: 820px; margin-right: 20px; vertical-align: top; width: 100%;">
|
||||
|
||||
</div>
|
||||
<div id="gameprofile" style="display: inline-block; width: 250px;">
|
||||
|
Reference in New Issue
Block a user