58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
namespace LogViewer.Data
|
|
{
|
|
public class ReportFileService
|
|
{
|
|
private static IConfiguration _configuration;
|
|
|
|
private static ILogger<ReportFileService> _logger;
|
|
|
|
//private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
/// <summary>
|
|
/// Init classe
|
|
/// </summary>
|
|
/// <param name="configuration"></param>
|
|
/// <param name="logger"></param>
|
|
public ReportFileService(IConfiguration configuration, ILogger<ReportFileService> logger)
|
|
{
|
|
_logger = logger;
|
|
_configuration = configuration;
|
|
}
|
|
public async Task<Dictionary<string, string>> getDayReport()
|
|
{
|
|
string basec = _configuration["basePath"];
|
|
string targetDir = basec+$"/day";
|
|
return await getFileList(targetDir);
|
|
}
|
|
public async Task<Dictionary<string, string>> getWeekReport()
|
|
{
|
|
string basec = _configuration["basePath"];
|
|
string targetDir = basec + $"/week";
|
|
return await getFileList(targetDir);
|
|
//return await getFileList($"{Directory.GetCurrentDirectory()}/wwwroot/reports/week/");
|
|
}
|
|
public async Task<Dictionary<string, string>> getMonthReport()
|
|
{
|
|
string basec = _configuration["basePath"];
|
|
string targetDir = basec + $"/month";
|
|
return await getFileList(targetDir);
|
|
//return await getFileList($"{Directory.GetCurrentDirectory()}/wwwroot/reports/month/");
|
|
}
|
|
|
|
private static async Task<Dictionary<string, string>> getFileList(string baseDir)
|
|
{
|
|
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
|
|
|
|
Console.WriteLine($"GetfileList for {baseDir}");
|
|
var results = Directory.GetFiles(baseDir, "*.html");
|
|
Console.WriteLine($"Found {results.Length}");
|
|
foreach (var result in results)
|
|
{
|
|
keyValuePairs.Add(Path.GetFileName(result), result);
|
|
}
|
|
|
|
return await Task.FromResult(keyValuePairs);
|
|
}
|
|
}
|
|
}
|