WIP, thinking about converting to EF
This commit is contained in:
@@ -4,15 +4,14 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using fxl.codes.kisekae.Entities;
|
||||
using fxl.codes.kisekae.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace fxl.codes.kisekae.Services
|
||||
{
|
||||
public class ConfigurationReaderService
|
||||
{
|
||||
private const string CelRegex = @"#(?<Group>\d*)\.?(?<Fix>\d*)\s*(?<FileName>[\w\d\-]*\.[cCeElL]*)\s*\*?"
|
||||
+ @"(?<PaletteId>\d*)?\s*\:?(?<Sets>[\d\s]*)?;?(?<Comment>[\w\d\-\s\%]*)";
|
||||
private const string CelRegex = @"#(?<Mark>\d*)\.?(?<Fix>\d*)\s*(?<FileName>[\w\d\-]*\.[cCeElL]*)\s*\*?"
|
||||
+ @"(?<PaletteIndex>\d*)?\s*\:?(?<Sets>[\d\s]*)?;?(?<Comment>[\w\d\-\s\%]*)";
|
||||
|
||||
private const string ResolutionRegexPattern = @"\((?<Width>[0-9]*).(?<Height>[0-9]*)\)";
|
||||
|
||||
@@ -79,7 +78,7 @@ namespace fxl.codes.kisekae.Services
|
||||
{
|
||||
match.Groups.TryGetValue(groupName, out var group);
|
||||
if (string.IsNullOrEmpty(group?.Value)) continue;
|
||||
|
||||
|
||||
if (string.Equals(groupName, "FileName"))
|
||||
{
|
||||
cel.CelId = cels[group.Value.ToLowerInvariant()].Id;
|
||||
@@ -124,13 +123,16 @@ namespace fxl.codes.kisekae.Services
|
||||
foreach (var set in sets)
|
||||
{
|
||||
var value = set.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
var paletteGroup = int.Parse(value[0]);
|
||||
|
||||
for (var innerIndex = 1; innerIndex < value.Length; innerIndex++)
|
||||
{
|
||||
if (value[innerIndex] == "*") continue;
|
||||
var point = value[innerIndex].Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (var cel in dto.Cels.Where(x => x.Id == innerIndex - 1))
|
||||
foreach (var cel in dto.Cels.Where(x => x.Mark == innerIndex - 1))
|
||||
{
|
||||
cel.PaletteGroup = paletteGroup;
|
||||
cel.X = int.Parse(point[0]);
|
||||
cel.Y = int.Parse(point[1]);
|
||||
}
|
||||
|
||||
+25
-43
@@ -6,11 +6,11 @@ using System.IO.IsolatedStorage;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using fxl.codes.kisekae.Entities;
|
||||
using fxl.codes.kisekae.Extensions;
|
||||
using fxl.codes.kisekae.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -55,48 +55,6 @@ namespace fxl.codes.kisekae.Services
|
||||
return files;
|
||||
}
|
||||
|
||||
public async void GetKisekaeConfig(int id, int configId)
|
||||
{
|
||||
await using var connection = new NpgsqlConnection(_connectionString);
|
||||
await connection.OpenAsync();
|
||||
|
||||
var queryParams = new { Id = id, ConfigId = configId };
|
||||
var cels = connection.Query<CelConfigDto>("select * from cel_config where config_id = @ConfigId", queryParams);
|
||||
if (cels == null)
|
||||
{
|
||||
var config = connection.QuerySingle<ConfigurationDto>(
|
||||
"select * from configuration where kisekae_id = @Id and id = @ConfigId",
|
||||
queryParams);
|
||||
|
||||
foreach (var line in config.Data.Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries))
|
||||
switch (line.ToCharArray()[0])
|
||||
{
|
||||
case '(':
|
||||
var resolutionRegex = new Regex(ResolutionRegexPattern);
|
||||
var resolutionMatch = resolutionRegex.Match(line);
|
||||
config.Width = int.Parse(resolutionMatch.Groups["Width"].Value);
|
||||
config.Height = int.Parse(resolutionMatch.Groups["Height"].Value);
|
||||
break;
|
||||
case '[':
|
||||
var borderValue = line[1..];
|
||||
if (borderValue.Contains(';')) borderValue = borderValue.Split(';')[0].Trim();
|
||||
config.BorderIndex = int.Parse(borderValue);
|
||||
break;
|
||||
case '%':
|
||||
break;
|
||||
case '#':
|
||||
break;
|
||||
case '$':
|
||||
case ' ':
|
||||
break;
|
||||
}
|
||||
|
||||
await connection.UpdateAsync(config);
|
||||
}
|
||||
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
|
||||
public async void StoreToDatabase(IFormFile file)
|
||||
{
|
||||
var memoryStream = await GetAsMemoryStream(file);
|
||||
@@ -155,6 +113,30 @@ namespace fxl.codes.kisekae.Services
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
|
||||
public async Task<PlaysetModel> LoadConfig(int configId)
|
||||
{
|
||||
await using var connection = new NpgsqlConnection(_connectionString);
|
||||
await connection.OpenAsync();
|
||||
|
||||
var config = await connection.QuerySingleAsync<ConfigurationDto>("select * from configuration where id = @configId", new { configId });
|
||||
|
||||
var celIds = await connection.QueryAsync<int>("select cel_id from cel_config where config_id = @configId", new { configId });
|
||||
var renders = await connection.QueryAsync<CelRenderDto>($"select * from cel_render where cel_id in ({string.Join(",", celIds)})");
|
||||
if (!renders.Any())
|
||||
{
|
||||
using var reader = await connection.QueryMultipleAsync($"select * from cel where id in ({string.Join(",", celIds)});"
|
||||
+ "select * from palette where kisekae_id = @kisekaeId", new { kisekaeId = config.KisekaeId });
|
||||
|
||||
var cels = reader.Read<CelDto>();
|
||||
var palettes = reader.Read<PaletteDto>().ToDictionary(x => x.Id);
|
||||
|
||||
|
||||
}
|
||||
|
||||
await connection.CloseAsync();
|
||||
return null;
|
||||
}
|
||||
|
||||
private KisekaeDto GetExisting(IDbConnection connection, string filename, string checksum)
|
||||
{
|
||||
var existing = connection.QuerySingleOrDefault<KisekaeDto>("select * from kisekae where kisekae.filename = @Filename", new { Filename = filename });
|
||||
|
||||
Reference in New Issue
Block a user