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