Skip to content

Commit cc6cd71

Browse files
bytedreamerclaude
andcommitted
Fix code style and API design issues in delegation support
- Convert tab indentation to 4-space to match codebase standard - Rename Command property to ReplyType in RawReplyEventArgs for clarity - Use ReadOnlyMemory<byte> for Payload to prevent mutation by subscribers - Move RawReplyReceived invocation after typed event dispatch Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9556b3a commit cc6cd71

1 file changed

Lines changed: 76 additions & 73 deletions

File tree

src/OSDP.Net/ControlPanel.cs

Lines changed: 76 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -187,27 +187,27 @@ public async Task SendCustomCommand(Guid connectionId, byte address, CommandData
187187
await SendCommand(connectionId, address, command).ConfigureAwait(false);
188188
}
189189

190-
/// <summary>
191-
/// Enqueue a custom command to be sent without waiting for a response.
192-
/// </summary>
193-
/// <param name="connectionId">Identify the connection for communicating to the device.</param>
194-
/// <param name="address">Address assigned to the device.</param>
195-
/// <param name="command">The custom command to send.</param>
196-
public void EnqueueCustomCommand(Guid connectionId, byte address, CommandData command)
197-
{
198-
if (!_buses.TryGetValue(connectionId, out var bus))
199-
{
200-
throw new ArgumentException("Connection could not be found", nameof(connectionId));
201-
}
202-
203-
bus.SendCommand(address, command);
204-
}
205-
206-
/// <summary>Request to get an ID Report from the PD.</summary>
207-
/// <param name="connectionId">Identify the connection for communicating to the device.</param>
208-
/// <param name="address">Address assigned to the device.</param>
209-
/// <returns>ID report reply data that was requested.</returns>
210-
public async Task<DeviceIdentification> IdReport(Guid connectionId, byte address) =>
190+
/// <summary>
191+
/// Enqueue a custom command to be sent without waiting for a response.
192+
/// </summary>
193+
/// <param name="connectionId">Identify the connection for communicating to the device.</param>
194+
/// <param name="address">Address assigned to the device.</param>
195+
/// <param name="command">The custom command to send.</param>
196+
public void EnqueueCustomCommand(Guid connectionId, byte address, CommandData command)
197+
{
198+
if (!_buses.TryGetValue(connectionId, out var bus))
199+
{
200+
throw new ArgumentException("Connection could not be found", nameof(connectionId));
201+
}
202+
203+
bus.SendCommand(address, command);
204+
}
205+
206+
/// <summary>Request to get an ID Report from the PD.</summary>
207+
/// <param name="connectionId">Identify the connection for communicating to the device.</param>
208+
/// <param name="address">Address assigned to the device.</param>
209+
/// <returns>ID report reply data that was requested.</returns>
210+
public async Task<DeviceIdentification> IdReport(Guid connectionId, byte address) =>
211211
await IdReport(connectionId, address, CancellationToken.None).ConfigureAwait(false);
212212

213213
/// <summary>Request to get an ID Report from the PD.</summary>
@@ -1463,9 +1463,8 @@ private void OnConnectionStatusChanged(Guid connectionId, byte address, bool isC
14631463
private void OnReplyReceived(ReplyTracker reply)
14641464
{
14651465
ReplyReceived?.Invoke(this, new ReplyEventArgs { Reply = reply });
1466-
RawReplyReceived?.Invoke(this, new RawReplyEventArgs(reply.ConnectionId, reply.ReplyMessage.Address, reply.ReplyMessage.Type, reply.ReplyMessage.Payload));
14671466

1468-
switch ((ReplyType)reply.ReplyMessage.Type)
1467+
switch ((ReplyType)reply.ReplyMessage.Type)
14691468
{
14701469
case ReplyType.Nak:
14711470
NakReplyReceived?.Invoke(this,
@@ -1543,19 +1542,23 @@ private void OnReplyReceived(ReplyTracker reply)
15431542
BiometricMatchResult.ParseData(reply.ReplyMessage.Payload)));
15441543
break;
15451544
}
1545+
1546+
RawReplyReceived?.Invoke(this,
1547+
new RawReplyEventArgs(reply.ConnectionId, reply.ReplyMessage.Address,
1548+
reply.ReplyMessage.Type, reply.ReplyMessage.Payload));
15461549
}
15471550

