public SniffFile(string fileName, DumpFormatType dumpFormat = DumpFormatType.Text, Tuple<int, int> number = null) { if (string.IsNullOrWhiteSpace(fileName)) throw new ArgumentException("fileName cannot be null, empty or whitespace.", nameof(fileName)); _stats = new Statistics(); FileName = fileName; _dumpFormat = dumpFormat; _logPrefix = number == null ? $"[{Path.GetFileName(FileName)}]" : $"[{number.Item1}/{number.Item2} {Path.GetFileName(FileName)}]"; }
public SniffFile(string fileName, DumpFormatType dumpFormat = DumpFormatType.Text, Tuple<int, int> number = null) { if (string.IsNullOrWhiteSpace(fileName)) throw new ArgumentException("fileName cannot be null, empty or whitespace.", "fileName"); _stats = new Statistics(); _fileName = fileName; _dumpFormat = dumpFormat; if (number == null) _logPrefix = string.Format("[{0}]", Path.GetFileName(fileName)); else _logPrefix = string.Format("[{0}/{1} {2}]", number.Item1, number.Item2, Path.GetFileName(fileName)); }
public void TestAdds() { var stats = new Statistics(6); stats.AddSucess(); stats.AddSucess(); stats.AddSucess(); stats.AddWithErrors(); stats.AddWithErrors(); stats.AddNotParsed(); Assert.AreEqual(3, stats.SucessPacketCount); Assert.AreEqual(2, stats.WithErrorsPacketCount); Assert.AreEqual(1, stats.NotParsedPacketCount); Assert.AreEqual(stats.TotalPacketCount, stats.CalculatedTotalPacketCount); }
public void TestConstructor() { Assert.Throws<ArgumentOutOfRangeException>(() => new Statistics(0)); var stats = new Statistics(10); Assert.AreEqual(10, stats.TotalPacketCount); Assert.AreEqual(0, stats.CalculatedTotalPacketCount); Assert.AreEqual(0, stats.SucessPacketCount); Assert.AreEqual(0, stats.WithErrorsPacketCount); Assert.AreEqual(0, stats.NotParsedPacketCount); var stats2 = new Statistics(); Assert.AreEqual(0, stats2.TotalPacketCount); Assert.AreEqual(0, stats2.CalculatedTotalPacketCount); Assert.AreEqual(0, stats2.SucessPacketCount); Assert.AreEqual(0, stats2.WithErrorsPacketCount); Assert.AreEqual(0, stats2.NotParsedPacketCount); }
public SniffFile(string fileName, DumpFormatType dumpFormat = DumpFormatType.Text, Tuple<int, int> number = null, SQLOutputFlags sqlOutput = SQLOutputFlags.None) { if (string.IsNullOrWhiteSpace(fileName)) throw new ArgumentException("fileName cannot be null, empty or whitespace.", "fileName"); _stats = new Statistics(); _packets = null; _fileName = fileName; _dumpFormat = dumpFormat; _sqlOutput = sqlOutput; _outFileName = Path.ChangeExtension(fileName, null) + "_parsed.txt"; if (number == null) _logPrefix = string.Format("[{0}]", Path.GetFileName(fileName)); else _logPrefix = string.Format("[{0}/{1} {2}]", number.Item1, number.Item2, Path.GetFileName(fileName)); }
public void TestAddByStatus() { var packet1 = new Packet(new byte[] { 1, 2 }, 1, DateTime.Now, Direction.ClientToServer, 1, "test.bin"); var packet2 = new Packet(new byte[] { 1, 2 }, 1, DateTime.Now, Direction.ClientToServer, 2, "test.bin"); var packet3 = new Packet(new byte[] { 1, 2 }, 1, DateTime.Now, Direction.ClientToServer, 3, "test.bin"); packet1.Status = ParsedStatus.Success; packet2.Status = ParsedStatus.NotParsed; var stats = new Statistics(); stats.AddByStatus(packet1.Status); stats.AddByStatus(packet2.Status); stats.AddByStatus(packet3.Status); Assert.AreEqual(1, stats.SucessPacketCount); Assert.AreEqual(0, stats.WithErrorsPacketCount); Assert.AreEqual(1, stats.NotParsedPacketCount); Assert.AreEqual(2, stats.CalculatedTotalPacketCount); }
public SniffFile(string fileName, DumpFormatType dumpFormat = DumpFormatType.Text, Tuple<int, int> number = null) { if (string.IsNullOrWhiteSpace(fileName)) throw new ArgumentException("fileName cannot be null, empty or whitespace.", "fileName"); _stats = new Statistics(); _fileName = fileName; _originalFileName = fileName; var extension = Path.GetExtension(_originalFileName); if (extension.ToLower() == ".gz") _originalFileName = _originalFileName.Remove(_originalFileName.Length - extension.Length); _dumpFormat = dumpFormat; if (number == null) _logPrefix = string.Format("[{0}]", Path.GetFileName(_originalFileName)); else _logPrefix = string.Format("[{0}/{1} {2}]", number.Item1, number.Item2, Path.GetFileName(_originalFileName)); }
public void TestPercentage() { var stats = new Statistics(6); stats.AddSucess(); stats.AddSucess(); stats.AddSucess(); stats.AddWithErrors(); stats.AddWithErrors(); stats.AddNotParsed(); Assert.AreEqual(3.0 / 6.0 * 100.0, stats.GetSucessPercentage(), 0.001); Assert.AreEqual(2.0 / 6.0 * 100.0, stats.GetWithErrorsPercentage(), 0.001); Assert.AreEqual(1.0 / 6.0 * 100.0, stats.GetNotParsedPercentage(), 0.001); }
public void TestToString() { // What is there to test? var stats = new Statistics(6); stats.AddSucess(); stats.AddSucess(); stats.AddSucess(); stats.AddWithErrors(); stats.AddWithErrors(); stats.AddNotParsed(); var str = stats.ToString(); Assert.IsNotNullOrEmpty(str); }
public void TestTimes() { var stats = new Statistics(1); stats.SetStartTime(DateTime.Now); Thread.Sleep(1); stats.SetEndTime(DateTime.Now); var span = stats.GetParsingTime(); Assert.Greater(span.Milliseconds, 0); }
/// <summary> /// Goes through each packet in a collection of packets and returns an instance of Statistics /// containing parsing status information. /// </summary> /// <param name="packets">Collection of packets</param> /// <returns>An instance of Statistics</returns> public static Statistics BuildStats(ICollection<Packet> packets) { var stats = new Statistics(packets.Count); Parallel.ForEach(packets, packet => { if (!packet.WriteToFile) stats.AddNotParsed(); else { switch (packet.Status) { case ParsedStatus.Success: stats.AddSuccess(); break; case ParsedStatus.WithErrors: stats.AddWithErrors(); break; case ParsedStatus.NotParsed: stats.AddNotParsed(); break; case ParsedStatus.NoStructure: stats.AddNoStructure(); break; } } }); return stats; }