public LogFileModel(Stream stream, Func <string?, string> transformer, bool allowEscape) { if (stream is null) { throw new ArgumentNullException(nameof(stream)); } if (transformer is null) { throw new ArgumentNullException(nameof(transformer)); } var logs = new List <LogDataModel>(); using (var sr = new StreamReader(stream, true)) { while (sr.ReadLine() is not null and string line) { var row = ParseCsv(line, allowEscape); if (row.Count == 12) { if (row[0] != "output_date") { string msg = row[02]; logs.Add(new( row[00], row[01], msg, transformer(msg) ?? msg, row[03], row[04], row[05], row[06], row[07], row[08], row[09], row[10], row[11], PrivacyValidator.Check(msg) )); } } else { logs.Add(new( LanguageData.Current.LogFileModel_InvalidLog_Short, nameof(LogLevel.Remarks), row.Aggregate((a, b) => $"{a}, {b}"), LanguageData.Current.LogFileModel_InvalidLog_Long, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, false )); } } } this.Logs = logs; }
public void CheckTest() { Assert.IsFalse(PrivacyValidator.Check(string.Empty)); Assert.IsFalse(PrivacyValidator.Check("")); Assert.IsFalse(PrivacyValidator.Check(null !)); Assert.IsTrue(PrivacyValidator.Check("Exposure notification status: ")); Assert.IsTrue(PrivacyValidator.Check("Exposure count: ")); Assert.IsTrue(PrivacyValidator.Check("http://")); Assert.IsTrue(PrivacyValidator.Check("https://")); Assert.IsTrue(PrivacyValidator.Check("Exception")); Assert.IsFalse(PrivacyValidator.Check(" Exposure notification status: ")); Assert.IsFalse(PrivacyValidator.Check("Exposure notification status:")); Assert.IsFalse(PrivacyValidator.Check(" Exposure count: ")); Assert.IsFalse(PrivacyValidator.Check("Exposure count:")); Assert.IsFalse(PrivacyValidator.Check("http")); Assert.IsFalse(PrivacyValidator.Check("https")); Assert.IsFalse(PrivacyValidator.Check("exception")); Assert.IsTrue(PrivacyValidator.Check("Exposure count: http://")); Assert.IsTrue(PrivacyValidator.Check("http:// Exception")); Assert.IsTrue(PrivacyValidator.Check("aa http:// bb")); Assert.IsTrue(PrivacyValidator.Check("aa https:// bb")); Assert.IsTrue(PrivacyValidator.Check("aa Exception bb")); Assert.IsTrue(PrivacyValidator.Check("http http:// ____")); Assert.IsTrue(PrivacyValidator.Check("https https:// ____")); Assert.IsTrue(PrivacyValidator.Check("{{}}")); Assert.IsTrue(PrivacyValidator.Check("]:,[")); Assert.IsTrue(PrivacyValidator.Check("[ 123, 456, { \"abc\": null } ]")); Assert.IsFalse(PrivacyValidator.Check("http https")); Assert.IsFalse(PrivacyValidator.Check("Hello, World!!")); Assert.IsFalse(PrivacyValidator.Check("0123456789")); Assert.IsFalse(PrivacyValidator.Check("{ \"hello\": \"world\" }")); Assert.IsFalse(PrivacyValidator.Check("[ false ]")); }