2024-06-19 08:39:14 +00:00
|
|
|
|
using KubernetesWorkflow;
|
|
|
|
|
using Logging;
|
2023-04-13 09:30:19 +00:00
|
|
|
|
|
2023-09-12 11:32:06 +00:00
|
|
|
|
namespace Core
|
2023-04-13 09:30:19 +00:00
|
|
|
|
{
|
2023-06-27 13:28:00 +00:00
|
|
|
|
public interface IDownloadedLog
|
2023-04-13 09:30:19 +00:00
|
|
|
|
{
|
2024-07-25 08:10:11 +00:00
|
|
|
|
void IterateLines(Action<string> action, params string[] thatContain);
|
2024-03-20 10:11:59 +00:00
|
|
|
|
string[] GetLinesContaining(string expectedString);
|
2023-08-16 08:52:44 +00:00
|
|
|
|
string[] FindLinesThatContain(params string[] tags);
|
|
|
|
|
void DeleteFile();
|
2023-04-13 09:30:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 13:40:15 +00:00
|
|
|
|
internal class DownloadedLog : IDownloadedLog
|
2023-04-13 09:30:19 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly LogFile logFile;
|
|
|
|
|
|
2024-06-19 08:39:14 +00:00
|
|
|
|
internal DownloadedLog(WriteToFileLogHandler logHandler)
|
2023-04-13 09:30:19 +00:00
|
|
|
|
{
|
2024-06-19 08:39:14 +00:00
|
|
|
|
logFile = logHandler.LogFile;
|
2023-04-13 09:30:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-25 08:10:11 +00:00
|
|
|
|
public void IterateLines(Action<string> action, params string[] thatContain)
|
2024-04-19 09:40:32 +00:00
|
|
|
|
{
|
|
|
|
|
using var file = File.OpenRead(logFile.FullFilename);
|
|
|
|
|
using var streamReader = new StreamReader(file);
|
|
|
|
|
|
|
|
|
|
var line = streamReader.ReadLine();
|
|
|
|
|
while (line != null)
|
|
|
|
|
{
|
2024-07-25 08:10:11 +00:00
|
|
|
|
if (thatContain.All(line.Contains))
|
|
|
|
|
{
|
|
|
|
|
action(line);
|
|
|
|
|
}
|
2024-04-19 09:40:32 +00:00
|
|
|
|
line = streamReader.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 10:11:59 +00:00
|
|
|
|
public string[] GetLinesContaining(string expectedString)
|
2023-04-13 09:30:19 +00:00
|
|
|
|
{
|
|
|
|
|
using var file = File.OpenRead(logFile.FullFilename);
|
|
|
|
|
using var streamReader = new StreamReader(file);
|
2024-03-20 10:11:59 +00:00
|
|
|
|
var lines = new List<string>();
|
2023-04-13 09:30:19 +00:00
|
|
|
|
|
|
|
|
|
var line = streamReader.ReadLine();
|
|
|
|
|
while (line != null)
|
|
|
|
|
{
|
2024-03-20 10:11:59 +00:00
|
|
|
|
if (line.Contains(expectedString))
|
|
|
|
|
{
|
|
|
|
|
lines.Add(line);
|
|
|
|
|
}
|
2023-04-13 09:30:19 +00:00
|
|
|
|
line = streamReader.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 10:11:59 +00:00
|
|
|
|
return lines.ToArray(); ;
|
2023-04-13 09:30:19 +00:00
|
|
|
|
}
|
2023-08-16 08:52:44 +00:00
|
|
|
|
|
|
|
|
|
public string[] FindLinesThatContain(params string[] tags)
|
|
|
|
|
{
|
|
|
|
|
var result = new List<string>();
|
|
|
|
|
using var file = File.OpenRead(logFile.FullFilename);
|
|
|
|
|
using var streamReader = new StreamReader(file);
|
|
|
|
|
|
|
|
|
|
var line = streamReader.ReadLine();
|
|
|
|
|
while (line != null)
|
|
|
|
|
{
|
|
|
|
|
if (tags.All(line.Contains))
|
|
|
|
|
{
|
|
|
|
|
result.Add(line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
line = streamReader.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteFile()
|
|
|
|
|
{
|
|
|
|
|
File.Delete(logFile.FullFilename);
|
|
|
|
|
}
|
2023-04-13 09:30:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|