46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using System.Text.Json;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace ReportGenerator.Models;
|
|
|
|
internal struct ScannedResultInfo
|
|
{
|
|
public string Path { get; private init; }
|
|
|
|
private static readonly Regex parseRegex = new(
|
|
@"(?'image'.+)\.(?'processor'.+)\..+",
|
|
RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase
|
|
);
|
|
|
|
public string ProcessorName { get; set; }
|
|
|
|
public string ImageName { get; set; }
|
|
|
|
public ICollection<string> GetWords()
|
|
{
|
|
using var file = File.OpenRead(Path);
|
|
return JsonDocument
|
|
.Parse(file)
|
|
.RootElement
|
|
.EnumerateArray()
|
|
.Select(e =>
|
|
e.GetProperty("Text").GetString() ?? throw new Exception("Cannot parse null words"))
|
|
.ToArray();
|
|
}
|
|
|
|
public static ScannedResultInfo FromPath(string path)
|
|
{
|
|
var match = parseRegex.Match(System.IO.Path.GetFileName(path));
|
|
return new ScannedResultInfo
|
|
{
|
|
Path = path,
|
|
ProcessorName = match.Groups["processor"].Value,
|
|
ImageName = match.Groups["image"].Value
|
|
};
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
public override string ToString() => ImageName;
|
|
}
|