WIP - All server communications can now use Hasheous
This commit is contained in:
@@ -256,7 +256,7 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
return await IGDBAPI<T>(EndpointString, fieldList, query);
|
return await IGDBAPI<T>(EndpointString, fieldList, query);
|
||||||
|
|
||||||
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
||||||
ConfigureHasheousClient();
|
ConfigureHasheousClient(ref hasheous);
|
||||||
|
|
||||||
return await HasheousAPI<T>(Endpoint.ToString(), "slug", Slug);
|
return await HasheousAPI<T>(Endpoint.ToString(), "slug", Slug);
|
||||||
|
|
||||||
@@ -416,7 +416,7 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
return await IGDBAPI<T>(EndpointString, fieldList, query);
|
return await IGDBAPI<T>(EndpointString, fieldList, query);
|
||||||
|
|
||||||
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
||||||
ConfigureHasheousClient();
|
ConfigureHasheousClient(ref hasheous);
|
||||||
|
|
||||||
return await HasheousAPI<T>(Endpoint.ToString(), "id", Id.ToString());
|
return await HasheousAPI<T>(Endpoint.ToString(), "id", Id.ToString());
|
||||||
default:
|
default:
|
||||||
@@ -424,7 +424,7 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConfigureHasheousClient()
|
public static void ConfigureHasheousClient(ref HasheousClient.Hasheous hasheous)
|
||||||
{
|
{
|
||||||
// configure the Hasheous client
|
// configure the Hasheous client
|
||||||
hasheous = new HasheousClient.Hasheous();
|
hasheous = new HasheousClient.Hasheous();
|
||||||
@@ -853,7 +853,7 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
/// <typeparam name="T">The type of object to convert to</typeparam>
|
/// <typeparam name="T">The type of object to convert to</typeparam>
|
||||||
/// <param name="input">The object to convert</param>
|
/// <param name="input">The object to convert</param>
|
||||||
/// <returns>The converted object</returns>
|
/// <returns>The converted object</returns>
|
||||||
public T ConvertToIGDBModel<T>(object input)
|
public static T ConvertToIGDBModel<T>(object input)
|
||||||
{
|
{
|
||||||
// loop through the properties of intput and copy all strings to an output object of type T
|
// loop through the properties of intput and copy all strings to an output object of type T
|
||||||
|
|
||||||
@@ -978,7 +978,7 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
|
|
||||||
private async Task<bool?> _DownloadFile(Uri uri, string DestinationFile)
|
private async Task<bool?> _DownloadFile(Uri uri, string DestinationFile)
|
||||||
{
|
{
|
||||||
ConfigureHasheousClient();
|
ConfigureHasheousClient(ref hasheous);
|
||||||
|
|
||||||
string DestinationDirectory = new FileInfo(DestinationFile).Directory.FullName;
|
string DestinationDirectory = new FileInfo(DestinationFile).Directory.FullName;
|
||||||
if (!Directory.Exists(DestinationDirectory))
|
if (!Directory.Exists(DestinationDirectory))
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using gaseous_server.Models;
|
using gaseous_server.Models;
|
||||||
using IGDB;
|
using IGDB;
|
||||||
using IGDB.Models;
|
using IGDB.Models;
|
||||||
@@ -527,7 +528,16 @@ namespace gaseous_server.Classes.Metadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
||||||
return new Game[0];
|
HasheousClient.Hasheous hasheous = new HasheousClient.Hasheous();
|
||||||
|
HasheousClient.Models.Metadata.IGDB.Game[] hResults = hasheous.GetMetadataProxy_SearchGame<HasheousClient.Models.Metadata.IGDB.Game>(HasheousClient.Hasheous.MetadataProvider.IGDB, PlatformId.ToString(), SearchString);
|
||||||
|
|
||||||
|
List<Game> hGames = new List<Game>();
|
||||||
|
foreach (HasheousClient.Models.Metadata.IGDB.Game hResult in hResults)
|
||||||
|
{
|
||||||
|
hGames.Add(Communications.ConvertToIGDBModel<Game>(hResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
return hGames.ToArray();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return new Game[0];
|
return new Game[0];
|
||||||
|
@@ -36,27 +36,20 @@ namespace gaseous_server.Controllers
|
|||||||
|
|
||||||
private static async Task<List<Platform>> _SearchForPlatform(string SearchString)
|
private static async Task<List<Platform>> _SearchForPlatform(string SearchString)
|
||||||
{
|
{
|
||||||
string searchBody = "";
|
// search the database for the requested platforms
|
||||||
string searchFields = "fields abbreviation,alternative_name,category,checksum,created_at,generation,name,platform_family,platform_logo,slug,summary,updated_at,url,versions,websites; ";
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
searchBody += "where name ~ *\"" + SearchString + "\"*;";
|
string query = "SELECT `Id` FROM Platform WHERE `Name` LIKE '%" + SearchString + "%';";
|
||||||
|
DataTable data = db.ExecuteCMD(query);
|
||||||
|
|
||||||
List<Platform>? searchCache = Communications.GetSearchCache<List<Platform>>(searchFields, searchBody);
|
List<Platform> platforms = new List<Platform>();
|
||||||
|
foreach (DataRow row in data.Rows)
|
||||||
if (searchCache == null)
|
|
||||||
{
|
{
|
||||||
// cache miss
|
Platform platform = Platforms.GetPlatform((long)row["Id"], false, false);
|
||||||
// get Platform metadata from data source
|
|
||||||
Communications comms = new Communications();
|
|
||||||
var results = await comms.APIComm<Platform>(IGDBClient.Endpoints.Platforms, searchFields, searchBody);
|
|
||||||
|
|
||||||
Communications.SetSearchCache<List<Platform>>(searchFields, searchBody, results.ToList());
|
platforms.Add(platform);
|
||||||
|
}
|
||||||
|
|
||||||
return results.ToList();
|
return platforms;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return searchCache;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MapToApiVersion("1.0")]
|
[MapToApiVersion("1.0")]
|
||||||
@@ -72,6 +65,9 @@ namespace gaseous_server.Controllers
|
|||||||
|
|
||||||
private static async Task<List<GaseousGame>> _SearchForGame(long PlatformId, string SearchString)
|
private static async Task<List<GaseousGame>> _SearchForGame(long PlatformId, string SearchString)
|
||||||
{
|
{
|
||||||
|
switch (Communications.MetadataSource)
|
||||||
|
{
|
||||||
|
case HasheousClient.Models.MetadataModel.MetadataSources.IGDB:
|
||||||
string searchBody = "";
|
string searchBody = "";
|
||||||
string searchFields = "fields *; ";
|
string searchFields = "fields *; ";
|
||||||
searchBody += "search \"" + SearchString + "\";";
|
searchBody += "search \"" + SearchString + "\";";
|
||||||
@@ -123,6 +119,24 @@ namespace gaseous_server.Controllers
|
|||||||
|
|
||||||
return gamesToReturn;
|
return gamesToReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case HasheousClient.Models.MetadataModel.MetadataSources.Hasheous:
|
||||||
|
HasheousClient.Hasheous hasheous = new HasheousClient.Hasheous();
|
||||||
|
Communications.ConfigureHasheousClient(ref hasheous);
|
||||||
|
List<HasheousClient.Models.Metadata.IGDB.Game> hSearch = hasheous.GetMetadataProxy_SearchGame<HasheousClient.Models.Metadata.IGDB.Game>(HasheousClient.Hasheous.MetadataProvider.IGDB, PlatformId.ToString(), SearchString).ToList<HasheousClient.Models.Metadata.IGDB.Game>();
|
||||||
|
|
||||||
|
List<GaseousGame> hGamesToReturn = new List<GaseousGame>();
|
||||||
|
foreach (HasheousClient.Models.Metadata.IGDB.Game game in hSearch)
|
||||||
|
{
|
||||||
|
IGDB.Models.Game tempGame = Communications.ConvertToIGDBModel<IGDB.Models.Game>(game);
|
||||||
|
hGamesToReturn.Add(new GaseousGame(tempGame));
|
||||||
|
}
|
||||||
|
|
||||||
|
return hGamesToReturn;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return new List<GaseousGame>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@
|
|||||||
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
|
||||||
<PackageReference Include="gaseous-signature-parser" Version="2.2.1" />
|
<PackageReference Include="gaseous-signature-parser" Version="2.2.1" />
|
||||||
<PackageReference Include="gaseous.IGDB" Version="1.0.2" />
|
<PackageReference Include="gaseous.IGDB" Version="1.0.2" />
|
||||||
<PackageReference Include="hasheous-client" Version="1.1.2" />
|
<PackageReference Include="hasheous-client" Version="1.1.3" />
|
||||||
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="13.8.0" />
|
<PackageReference Include="Magick.NET-Q8-AnyCPU" Version="13.8.0" />
|
||||||
<PackageReference Include="sharpcompress" Version="0.37.2" />
|
<PackageReference Include="sharpcompress" Version="0.37.2" />
|
||||||
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.2.24" />
|
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.2.24" />
|
||||||
|
Reference in New Issue
Block a user