13 private readonly StreamWriter _writer;
14 private readonly
string _source;
15 private bool _disposed;
25 : this(filePath, source, new FileSystemAdapter(), append)
39 if (
string.IsNullOrEmpty(filePath))
40 throw new ArgumentNullException(nameof(filePath));
41 if (
string.IsNullOrEmpty(source))
42 throw new ArgumentNullException(nameof(source));
45 if (!
string.IsNullOrEmpty(directory))
62 if (data ==
null)
throw new ArgumentNullException(nameof(data));
64 WritePacketInternal(data, direction, DateTime.UtcNow);
78 if (data ==
null)
throw new ArgumentNullException(nameof(data));
80 WritePacketInternal(data, direction, timestamp);
93 WritePacketInternal(trace.
Data, trace.
Direction, DateTime.UtcNow);
96 private void WritePacketInternal(
byte[] data,
TraceDirection direction, DateTime timestamp)
98 var unixTime = timestamp.Subtract(
new DateTime(1970, 1, 1));
99 long timeSec = (long)Math.Floor(unixTime.TotalSeconds);
100 long timeNano = (unixTime.Ticks - timeSec * TimeSpan.TicksPerSecond) * 100L;
102 string ioValue = direction
switch
112 timeSec = timeSec.ToString(
"F0"),
113 timeNano = timeNano.ToString(
"000000000"),
115 data = BitConverter.ToString(data),
116 osdpTraceVersion =
"1",
120 string json = JsonSerializer.Serialize(entry);
121 _writer.WriteLine(json);
131 GC.SuppressFinalize(
this);
138 protected virtual void Dispose(
bool disposing)
void WriteTrace(TraceEntry trace)
Writes a trace entry to the capture file.
void WritePacket(byte[] data, TraceDirection direction, DateTime timestamp)
Writes a packet to the capture file with a specific timestamp.
void WritePacket(byte[] data, TraceDirection direction)
Writes a packet to the capture file.
virtual void Dispose(bool disposing)
Releases resources used by the OSDPCaptureFileWriter.
OSDPCaptureFileWriter(string filePath, string source, bool append=true)
Initializes a new instance of the OSDPCaptureFileWriter class.
void Dispose()
Releases all resources used by the OSDPCaptureFileWriter.
Abstraction for file system operations to enable testing without actual file I/O.
StreamWriter CreateStreamWriter(string path, bool append)
Creates a StreamWriter for the specified file path.
void CreateDirectory(string path)
Creates all directories in the specified path.
string GetDirectoryName(string path)
Gets the directory name from a file path.
TraceDirection
Direction of trace.
@ Output
Data is sent from the device.
@ Input
Data is sent to the device.
@ Trace
Data is being monitored.
Represents low level data sent on the wire between the control panel and the devices.
byte[] Data
The data that is sent/received.
TraceDirection Direction
The direction in which the data is sent.