cs-codex-dist-tests/Framework/Core/DownloadedLog.cs

84 lines
2.3 KiB
C#
Raw Normal View History

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);
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;
internal DownloadedLog(WriteToFileLogHandler logHandler)
2023-04-13 09:30:19 +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)
{
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);
}
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
}
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
}
}