diff --git a/NTwain/ITwainOperation.cs b/NTwain/ITwainOperation.cs
index 367ab8e..6eab116 100644
--- a/NTwain/ITwainOperation.cs
+++ b/NTwain/ITwainOperation.cs
@@ -32,16 +32,16 @@ namespace NTwain
///
/// Opens the data source manager. This must be the first method used
- /// before using other TWAIN functions. Calls to this must be followed by when done with a TWAIN session.
+ /// before using other TWAIN functions. Calls to this must be followed by when done with a TWAIN session.
///
///
- ReturnCode OpenManager();
+ ReturnCode Open();
///
/// Closes the data source manager.
///
///
- ReturnCode CloseManager();
+ ReturnCode Close();
///
/// Forces the stepping down of an opened source when things gets out of control.
@@ -54,7 +54,7 @@ namespace NTwain
/// Gets list of sources available in the system.
///
///
- IList GetSources();
+ IEnumerable GetSources();
///
/// Gets the manager status. Only call this at state 2 or higher.
diff --git a/NTwain/Internals/TransferLogic.cs b/NTwain/Internals/TransferLogic.cs
index cb95201..67b8415 100644
--- a/NTwain/Internals/TransferLogic.cs
+++ b/NTwain/Internals/TransferLogic.cs
@@ -70,7 +70,7 @@ namespace NTwain.Internals
if (xferGroup == DataGroups.None ||
(xferGroup & DataGroups.Image) == DataGroups.Image)
{
- var mech = session.Source.GetCurrentCap(CapabilityId.ICapXferMech).ConvertToEnum();
+ var mech = session.Source.CapGetCurrent(CapabilityId.ICapXferMech).ConvertToEnum();
switch (mech)
{
case XferMech.Memory:
@@ -91,7 +91,7 @@ namespace NTwain.Internals
}
if ((xferGroup & DataGroups.Audio) == DataGroups.Audio)
{
- var mech = session.Source.GetCurrentCap(CapabilityId.ACapXferMech).ConvertToEnum();
+ var mech = session.Source.CapGetCurrent(CapabilityId.ACapXferMech).ConvertToEnum();
switch (mech)
{
case XferMech.File:
diff --git a/NTwain/TwainSession.cs b/NTwain/TwainSession.cs
index fbe2992..1bb5e01 100644
--- a/NTwain/TwainSession.cs
+++ b/NTwain/TwainSession.cs
@@ -145,44 +145,6 @@ namespace NTwain
}
}
-
- ///
- /// Gets list of sources available in the system.
- /// Only call this at state 2 or higher.
- ///
- /// The session.
- ///
- public IList GetSources()
- {
- List list = new List();
-
- // now enumerate
- TWIdentity srcId;
- var rc = DGControl.Identity.GetFirst(out srcId);
- if (rc == ReturnCode.Success) { list.Add(new TwainSource(this, srcId)); }
- do
- {
- rc = DGControl.Identity.GetNext(out srcId);
- if (rc == ReturnCode.Success)
- {
- list.Add(new TwainSource(this, srcId));
- }
- } while (rc == ReturnCode.Success);
-
- return list;
- }
- ///
- /// Gets the manager status. Only call this at state 2 or higher.
- ///
- /// The session.
- ///
- public TWStatus GetStatus()
- {
- TWStatus stat;
- DGControl.Status.GetManager(out stat);
- return stat;
- }
-
#endregion
#region ITwainOperation Members
@@ -238,6 +200,90 @@ namespace NTwain
return _dgCustom;
}
}
+ ///
+ /// Opens the data source manager. This must be the first method used
+ /// before using other TWAIN functions. Calls to this must be followed by when done with a TWAIN session.
+ ///
+ ///
+ public ReturnCode Open()
+ {
+ var rc = ReturnCode.Failure;
+ MessageLoop.Instance.Invoke(() =>
+ {
+ Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenManager.", Thread.CurrentThread.ManagedThreadId));
+
+ rc = DGControl.Parent.OpenDsm(MessageLoop.Instance.LoopHandle);
+ if (rc == ReturnCode.Success)
+ {
+ // if twain2 then get memory management functions
+ if ((_appId.DataFunctionalities & DataFunctionalities.Dsm2) == DataFunctionalities.Dsm2)
+ {
+ TWEntryPoint entry;
+ rc = DGControl.EntryPoint.Get(out entry);
+ if (rc == ReturnCode.Success)
+ {
+ Platform.MemoryManager = entry;
+ Debug.WriteLine("Using TWAIN2 memory functions.");
+ }
+ else
+ {
+ Close();
+ }
+ }
+ }
+ });
+ return rc;
+ }
+
+ ///
+ /// Closes the data source manager.
+ ///
+ ///
+ public ReturnCode Close()
+ {
+ var rc = ReturnCode.Failure;
+ MessageLoop.Instance.Invoke(() =>
+ {
+ Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CloseManager.", Thread.CurrentThread.ManagedThreadId));
+
+ rc = DGControl.Parent.CloseDsm(MessageLoop.Instance.LoopHandle);
+ if (rc == ReturnCode.Success)
+ {
+ Platform.MemoryManager = null;
+ }
+ });
+ return rc;
+ }
+
+
+ ///
+ /// Gets list of sources available in the system.
+ /// Only call this at state 2 or higher.
+ ///
+ /// The session.
+ ///
+ public IEnumerable GetSources()
+ {
+ TWIdentity srcId;
+ var rc = DGControl.Identity.GetFirst(out srcId);
+ while (rc == ReturnCode.Success)
+ {
+ yield return new TwainSource(this, srcId);
+ rc = DGControl.Identity.GetNext(out srcId);
+ }
+ }
+ ///
+ /// Gets the manager status. Only call this at state 2 or higher.
+ ///
+ /// The session.
+ ///
+ public TWStatus GetStatus()
+ {
+ TWStatus stat;
+ DGControl.Status.GetManager(out stat);
+ return stat;
+ }
+
#endregion
@@ -282,61 +328,6 @@ namespace NTwain
#region privileged calls that causes state change in TWAIN
- ///
- /// Opens the data source manager. This must be the first method used
- /// before using other TWAIN functions. Calls to this must be followed by when done with a TWAIN session.
- ///
- ///
- public ReturnCode OpenManager()
- {
- var rc = ReturnCode.Failure;
- MessageLoop.Instance.Invoke(() =>
- {
- Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenManager.", Thread.CurrentThread.ManagedThreadId));
-
- rc = DGControl.Parent.OpenDsm(MessageLoop.Instance.LoopHandle);
- if (rc == ReturnCode.Success)
- {
- // if twain2 then get memory management functions
- if ((_appId.DataFunctionalities & DataFunctionalities.Dsm2) == DataFunctionalities.Dsm2)
- {
- TWEntryPoint entry;
- rc = DGControl.EntryPoint.Get(out entry);
- if (rc == ReturnCode.Success)
- {
- Platform.MemoryManager = entry;
- Debug.WriteLine("Using TWAIN2 memory functions.");
- }
- else
- {
- CloseManager();
- }
- }
- }
- });
- return rc;
- }
-
- ///
- /// Closes the data source manager.
- ///
- ///
- public ReturnCode CloseManager()
- {
- var rc = ReturnCode.Failure;
- MessageLoop.Instance.Invoke(() =>
- {
- Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CloseManager.", Thread.CurrentThread.ManagedThreadId));
-
- rc = DGControl.Parent.CloseDsm(MessageLoop.Instance.LoopHandle);
- if (rc == ReturnCode.Success)
- {
- Platform.MemoryManager = null;
- }
- });
- return rc;
- }
-
///
/// Enables the source to start transferring.
@@ -459,13 +450,13 @@ namespace NTwain
{
((ITwainSessionInternal)this).DisableSource();
}
- if (targetState < 4)
+ if (targetState < 4 && Source != null)
{
Source.Close();
}
if (targetState < 3)
{
- CloseManager();
+ Close();
}
});
EnforceState = origFlag;
diff --git a/NTwain/TwainSource.Caps.cs b/NTwain/TwainSource.Caps.cs
index 6524666..d368f04 100644
--- a/NTwain/TwainSource.Caps.cs
+++ b/NTwain/TwainSource.Caps.cs
@@ -13,7 +13,7 @@ namespace NTwain
///
/// The cap identifier.
///
- public QuerySupport GetCapabilitySupport(CapabilityId capId)
+ public QuerySupport CapQuerySupport(CapabilityId capId)
{
QuerySupport retVal = QuerySupport.None;
using (TWCapability cap = new TWCapability(capId))
@@ -37,7 +37,7 @@ namespace NTwain
///
/// The cap id.
///
- public object GetCurrentCap(CapabilityId capId)
+ public object CapGetCurrent(CapabilityId capId)
{
using (TWCapability cap = new TWCapability(capId))
{
@@ -77,7 +77,7 @@ namespace NTwain
///
/// The capability unique identifier.
///
- public IList