using NTwain.Data; using System; using System.Runtime.Serialization; using System.Security.Permissions; namespace NTwain { /// /// Represents an exception from calling a TWAIN triplet operation in the wrong state. /// [Serializable] public class TwainStateException : TwainException { /// /// Initializes a new instance of the class. /// public TwainStateException() { } /// /// Initializes a new instance of the class. /// /// The actual state number. /// The minimum state allowed. /// The maximum state allowed. /// The data group used. /// The data argument type used. /// The twain message used. /// The message. public TwainStateException(int currentState, int minStateExpected, int maxStateExpected, DataGroups dataGroup, DataArgumentType argumentType, Message twainMessage, string message) : base(default(ReturnCode), message) { ActualState = currentState; MinStateExpected = minStateExpected; MaxStateExpected = maxStateExpected; DataGroup = dataGroup; ArgumentType = argumentType; TwainMessage = twainMessage; } /// /// Initializes a new instance of the class. /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. /// /// The parameter is null. /// /// /// The class name is null or is zero (0). /// protected TwainStateException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info != null) { MinStateExpected = info.GetInt32("MIN"); MaxStateExpected = info.GetInt32("MAX"); ActualState = info.GetInt32("State"); DataGroup = (DataGroups)info.GetUInt32("DG"); ArgumentType = (DataArgumentType)info.GetUInt16("DAT"); TwainMessage = (Message)info.GetUInt16("MSG"); } } /// /// When overridden in a derived class, sets the with information about the exception. /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. /// /// The parameter is a null reference (Nothing in Visual Basic). /// /// /// /// /// [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info != null) { info.AddValue("MIN", MinStateExpected); info.AddValue("MAX", MaxStateExpected); info.AddValue("State", ActualState); info.AddValue("DG", DataGroup); info.AddValue("DAT", ArgumentType); info.AddValue("MSG", TwainMessage); } base.GetObjectData(info, context); } /// /// Gets the allowed minimum state. /// /// The minimum. public int MinStateExpected { get; private set; } /// /// Gets the allowed maximum state. /// /// The maximum. public int MaxStateExpected { get; private set; } /// /// Gets the actual state number. /// /// The state. public int ActualState { get; private set; } /// /// Gets the triplet data group. /// /// The data group. public DataGroups DataGroup { get; private set; } /// /// Gets the triplet data argument type. /// /// The type of the argument. public DataArgumentType ArgumentType { get; private set; } /// /// Gets the triplet message. /// /// The twain message. public Message TwainMessage { get; private set; } } }