wabbajack/Wabbajack.Server/DataLayer/ValidationData.cs

59 lines
2.2 KiB
C#
Raw Normal View History

2020-05-14 22:21:56 +00:00
using System;
using System.Collections.Generic;
2020-05-13 21:52:34 +00:00
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Wabbajack.Common;
using Wabbajack.Lib;
using Wabbajack.Lib.ModListRegistry;
using Wabbajack.Server.DTOs;
namespace Wabbajack.Server.DataLayer
{
public partial class SqlService
{
public async Task<ValidationData> GetValidationData()
{
var nexusFiles = AllNexusFiles();
var archiveStatus = AllModListArchivesStatus();
var modLists = AllModLists();
return new ValidationData
{
2020-05-14 22:21:56 +00:00
NexusFiles = new ConcurrentHashSet<(long Game, long ModId, long FileId)>((await nexusFiles).Select(f => (f.NexusGameId, f.ModId, f.FileId))),
2020-05-13 21:52:34 +00:00
ArchiveStatus = await archiveStatus,
ModLists = await modLists,
};
}
public async Task<Dictionary<(string PrimaryKeyString, Hash Hash), bool>> AllModListArchivesStatus()
{
await using var conn = await Open();
var results =
await conn.QueryAsync<(string, Hash, bool)>(
@"SELECT PrimaryKeyString, Hash, IsValid FROM dbo.ModListArchiveStatus");
return results.ToDictionary(v => (v.Item1, v.Item2), v => v.Item3);
}
2020-05-14 22:21:56 +00:00
public async Task<HashSet<(long NexusGameId, long ModId, long FileId, DateTime LastChecked)>> AllNexusFiles()
2020-05-13 21:52:34 +00:00
{
await using var conn = await Open();
2020-05-14 22:21:56 +00:00
var results = await conn.QueryAsync<(long, long, long, DateTime)>(@"SELECT Game, ModId, p.file_id, LastChecked
FROM [NexusModFiles] files
CROSS APPLY
OPENJSON(Data, '$.files') WITH (file_id bigint '$.file_id', category varchar(max) '$.category_name') p
WHERE p.category is not null
UNION
SELECT GameId, ModId, FileId, LastChecked FROM dbo.NexusModFilesSlow
");
2020-05-13 21:52:34 +00:00
return results.ToHashSet();
}
2020-07-15 22:29:43 +00:00
public async Task<List<ModlistMetadata>> AllModLists()
2020-05-13 21:52:34 +00:00
{
await using var conn = await Open();
2020-07-15 22:29:43 +00:00
var results = await conn.QueryAsync<ModlistMetadata>(@"SELECT Metadata FROM dbo.ModLists");
return results.ToList();
2020-05-13 21:52:34 +00:00
}
}
}