15481551
private event EventHandler<ReplyEventArgs> ReplyReceived;
15491552

1550-
/// <summary>
1551-
/// Occurs when any reply is received
1552-
/// </summary>
1553-
public event EventHandler<RawReplyEventArgs> RawReplyReceived;
1553+
/// <summary>
1554+
/// Occurs when any reply is received.
1555+
/// </summary>
1556+
public event EventHandler<RawReplyEventArgs> RawReplyReceived;
15541557

1555-
/// <summary>
1556-
/// Occurs when connection status changed.
1557-
/// </summary>
1558-
public event EventHandler<ConnectionStatusEventArgs> ConnectionStatusChanged;
1558+
/// <summary>
1559+
/// Occurs when connection status changed.
1560+
/// </summary>
1561+
public event EventHandler<ConnectionStatusEventArgs> ConnectionStatusChanged;
15591562

15601563
/// <summary>
15611564
/// Occurs when a negative reply is received.
@@ -2174,48 +2177,48 @@ internal FileTransferException(string msg, FileTransferStatus status) : base(msg
21742177
public FileTransferStatus Status { get; }
21752178
}
21762179

2177-
/// <summary>
2178-
/// A reply has been received.
2179-
/// </summary>
2180-
public class RawReplyEventArgs : EventArgs
2181-
{
2182-
/// <summary>
2183-
/// Initializes a new instance of the <see cref="RawReplyEventArgs"/> class.
2184-
/// </summary>
2185-
/// <param name="connectionId">Identify the connection for communicating to the device.</param>
2186-
/// <param name="address">Address assigned to the device.</param>
2187-
/// <param name="command">The reply code of the message.</param>
2188-
/// <param name="payload">The raw reply payload.</param>
2189-
public RawReplyEventArgs(Guid connectionId, byte address, byte command, byte[] payload)
2190-
{
2191-
ConnectionId = connectionId;
2192-
Address = address;
2193-
Command = command;
2194-
Payload = payload;
2195-
}
2196-
2197-
/// <summary>
2198-
/// Identify the connection for communicating to the device.
2199-
/// </summary>
2200-
public Guid ConnectionId { get; }
2201-
2202-
/// <summary>
2203-
/// Address assigned to the device.
2204-
/// </summary>
2205-
public byte Address { get; }
2206-
2207-
/// <summary>
2208-
/// The reply code of the message.
2209-
/// </summary>
2210-
public byte Command { get; }
2211-
2212-
/// <summary>
2213-
/// The raw reply payload.
2214-
/// </summary>
2215-
public byte[] Payload { get; }
2216-
}
2217-
2218-
private class ReplyEventArgs : EventArgs
2180+
/// <summary>
2181+
/// A reply has been received.
2182+
/// </summary>
2183+
public class RawReplyEventArgs : EventArgs
2184+
{
2185+
/// <summary>
2186+
/// Initializes a new instance of the <see cref="RawReplyEventArgs"/> class.
2187+
/// </summary>
2188+
/// <param name="connectionId">Identify the connection for communicating to the device.</param>
2189+
/// <param name="address">Address assigned to the device.</param>
2190+
/// <param name="replyType">The reply type code of the message.</param>
2191+
/// <param name="payload">The raw reply payload.</param>
2192+
public RawReplyEventArgs(Guid connectionId, byte address, byte replyType, ReadOnlyMemory<byte> payload)
2193+
{
2194+
ConnectionId = connectionId;
2195+
Address = address;
2196+
ReplyType = replyType;
2197+
Payload = payload;
2198+
}
2199+
2200+
/// <summary>
2201+
/// Identify the connection for communicating to the device.
2202+
/// </summary>
2203+
public Guid ConnectionId { get; }
2204+
2205+
/// <summary>
2206+
/// Address assigned to the device.
2207+
/// </summary>
2208+
public byte Address { get; }
2209+
2210+
/// <summary>
2211+
/// The reply type code of the message.
2212+
/// </summary>
2213+
public byte ReplyType { get; }
2214+
2215+
/// <summary>
2216+
/// The raw reply payload.
2217+
/// </summary>
2218+
public ReadOnlyMemory<byte> Payload { get; }
2219+
}
2220+
2221+
private class ReplyEventArgs : EventArgs
22192222
{
22202223
public ReplyTracker Reply { get; set; }
22212224
}

0 commit comments

Comments
 (0)