Initial commit
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
namespace Sick.SafetyScanners.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Base exception cho tất cả COLA2 errors
|
||||
/// </summary>
|
||||
public class Cola2Exception : Exception
|
||||
{
|
||||
public ushort? ErrorCode { get; }
|
||||
public uint? SessionId { get; }
|
||||
public ushort? RequestId { get; }
|
||||
|
||||
public Cola2Exception(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public Cola2Exception(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
public Cola2Exception(ushort errorCode, string message) : base(message)
|
||||
{
|
||||
ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
public Cola2Exception(uint sessionId, ushort requestId, ushort errorCode, string message)
|
||||
: base(message)
|
||||
{
|
||||
SessionId = sessionId;
|
||||
RequestId = requestId;
|
||||
ErrorCode = errorCode;
|
||||
}
|
||||
|
||||
public Cola2Exception(uint sessionId, string message)
|
||||
: base(message)
|
||||
{
|
||||
SessionId = sessionId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Session management errors
|
||||
/// </summary>
|
||||
public class SessionException : Cola2Exception
|
||||
{
|
||||
public SessionException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public SessionException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
public SessionException(uint sessionId, string message) : base(sessionId, message)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Command execution errors
|
||||
/// </summary>
|
||||
public class CommandException : Cola2Exception
|
||||
{
|
||||
public byte CommandType { get; }
|
||||
public byte CommandMode { get; }
|
||||
|
||||
public CommandException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CommandException(byte commandType, byte commandMode, string message) : base(message)
|
||||
{
|
||||
CommandType = commandType;
|
||||
CommandMode = commandMode;
|
||||
}
|
||||
|
||||
public CommandException(uint sessionId, ushort requestId, byte commandType, byte commandMode,
|
||||
ushort errorCode, string message) : base(sessionId, requestId, errorCode, message)
|
||||
{
|
||||
CommandType = commandType;
|
||||
CommandMode = commandMode;
|
||||
}
|
||||
|
||||
public override string Message =>
|
||||
$"Command Error (Type: 0x{CommandType:X2}, Mode: 0x{CommandMode:X2}): {base.Message}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Timeout errors
|
||||
/// </summary>
|
||||
public class Cola2TimeoutException : Cola2Exception
|
||||
{
|
||||
public TimeSpan Timeout { get; }
|
||||
public string Operation { get; }
|
||||
|
||||
public Cola2TimeoutException(string operation, TimeSpan timeout, string message) : base(message)
|
||||
{
|
||||
Operation = operation;
|
||||
Timeout = timeout;
|
||||
}
|
||||
|
||||
public override string Message =>
|
||||
$"Timeout after {Timeout.TotalMilliseconds}ms during {Operation}: {base.Message}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TCP communication errors
|
||||
/// </summary>
|
||||
public class TcpCommunicationException : Cola2Exception
|
||||
{
|
||||
public string? ServerIp { get; }
|
||||
public ushort? ServerPort { get; }
|
||||
|
||||
public TcpCommunicationException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public TcpCommunicationException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
public TcpCommunicationException(string serverIp, ushort serverPort, string message)
|
||||
: base(message)
|
||||
{
|
||||
ServerIp = serverIp;
|
||||
ServerPort = serverPort;
|
||||
}
|
||||
|
||||
public TcpCommunicationException(string serverIp, ushort serverPort, string message,
|
||||
Exception innerException) : base(message, innerException)
|
||||
{
|
||||
ServerIp = serverIp;
|
||||
ServerPort = serverPort;
|
||||
}
|
||||
|
||||
public override string Message =>
|
||||
ServerIp != null && ServerPort.HasValue
|
||||
? $"TCP Communication Error to {ServerIp}:{ServerPort}: {base.Message}"
|
||||
: $"TCP Communication Error: {base.Message}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Packet parsing errors
|
||||
/// </summary>
|
||||
public class PacketParsingException : Cola2Exception
|
||||
{
|
||||
public PacketParsingException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public PacketParsingException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UDP communication errors
|
||||
/// </summary>
|
||||
public class UdpCommunicationException : Cola2Exception
|
||||
{
|
||||
public UdpCommunicationException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public UdpCommunicationException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
public override string Message => $"UDP Communication Error: {base.Message}";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user