using System.Text.Json; using Microsoft.Extensions.Configuration; using System.IO; using System; using System.Collections.Generic; using System.Text.RegularExpressions; namespace gameapi.Library { public class BlockLoader : IBlockLoader { private string path; public BlockLoader() { path = GlobalConfiguration.Get().GetSection("Slackbot").GetValue("BlocksPath"); } public dynamic Read(string filename, Dictionary replaceKeys = null) { if (replaceKeys == null) { replaceKeys = new Dictionary(); } var filePath = path + "/" + filename; var text = File.ReadAllText(filePath); foreach (var replacement in replaceKeys) { text = text.Replace("{" + replacement.Key + "}", replacement.Value, StringComparison.InvariantCultureIgnoreCase); } var blocks = JsonSerializer.Deserialize(text); return blocks; } } public interface IBlockLoader { dynamic Read(string filename, Dictionary replaceKeys = null); } }