using NTwain.Data;
using NTwain.Internals;
namespace NTwain.Triplets
{
///
/// Represents .
///
sealed class Identity : OpBase
{
internal Identity(ITwainSessionInternal session) : base(session) { }
///
/// When an application is finished with a Source, it must formally close the session between them
/// using this operation. This is necessary in case the Source only supports connection with a single
/// application (many desktop scanners will behave this way). A Source such as this cannot be
/// accessed by other applications until its current session is terminated.
///
///
public ReturnCode CloseDS()
{
Session.VerifyState(4, 4, DataGroups.Control, DataArgumentType.Identity, Message.CloseDS);
var rc = Dsm.DsmEntry(Session.AppId, Message.CloseDS, Session.CurrentSource.Identity);
if (rc == ReturnCode.Success)
{
Session.ChangeCurrentSource(null);
Session.ChangeState(3, true);
}
return rc;
}
///
/// Gets the identification information of the system default Source.
///
/// The source.
///
public ReturnCode GetDefault(out TWIdentity source)
{
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.Identity, Message.GetDefault);
source = new TWIdentity();
return Dsm.DsmEntry(Session.AppId, Message.GetDefault, source);
}
///
/// The application may obtain the first Source that are currently available on the system which
/// match the application’s supported groups.
///
/// The source.
///
public ReturnCode GetFirst(out TWIdentity source)
{
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.Identity, Message.GetFirst);
source = new TWIdentity();
return Dsm.DsmEntry(Session.AppId, Message.GetFirst, source);
}
///
/// The application may obtain the next Source that are currently available on the system which
/// match the application’s supported groups.
///
/// The source.
///
public ReturnCode GetNext(out TWIdentity source)
{
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.Identity, Message.GetNext);
source = new TWIdentity();
return Dsm.DsmEntry(Session.AppId, Message.GetNext, source);
}
///
/// Loads the specified Source into main memory and causes its initialization.
///
/// The source.
///
public ReturnCode OpenDS(TwainSource source)
{
Session.VerifyState(3, 3, DataGroups.Control, DataArgumentType.Identity, Message.OpenDS);
var rc = Dsm.DsmEntry(Session.AppId, Message.OpenDS, source.Identity);
if (rc == ReturnCode.Success)
{
Session.ChangeCurrentSource(source);
Session.ChangeState(4, true);
}
return rc;
}
///
/// It allows an application to set the
/// default TWAIN driver, which is reported back by GetDefault.
///
/// The source.
///
public ReturnCode Set(TWIdentity source)
{
Session.VerifyState(3, 3, DataGroups.Control, DataArgumentType.Identity, Message.Set);
return Dsm.DsmEntry(Session.AppId, Message.Set, source);
}
///
/// This operation should be invoked when the user chooses Select Source... from the application’s
/// File menu (or an equivalent user action). The Source selected becomes the system default Source.
///
/// The source.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "0#")]
public ReturnCode UserSelect(out TWIdentity source)
{
Session.VerifyState(3, 7, DataGroups.Control, DataArgumentType.Identity, Message.UserSelect);
source = new TWIdentity();
return Dsm.DsmEntry(Session.AppId, Message.UserSelect, source);
}
}
}