using Serilog; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Dynamic; namespace LCU.Library.Internal.CoreApiWrapperLib.Utilities { public static class QueryUtilities { private const string QueryFolder = "Queries"; private const string DynamicParamater = "param"; public static string GetQuery(string queryFileName) { var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory); var path = $"{basePath}//{QueryFolder}//{queryFileName}.sql"; if (!File.Exists(path)) { Log.Error($"Query was not found at location {path}"); return ""; } var query = File.ReadAllText(path); return query; } public static string BuildParameterListString(List values) { var bindListBuilder = new StringBuilder(); for (int currentCount = 0; currentCount < values.Count; ++currentCount) { var comma = ""; if (currentCount != 0) { comma = ","; } bindListBuilder.Append($"{comma}:{DynamicParamater}{currentCount}"); } return bindListBuilder.ToString(); } public static Dictionary BuildDictionaryParameter(List values) { var parameterDictionary = new Dictionary(); for (int currentCount = 0; currentCount < values.Count; ++currentCount) { parameterDictionary.Add($"{DynamicParamater}{currentCount}", values[currentCount]); } return parameterDictionary; } } }