Some renames.

This commit is contained in:
soukoku
2014-05-19 21:26:44 -04:00
parent eb99616530
commit 9bf86464c8
9 changed files with 290 additions and 294 deletions

View File

@@ -32,16 +32,16 @@ namespace NTwain
/// <summary>
/// Opens the data source manager. This must be the first method used
/// before using other TWAIN functions. Calls to this must be followed by <see cref="CloseManager"/> when done with a TWAIN session.
/// before using other TWAIN functions. Calls to this must be followed by <see cref="Close"/> when done with a TWAIN session.
/// </summary>
/// <returns></returns>
ReturnCode OpenManager();
ReturnCode Open();
/// <summary>
/// Closes the data source manager.
/// </summary>
/// <returns></returns>
ReturnCode CloseManager();
ReturnCode Close();
/// <summary>
/// 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.
/// </summary>
/// <returns></returns>
IList<TwainSource> GetSources();
IEnumerable<TwainSource> GetSources();
/// <summary>
/// Gets the manager status. Only call this at state 2 or higher.

View File

@@ -70,7 +70,7 @@ namespace NTwain.Internals
if (xferGroup == DataGroups.None ||
(xferGroup & DataGroups.Image) == DataGroups.Image)
{
var mech = session.Source.GetCurrentCap(CapabilityId.ICapXferMech).ConvertToEnum<XferMech>();
var mech = session.Source.CapGetCurrent(CapabilityId.ICapXferMech).ConvertToEnum<XferMech>();
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<XferMech>();
var mech = session.Source.CapGetCurrent(CapabilityId.ACapXferMech).ConvertToEnum<XferMech>();
switch (mech)
{
case XferMech.File:

View File

@@ -145,44 +145,6 @@ namespace NTwain
}
}
/// <summary>
/// Gets list of sources available in the system.
/// Only call this at state 2 or higher.
/// </summary>
/// <param name="session">The session.</param>
/// <returns></returns>
public IList<TwainSource> GetSources()
{
List<TwainSource> list = new List<TwainSource>();
// 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;
}
/// <summary>
/// Gets the manager status. Only call this at state 2 or higher.
/// </summary>
/// <param name="session">The session.</param>
/// <returns></returns>
public TWStatus GetStatus()
{
TWStatus stat;
DGControl.Status.GetManager(out stat);
return stat;
}
#endregion
#region ITwainOperation Members
@@ -238,6 +200,90 @@ namespace NTwain
return _dgCustom;
}
}
/// <summary>
/// Opens the data source manager. This must be the first method used
/// before using other TWAIN functions. Calls to this must be followed by <see cref="Close"/> when done with a TWAIN session.
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// Closes the data source manager.
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// Gets list of sources available in the system.
/// Only call this at state 2 or higher.
/// </summary>
/// <param name="session">The session.</param>
/// <returns></returns>
public IEnumerable<TwainSource> 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);
}
}
/// <summary>
/// Gets the manager status. Only call this at state 2 or higher.
/// </summary>
/// <param name="session">The session.</param>
/// <returns></returns>
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
/// <summary>
/// Opens the data source manager. This must be the first method used
/// before using other TWAIN functions. Calls to this must be followed by <see cref="CloseManager"/> when done with a TWAIN session.
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// Closes the data source manager.
/// </summary>
/// <returns></returns>
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;
}
/// <summary>
/// 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;

View File

