2024-02-22 08:07:38 -06:00
|
|
|
using Errata;
|
|
|
|
|
using Microsoft.Iris;
|
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2024-07-07 22:40:19 -05:00
|
|
|
|
2024-02-22 08:07:38 -06:00
|
|
|
namespace UIXC;
|
|
|
|
|
|
2024-07-07 22:40:19 -05:00
|
|
|
public class IrisSourceRepository(IEnumerable<string?> compilands) : ISourceRepository
|
2024-02-22 08:07:38 -06:00
|
|
|
{
|
2024-07-07 22:40:19 -05:00
|
|
|
private readonly Dictionary<string, Source?> _sourceCache = compilands
|
|
|
|
|
.Where(c => c is not null).Cast<string>()
|
|
|
|
|
.Where(c => !c.Contains(Uri.SchemeDelimiter))
|
|
|
|
|
.Select(c => (c, (Source?)null))
|
|
|
|
|
.ToDictionary();
|
2024-02-22 08:07:38 -06:00
|
|
|
|
|
|
|
|
public IrisSourceRepository(CompilerInput[] compilands, CompilerInput? sharedBinaryDataTable)
|
2024-07-07 22:40:19 -05:00
|
|
|
: this(compilands.Select(c => c.SourceFileName).AsEnumerable().Append(sharedBinaryDataTable.HasValue ? sharedBinaryDataTable.Value.SourceFileName : null))
|
2024-02-22 08:07:38 -06:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-07 15:36:29 -05:00
|
|
|
public bool TryGet(string uri, [NotNullWhen(true)] out Source? source)
|
2024-02-22 08:07:38 -06:00
|
|
|
{
|
2024-07-07 15:36:29 -05:00
|
|
|
var idStart = uri.IndexOf(Uri.SchemeDelimiter) + Uri.SchemeDelimiter.Length;
|
|
|
|
|
var id = uri[idStart..];
|
|
|
|
|
|
2024-02-22 08:07:38 -06:00
|
|
|
if (!_sourceCache.TryGetValue(id, out source))
|
2024-07-07 15:36:29 -05:00
|
|
|
return false;
|
2024-02-22 08:07:38 -06:00
|
|
|
|
|
|
|
|
if (source is null)
|
|
|
|
|
{
|
|
|
|
|
var sourceText = File.ReadAllText(id);
|
|
|
|
|
source = _sourceCache[id] = new(id, sourceText);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|