58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
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<string> 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<string, object> BuildDictionaryParameter(List<string> values)
|
|
{
|
|
var parameterDictionary = new Dictionary<string, object>();
|
|
for (int currentCount = 0; currentCount < values.Count; ++currentCount)
|
|
{
|
|
parameterDictionary.Add($"{DynamicParamater}{currentCount}", values[currentCount]);
|
|
}
|
|
return parameterDictionary;
|
|
}
|
|
}
|
|
}
|