@@ -13,7 +13,7 @@ namespace NTwain
/// </summary>
/// <param name="capId">The cap identifier.</param>
/// <returns></returns>
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
/// </summary>
/// <param name="capId">The cap id.</param>
/// <returns></returns>
public object GetCurrentCap(CapabilityId capId)
public object CapGetCurrent(CapabilityId capId)
{
using (TWCapability cap = new TWCapability(capId))
{
@@ -77,7 +77,7 @@ namespace NTwain
/// </summary>
/// <param name="capabilityId">The capability unique identifier.</param>
/// <returns></returns>
public IList<object> GetCapabilityValues(CapabilityId capabilityId)
public IList<object> CapGetValues(CapabilityId capabilityId)
{
var list = new List<object>();
using (TWCapability cap = new TWCapability(capabilityId))
@@ -100,9 +100,7 @@ namespace NTwain
/// <returns></returns>
public IList<XferMech> CapGetImageXferMech()
{
return GetCapabilityValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
return CapGetValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
}
#endregion
@@ -116,7 +114,7 @@ namespace NTwain
/// <returns></returns>
public IList<CompressionType> CapGetCompression()
{
return GetCapabilityValues(CapabilityId.ICapCompression).CastToEnum<CompressionType>(true);
return CapGetValues(CapabilityId.ICapCompression).CastToEnum<CompressionType>(true);
}
/// <summary>
@@ -143,7 +141,7 @@ namespace NTwain
/// <returns></returns>
public IList<FileFormat> CapGetImageFileFormat()
{
return GetCapabilityValues(CapabilityId.ICapImageFileFormat).CastToEnum<FileFormat>(true);
return CapGetValues(CapabilityId.ICapImageFileFormat).CastToEnum<FileFormat>(true);
}
/// <summary>
@@ -170,7 +168,7 @@ namespace NTwain
/// <returns></returns>
public IList<PixelType> CapGetPixelTypes()
{
return GetCapabilityValues(CapabilityId.ICapPixelType).CastToEnum<PixelType>(true);
return CapGetValues(CapabilityId.ICapPixelType).CastToEnum<PixelType>(true);
}
/// <summary>
@@ -200,7 +198,7 @@ namespace NTwain
/// <returns></returns>
public IList<XferMech> CapGetImageXferMechs()
{
return GetCapabilityValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
return CapGetValues(CapabilityId.ICapXferMech).CastToEnum<XferMech>(true);
}
/// <summary>
@@ -210,7 +208,7 @@ namespace NTwain
/// <returns></returns>
public IList<XferMech> CapGetAudioXferMechs()
{
return GetCapabilityValues(CapabilityId.ACapXferMech).CastToEnum<XferMech>(true);
return CapGetValues(CapabilityId.ACapXferMech).CastToEnum<XferMech>(true);
}
/// <summary>
@@ -256,7 +254,7 @@ namespace NTwain
/// <returns></returns>
public IList<TWFix32> CapGetDPIs()
{
var list = GetCapabilityValues(CapabilityId.ICapXResolution);
var list = CapGetValues(CapabilityId.ICapXResolution);
return list.Select(o => o.ConvertToFix32()).ToList();
}
@@ -308,7 +306,7 @@ namespace NTwain
/// <returns></returns>
public IList<SupportedSize> CapGetSupportedSizes()
{
return GetCapabilityValues(CapabilityId.ICapSupportedSizes).CastToEnum<SupportedSize>(true);
return CapGetValues(CapabilityId.ICapSupportedSizes).CastToEnum<SupportedSize>(true);
}
/// <summary>

View File

@@ -11,6 +11,9 @@ using System.Threading;
namespace NTwain
{
/// <summary>
/// Represents a TWAIN data source.
/// </summary>
public partial class TwainSource : INotifyPropertyChanged
{
ITwainSessionInternal _session;
@@ -82,6 +85,8 @@ namespace NTwain
return stat;
}
#region properties
internal TWIdentity Identity { get; private set; }
/// <summary>
@@ -156,7 +161,7 @@ namespace NTwain
{
if (_supportedCaps == null && _session.State > 3)
{
_supportedCaps = GetCapabilityValues(CapabilityId.CapSupportedCaps).CastToEnum<CapabilityId>(false);
_supportedCaps = CapGetValues(CapabilityId.CapSupportedCaps).CastToEnum<CapabilityId>(false);
}
return _supportedCaps ?? _emptyCapList;
}
@@ -167,6 +172,8 @@ namespace NTwain
}
}
#endregion
#region INotifyPropertyChanged Members
/// <summary>