-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportClassifier.cs
More file actions
48 lines (44 loc) · 1.57 KB
/
Copy pathReportClassifier.cs
File metadata and controls
48 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Xml.Linq;
namespace DmarcTlsReportParser
{
public class ReportClassifier
{
private readonly string _inputDir;
private readonly string _outputDir;
public List<string> ParsedFiles { get; private set; } = new();
public ReportClassifier(string inputDir, string baseOutputDir)
{
_inputDir = inputDir;
var today = DateTime.Now.ToString("yyyy-MM-dd");
_outputDir = Path.Combine(baseOutputDir, today);
Directory.CreateDirectory(_outputDir);
}
public void ClassifyAndParse(IEnumerable<string> filesToParse)
{
var dmarcParser = new DmarcParser(_outputDir);
var tlsRptParser = new TlsRptParser(_outputDir);
foreach (var file in filesToParse)
{
try
{
if (file.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
{
dmarcParser.Parse(file, ParsedFiles);
}
else if (file.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
{
tlsRptParser.Parse(file, ParsedFiles);
}
else
{
Console.WriteLine($"[SKIP] Unknown file type: {Path.GetFileName(file)}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error parsing {file}: {ex.Message}");
}
}
}
}
}