mirror of
https://github.com/soukoku/ntwain.git
synced 2025-04-05 20:59:23 +08:00
Added pluggable log (#44)
This commit is contained in:
parent
4356ed0615
commit
69d76569ff
@ -30,18 +30,18 @@ namespace Sample.WPF
|
|||||||
{
|
{
|
||||||
_twainVM = this.DataContext as TwainVM;
|
_twainVM = this.DataContext as TwainVM;
|
||||||
|
|
||||||
Messenger.Default.Register<RefreshCommandsMessage>(this, m => m.HandleRefreshCommands());
|
Messenger.Default.Register<RefreshCommandsMessage>(this, m => m.HandleIt());
|
||||||
Messenger.Default.Register<DialogMessage>(this, msg =>
|
Messenger.Default.Register<MessageBoxMessage>(this, msg =>
|
||||||
{
|
{
|
||||||
if (Dispatcher.CheckAccess())
|
if (Dispatcher.CheckAccess())
|
||||||
{
|
{
|
||||||
this.HandleDialogMessageModern(msg);
|
msg.HandleWithModern(this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Dispatcher.BeginInvoke(new Action(() =>
|
Dispatcher.BeginInvoke(new Action(() =>
|
||||||
{
|
{
|
||||||
this.HandleDialogMessageModern(msg);
|
msg.HandleWithModern(this);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -44,8 +44,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="CommonWin32, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a0a4edcfe233918d, processorArchitecture=MSIL">
|
<Reference Include="CommonWin32, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a0a4edcfe233918d, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<HintPath>..\..\packages\CommonWin32.2.0.5.6\lib\net35-Client\CommonWin32.dll</HintPath>
|
||||||
<HintPath>..\..\packages\CommonWin32.2.0.5.5\lib\net35-Client\CommonWin32.dll</HintPath>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="GalaSoft.MvvmLight, Version=5.1.1.35051, Culture=neutral, PublicKeyToken=0e453835af4ee6ce, processorArchitecture=MSIL">
|
<Reference Include="GalaSoft.MvvmLight, Version=5.1.1.35051, Culture=neutral, PublicKeyToken=0e453835af4ee6ce, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\MvvmLightLibs.5.1.1.0\lib\net40\GalaSoft.MvvmLight.dll</HintPath>
|
<HintPath>..\..\packages\MvvmLightLibs.5.1.1.0\lib\net40\GalaSoft.MvvmLight.dll</HintPath>
|
||||||
@ -70,11 +70,12 @@
|
|||||||
<HintPath>..\..\packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.ShellExtensions.dll</HintPath>
|
<HintPath>..\..\packages\Microsoft.WindowsAPICodePack-Shell.1.1.0.0\lib\Microsoft.WindowsAPICodePack.ShellExtensions.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="ModernWPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c99d0cfbea7491ef, processorArchitecture=MSIL">
|
<Reference Include="ModernWPF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c99d0cfbea7491ef, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\ModernWPF.1.2.10\lib\net40-Client\ModernWPF.dll</HintPath>
|
<HintPath>..\..\packages\ModernWPF.1.3.0\lib\net40-Client\ModernWPF.dll</HintPath>
|
||||||
<Private>True</Private>
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="ModernWPF.Mvvm">
|
<Reference Include="ModernWPF.Mvvm, Version=0.7.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\ModernWPF.Mvvm.0.7.0\lib\net40-Client\ModernWPF.Mvvm.dll</HintPath>
|
<HintPath>..\..\packages\ModernWPF.Mvvm.0.7.3\lib\net40-Client\ModernWPF.Mvvm.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
|
@ -225,7 +225,7 @@ namespace Sample.WPF
|
|||||||
{
|
{
|
||||||
if (e.Exception != null)
|
if (e.Exception != null)
|
||||||
{
|
{
|
||||||
Messenger.Default.Send(new DialogMessage(e.Exception.Message, null)
|
Messenger.Default.Send(new MessageBoxMessage (e.Exception.Message, null)
|
||||||
{
|
{
|
||||||
Caption = "Transfer Error Exception",
|
Caption = "Transfer Error Exception",
|
||||||
Icon = System.Windows.MessageBoxImage.Error,
|
Icon = System.Windows.MessageBoxImage.Error,
|
||||||
@ -234,7 +234,7 @@ namespace Sample.WPF
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Messenger.Default.Send(new DialogMessage(string.Format("Return Code: {0}\nCondition Code: {1}", e.ReturnCode, e.SourceStatus.ConditionCode), null)
|
Messenger.Default.Send(new MessageBoxMessage(string.Format("Return Code: {0}\nCondition Code: {1}", e.ReturnCode, e.SourceStatus.ConditionCode), null)
|
||||||
{
|
{
|
||||||
Caption = "Transfer Error",
|
Caption = "Transfer Error",
|
||||||
Icon = System.Windows.MessageBoxImage.Error,
|
Icon = System.Windows.MessageBoxImage.Error,
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="CommonServiceLocator" version="1.3" targetFramework="net40-Client" />
|
<package id="CommonServiceLocator" version="1.3" targetFramework="net4-client" userInstalled="true" />
|
||||||
<package id="CommonWin32" version="2.0.5.5" targetFramework="net40-Client" />
|
<package id="CommonWin32" version="2.0.5.6" targetFramework="net4-client" userInstalled="true" />
|
||||||
<package id="Microsoft.WindowsAPICodePack-Core" version="1.1.0.2" targetFramework="net40-Client" />
|
<package id="Microsoft.WindowsAPICodePack-Core" version="1.1.0.2" targetFramework="net4-client" userInstalled="true" />
|
||||||
<package id="Microsoft.WindowsAPICodePack-Shell" version="1.1.0.0" targetFramework="net40-Client" />
|
<package id="Microsoft.WindowsAPICodePack-Shell" version="1.1.0.0" targetFramework="net4-client" userInstalled="true" />
|
||||||
<package id="ModernWPF" version="1.2.10" targetFramework="net40-Client" />
|
<package id="ModernWPF" version="1.3.0" targetFramework="net4-client" userInstalled="true" />
|
||||||
<package id="ModernWPF.Mvvm" version="0.7.0" targetFramework="net40-Client" />
|
<package id="ModernWPF.Mvvm" version="0.7.3" targetFramework="net4-client" userInstalled="true" />
|
||||||
<package id="MvvmLightLibs" version="5.1.1.0" targetFramework="net40-Client" />
|
<package id="MvvmLightLibs" version="5.1.1.0" targetFramework="net4-client" userInstalled="true" />
|
||||||
</packages>
|
</packages>
|
@ -67,22 +67,22 @@ namespace Sample.Winform
|
|||||||
_twain = new TwainSession(appId);
|
_twain = new TwainSession(appId);
|
||||||
_twain.StateChanged += (s, e) =>
|
_twain.StateChanged += (s, e) =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine("State changed to " + _twain.State + " on thread " + Thread.CurrentThread.ManagedThreadId);
|
PlatformInfo.Current.Log.Info("State changed to " + _twain.State + " on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||||
};
|
};
|
||||||
_twain.TransferError += (s, e) =>
|
_twain.TransferError += (s, e) =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Got xfer error on thread " + Thread.CurrentThread.ManagedThreadId);
|
PlatformInfo.Current.Log.Info("Got xfer error on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||||
};
|
};
|
||||||
_twain.DataTransferred += (s, e) =>
|
_twain.DataTransferred += (s, e) =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Transferred data event on thread " + Thread.CurrentThread.ManagedThreadId);
|
PlatformInfo.Current.Log.Info("Transferred data event on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||||
|
|
||||||
// example on getting ext image info
|
// example on getting ext image info
|
||||||
var infos = e.GetExtImageInfo(ExtendedImageInfo.Camera).Where(it => it.ReturnCode == ReturnCode.Success);
|
var infos = e.GetExtImageInfo(ExtendedImageInfo.Camera).Where(it => it.ReturnCode == ReturnCode.Success);
|
||||||
foreach (var it in infos)
|
foreach (var it in infos)
|
||||||
{
|
{
|
||||||
var values = it.ReadValues();
|
var values = it.ReadValues();
|
||||||
Debug.WriteLine(string.Format("{0} = {1}", it.InfoID, values.FirstOrDefault()));
|
PlatformInfo.Current.Log.Info(string.Format("{0} = {1}", it.InfoID, values.FirstOrDefault()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ namespace Sample.Winform
|
|||||||
};
|
};
|
||||||
_twain.SourceDisabled += (s, e) =>
|
_twain.SourceDisabled += (s, e) =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Source disabled event on thread " + Thread.CurrentThread.ManagedThreadId);
|
PlatformInfo.Current.Log.Info("Source disabled event on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||||
this.BeginInvoke(new Action(() =>
|
this.BeginInvoke(new Action(() =>
|
||||||
{
|
{
|
||||||
btnStopScan.Enabled = false;
|
btnStopScan.Enabled = false;
|
||||||
@ -126,13 +126,13 @@ namespace Sample.Winform
|
|||||||
};
|
};
|
||||||
_twain.TransferReady += (s, e) =>
|
_twain.TransferReady += (s, e) =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Transferr ready event on thread " + Thread.CurrentThread.ManagedThreadId);
|
PlatformInfo.Current.Log.Info("Transferr ready event on thread " + Thread.CurrentThread.ManagedThreadId);
|
||||||
e.CancelAll = _stopScan;
|
e.CancelAll = _stopScan;
|
||||||
};
|
};
|
||||||
|
|
||||||
// either set sync context and don't worry about threads during events,
|
// either set sync context and don't worry about threads during events,
|
||||||
// or don't and use control.invoke during the events yourself
|
// or don't and use control.invoke during the events yourself
|
||||||
Debug.WriteLine("Setup thread = " + Thread.CurrentThread.ManagedThreadId);
|
PlatformInfo.Current.Log.Info("Setup thread = " + Thread.CurrentThread.ManagedThreadId);
|
||||||
_twain.SynchronizationContext = SynchronizationContext.Current;
|
_twain.SynchronizationContext = SynchronizationContext.Current;
|
||||||
if (_twain.State < 3)
|
if (_twain.State < 3)
|
||||||
{
|
{
|
||||||
|
@ -85,6 +85,9 @@
|
|||||||
<Compile Include="..\NTwain\IDataSource.cs">
|
<Compile Include="..\NTwain\IDataSource.cs">
|
||||||
<Link>IDataSource.cs</Link>
|
<Link>IDataSource.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="..\NTwain\ILog.cs">
|
||||||
|
<Link>ILog.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="..\NTwain\IMemoryManager.cs">
|
<Compile Include="..\NTwain\IMemoryManager.cs">
|
||||||
<Link>IMemoryManager.cs</Link>
|
<Link>IMemoryManager.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
@ -112,6 +115,9 @@
|
|||||||
<Compile Include="..\NTwain\Internals\TentativeStateCommitable.cs">
|
<Compile Include="..\NTwain\Internals\TentativeStateCommitable.cs">
|
||||||
<Link>Internals\TentativeStateCommitable.cs</Link>
|
<Link>Internals\TentativeStateCommitable.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="..\NTwain\Internals\TraceLog.cs">
|
||||||
|
<Link>Internals\TraceLog.cs</Link>
|
||||||
|
</Compile>
|
||||||
<Compile Include="..\NTwain\Internals\TransferLogic.cs">
|
<Compile Include="..\NTwain\Internals\TransferLogic.cs">
|
||||||
<Link>Internals\TransferLogic.cs</Link>
|
<Link>Internals\TransferLogic.cs</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -36,7 +36,7 @@ namespace NTwain
|
|||||||
var rc = ReturnCode.Failure;
|
var rc = ReturnCode.Failure;
|
||||||
_session.MessageLoopHook.Invoke(() =>
|
_session.MessageLoopHook.Invoke(() =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenSource.", Thread.CurrentThread.ManagedThreadId));
|
PlatformInfo.Current.Log.Debug("Thread {0}: OpenSource.", Thread.CurrentThread.ManagedThreadId);
|
||||||
|
|
||||||
rc = _session.DGControl.Identity.OpenDS(this);
|
rc = _session.DGControl.Identity.OpenDS(this);
|
||||||
_session.UpdateCallback();
|
_session.UpdateCallback();
|
||||||
@ -53,7 +53,7 @@ namespace NTwain
|
|||||||
var rc = ReturnCode.Failure;
|
var rc = ReturnCode.Failure;
|
||||||
_session.MessageLoopHook.Invoke(() =>
|
_session.MessageLoopHook.Invoke(() =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CloseSource.", Thread.CurrentThread.ManagedThreadId));
|
PlatformInfo.Current.Log.Debug("Thread {0}: CloseSource.", Thread.CurrentThread.ManagedThreadId);
|
||||||
|
|
||||||
rc = _session.DGControl.Identity.CloseDS();
|
rc = _session.DGControl.Identity.CloseDS();
|
||||||
//if (rc == ReturnCode.Success)
|
//if (rc == ReturnCode.Success)
|
||||||
|
83
src/NTwain/ILog.cs
Normal file
83
src/NTwain/ILog.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NTwain
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Simple log interface used by NTwain.
|
||||||
|
/// </summary>
|
||||||
|
public interface ILog
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether info messages will be logged.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> to enable info logging.
|
||||||
|
/// </value>
|
||||||
|
bool IsInfoEnabled { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether debug messages will be logged.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> to enable debug logging.
|
||||||
|
/// </value>
|
||||||
|
bool IsDebugEnabled { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether error messages will be logged.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// <c>true</c> to enable error logging.
|
||||||
|
/// </value>
|
||||||
|
bool IsErrorEnabled { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs info type message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message.</param>
|
||||||
|
void Info(string message);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs info type message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="messageFormat">The message format.</param>
|
||||||
|
/// <param name="args">The arguments.</param>
|
||||||
|
void Info(string messageFormat, params object[] args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs debug type message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message.</param>
|
||||||
|
void Debug(string message);
|
||||||
|
/// <summary>
|
||||||
|
/// Logs debug type message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="messageFormat">The message format.</param>
|
||||||
|
/// <param name="args">The arguments.</param>
|
||||||
|
void Debug(string messageFormat, params object[] args);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs error type message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message.</param>
|
||||||
|
void Error(string message);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs error type message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">The message.</param>
|
||||||
|
/// <param name="exception">The exception.</param>
|
||||||
|
void Error(string message, Exception exception);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Logs error type message.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="messageFormat">The message format.</param>
|
||||||
|
/// <param name="exception">The exception.</param>
|
||||||
|
/// <param name="args">The arguments.</param>
|
||||||
|
void Error(string messageFormat, Exception exception, params object[] args);
|
||||||
|
}
|
||||||
|
}
|
@ -86,5 +86,13 @@ namespace NTwain
|
|||||||
/// The memory manager.
|
/// The memory manager.
|
||||||
/// </value>
|
/// </value>
|
||||||
IMemoryManager MemoryManager { get; }
|
IMemoryManager MemoryManager { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the log used by NTwain.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The log.
|
||||||
|
/// </value>
|
||||||
|
ILog Log { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ namespace NTwain.Internals
|
|||||||
{
|
{
|
||||||
var loopThread = new Thread(new ThreadStart(() =>
|
var loopThread = new Thread(new ThreadStart(() =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine("NTwain message loop is starting.");
|
PlatformInfo.Current.Log.Debug("NTwain internal message loop is starting.");
|
||||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||||
if (!PlatformInfo.Current.IsOnMono)
|
if (!PlatformInfo.Current.IsOnMono)
|
||||||
{
|
{
|
||||||
|
82
src/NTwain/Internals/TraceLog.cs
Normal file
82
src/NTwain/Internals/TraceLog.cs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace NTwain.Internals
|
||||||
|
{
|
||||||
|
class TraceLog : ILog
|
||||||
|
{
|
||||||
|
public TraceLog()
|
||||||
|
{
|
||||||
|
IsInfoEnabled = true;
|
||||||
|
IsErrorEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsInfoEnabled { get; set; }
|
||||||
|
|
||||||
|
public bool IsDebugEnabled { get; set; }
|
||||||
|
|
||||||
|
public bool IsErrorEnabled { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public void Info(string message)
|
||||||
|
{
|
||||||
|
if (IsInfoEnabled && message != null)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Trace.WriteLine(message, "Info");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Info(string messageFormat, params object[] args)
|
||||||
|
{
|
||||||
|
Debug(string.Format(CultureInfo.CurrentCulture, messageFormat, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Debug(string message)
|
||||||
|
{
|
||||||
|
if (IsDebugEnabled && message != null)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Trace.WriteLine(message, "Debug");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Debug(string messageFormat, params object[] args)
|
||||||
|
{
|
||||||
|
Debug(string.Format(CultureInfo.CurrentCulture, messageFormat, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(string message)
|
||||||
|
{
|
||||||
|
if (IsErrorEnabled && message != null)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Trace.WriteLine(message, "Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(string message, Exception exception)
|
||||||
|
{
|
||||||
|
if (exception == null)
|
||||||
|
{
|
||||||
|
Error(message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Error(message + Environment.NewLine + exception.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Error(string messageFormat, Exception exception, params object[] args)
|
||||||
|
{
|
||||||
|
if (exception == null)
|
||||||
|
{
|
||||||
|
Error(string.Format(CultureInfo.CurrentCulture, messageFormat, args));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Error(string.Format(CultureInfo.CurrentCulture, messageFormat, args) + Environment.NewLine + exception.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -47,7 +47,6 @@ namespace NTwain.Internals
|
|||||||
}
|
}
|
||||||
if (!handled)
|
if (!handled)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Hwnd=" + hwnd);
|
|
||||||
handled = true;
|
handled = true;
|
||||||
// unnecessary to do default wndproc?
|
// unnecessary to do default wndproc?
|
||||||
return NativeMethods.DefWindowProc(hwnd, (uint)msg, wParam, lParam);
|
return NativeMethods.DefWindowProc(hwnd, (uint)msg, wParam, lParam);
|
||||||
|
@ -63,6 +63,8 @@
|
|||||||
<Compile Include="DeviceEventArgs.cs" />
|
<Compile Include="DeviceEventArgs.cs" />
|
||||||
<Compile Include="GlobalSuppressions.cs" />
|
<Compile Include="GlobalSuppressions.cs" />
|
||||||
<Compile Include="IDataSource.cs" />
|
<Compile Include="IDataSource.cs" />
|
||||||
|
<Compile Include="ILog.cs" />
|
||||||
|
<Compile Include="Internals\TraceLog.cs" />
|
||||||
<Compile Include="Internals\Extensions.cs" />
|
<Compile Include="Internals\Extensions.cs" />
|
||||||
<Compile Include="DataTransferredEventArgs.cs" />
|
<Compile Include="DataTransferredEventArgs.cs" />
|
||||||
<Compile Include="IMemoryManager.cs" />
|
<Compile Include="IMemoryManager.cs" />
|
||||||
|
@ -32,7 +32,7 @@ namespace NTwain
|
|||||||
IsOnMono = Type.GetType("Mono.Runtime") != null;
|
IsOnMono = Type.GetType("Mono.Runtime") != null;
|
||||||
IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
|
IsWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
|
||||||
IsLinux = Environment.OSVersion.Platform == PlatformID.Unix;
|
IsLinux = Environment.OSVersion.Platform == PlatformID.Unix;
|
||||||
|
_defaultLog = new TraceLog();
|
||||||
if (IsWindows)
|
if (IsWindows)
|
||||||
{
|
{
|
||||||
_defaultMemManager = new WinMemoryManager();
|
_defaultMemManager = new WinMemoryManager();
|
||||||
@ -84,7 +84,7 @@ namespace NTwain
|
|||||||
ExpectedDsmPath = newDsmPath;
|
ExpectedDsmPath = newDsmPath;
|
||||||
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
|
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
|
||||||
UseNewWinDSM = true;
|
UseNewWinDSM = true;
|
||||||
Debug.WriteLine("Using new dsm in windows.");
|
Log.Debug("Using new dsm in windows.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -92,14 +92,14 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
ExpectedDsmPath = newDsmPath;
|
ExpectedDsmPath = newDsmPath;
|
||||||
UseNewWinDSM = IsSupported = DsmExists = true;
|
UseNewWinDSM = IsSupported = DsmExists = true;
|
||||||
Debug.WriteLine("Using new dsm in windows.");
|
Log.Debug("Using new dsm in windows.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ExpectedDsmPath = oldDsmPath;
|
ExpectedDsmPath = oldDsmPath;
|
||||||
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
|
IsSupported = DsmExists = File.Exists(ExpectedDsmPath);
|
||||||
UseNewWinDSM = false;
|
UseNewWinDSM = false;
|
||||||
Debug.WriteLine("Using old dsm in windows.");
|
Log.Debug("Using old dsm in windows.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -186,13 +186,29 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_specifiedMemManager == null) { return _defaultMemManager; }
|
return _specifiedMemManager ?? _defaultMemManager;
|
||||||
return _specifiedMemManager;
|
|
||||||
}
|
}
|
||||||
internal set
|
internal set
|
||||||
{
|
{
|
||||||
_specifiedMemManager = value;
|
_specifiedMemManager = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
readonly ILog _defaultLog;
|
||||||
|
private ILog _log;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the log used by NTwain.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>
|
||||||
|
/// The log.
|
||||||
|
/// </value>
|
||||||
|
public ILog Log
|
||||||
|
{
|
||||||
|
get { return _log ?? _defaultLog; }
|
||||||
|
set { _log = value; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace NTwain
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The build release version number.
|
/// The build release version number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string Build = "3.3.4"; // change this for each nuget release
|
public const string Build = "3.3.5"; // change this for each nuget release
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ namespace NTwain
|
|||||||
DataSource GetSourceInstance(ITwainSessionInternal session, TWIdentity sourceId)
|
DataSource GetSourceInstance(ITwainSessionInternal session, TWIdentity sourceId)
|
||||||
{
|
{
|
||||||
DataSource source = null;
|
DataSource source = null;
|
||||||
Debug.WriteLine("Source id = " + sourceId.Id);
|
PlatformInfo.Current.Log.Debug("Source id = {0}", sourceId.Id);
|
||||||
var key = string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}|{3}", sourceId.Id, sourceId.Manufacturer, sourceId.ProductFamily, sourceId.ProductName);
|
var key = string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}|{3}", sourceId.Id, sourceId.Manufacturer, sourceId.ProductFamily, sourceId.ProductName);
|
||||||
if (_ownedSources.ContainsKey(key))
|
if (_ownedSources.ContainsKey(key))
|
||||||
{
|
{
|
||||||
@ -230,7 +230,7 @@ namespace NTwain
|
|||||||
var rc = ReturnCode.Failure;
|
var rc = ReturnCode.Failure;
|
||||||
_msgLoopHook.Invoke(() =>
|
_msgLoopHook.Invoke(() =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: OpenManager.", Thread.CurrentThread.ManagedThreadId));
|
PlatformInfo.Current.Log.Debug("Thread {0}: OpenManager.", Thread.CurrentThread.ManagedThreadId);
|
||||||
|
|
||||||
rc = ((ITwainSessionInternal)this).DGControl.Parent.OpenDsm(_msgLoopHook.Handle);
|
rc = ((ITwainSessionInternal)this).DGControl.Parent.OpenDsm(_msgLoopHook.Handle);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
@ -243,7 +243,7 @@ namespace NTwain
|
|||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
PlatformInfo.InternalCurrent.MemoryManager = entry;
|
PlatformInfo.InternalCurrent.MemoryManager = entry;
|
||||||
Debug.WriteLine("Using TWAIN2 memory functions.");
|
PlatformInfo.Current.Log.Debug("Using TWAIN2 memory functions.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -264,7 +264,7 @@ namespace NTwain
|
|||||||
var rc = ReturnCode.Failure;
|
var rc = ReturnCode.Failure;
|
||||||
_msgLoopHook.Invoke(() =>
|
_msgLoopHook.Invoke(() =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CloseManager.", Thread.CurrentThread.ManagedThreadId));
|
PlatformInfo.Current.Log.Debug("Thread {0}: CloseManager.", Thread.CurrentThread.ManagedThreadId);
|
||||||
|
|
||||||
rc = ((ITwainSessionInternal)this).DGControl.Parent.CloseDsm(_msgLoopHook.Handle);
|
rc = ((ITwainSessionInternal)this).DGControl.Parent.CloseDsm(_msgLoopHook.Handle);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
@ -360,7 +360,7 @@ namespace NTwain
|
|||||||
/// <param name="targetState">State of the target.</param>
|
/// <param name="targetState">State of the target.</param>
|
||||||
public void ForceStepDown(int targetState)
|
public void ForceStepDown(int targetState)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: ForceStepDown.", Thread.CurrentThread.ManagedThreadId));
|
PlatformInfo.Current.Log.Debug("Thread {0}: ForceStepDown.", Thread.CurrentThread.ManagedThreadId);
|
||||||
|
|
||||||
bool origFlag = EnforceState;
|
bool origFlag = EnforceState;
|
||||||
EnforceState = false;
|
EnforceState = false;
|
||||||
@ -462,7 +462,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("PropertyChanged event error: " + ex.ToString());
|
PlatformInfo.Current.Log.Error("PropertyChanged event error.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -476,7 +476,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("PropertyChanged event error: " + ex.ToString());
|
PlatformInfo.Current.Log.Error("PropertyChanged event error.", ex);
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
}
|
}
|
||||||
@ -533,7 +533,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(handler.Method.Name + " event error: " + ex.ToString());
|
PlatformInfo.Current.Log.Error("{0} event error.", ex, handler.Method.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -547,7 +547,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(handler.Method.Name + " event error: " + ex.ToString());
|
PlatformInfo.Current.Log.Error("{0} event error.", ex, handler.Method.Name);
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
}
|
}
|
||||||
@ -566,7 +566,7 @@ namespace NTwain
|
|||||||
var syncer = SynchronizationContext;
|
var syncer = SynchronizationContext;
|
||||||
if (syncer == null)
|
if (syncer == null)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Trying to raise event {0} on thread {1} without sync.", e.GetType().Name, Thread.CurrentThread.ManagedThreadId));
|
PlatformInfo.Current.Log.Debug("Trying to raise event {0} on thread {1} without sync.", e.GetType().Name, Thread.CurrentThread.ManagedThreadId);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -575,12 +575,12 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(handler.Method.Name + " event error: " + ex.ToString());
|
PlatformInfo.Current.Log.Error("{0} event error.", ex, handler.Method.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Trying to raise event {0} on thread {1} with sync.", e.GetType().Name, Thread.CurrentThread.ManagedThreadId));
|
PlatformInfo.Current.Log.Debug("Trying to raise event {0} on thread {1} with sync.", e.GetType().Name, Thread.CurrentThread.ManagedThreadId);
|
||||||
// on some consumer desktop scanner with poor drivers this can frequently hang. there's nothing I can do here.
|
// on some consumer desktop scanner with poor drivers this can frequently hang. there's nothing I can do here.
|
||||||
syncer.Send(o =>
|
syncer.Send(o =>
|
||||||
{
|
{
|
||||||
@ -591,7 +591,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(handler.Method.Name + " event error: " + ex.ToString());
|
PlatformInfo.Current.Log.Error("{0} event error.", ex, handler.Method.Name);
|
||||||
}
|
}
|
||||||
}, null);
|
}, null);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ namespace NTwain
|
|||||||
|
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Registered callback2 OK.");
|
PlatformInfo.Current.Log.Debug("Registered callback2 OK.");
|
||||||
_callbackObj = cb;
|
_callbackObj = cb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ namespace NTwain
|
|||||||
|
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Registered callback OK.");
|
PlatformInfo.Current.Log.Debug("Registered callback OK.");
|
||||||
_callbackObj = cb;
|
_callbackObj = cb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ namespace NTwain
|
|||||||
|
|
||||||
_msgLoopHook.Invoke(() =>
|
_msgLoopHook.Invoke(() =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: EnableSource with {1}.", Thread.CurrentThread.ManagedThreadId, mode));
|
PlatformInfo.Current.Log.Debug("Thread {0}: EnableSource with {1}.", Thread.CurrentThread.ManagedThreadId, mode);
|
||||||
|
|
||||||
|
|
||||||
_twui = new TWUserInterface();
|
_twui = new TWUserInterface();
|
||||||
@ -190,7 +190,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
_msgLoopHook.Invoke(() =>
|
_msgLoopHook.Invoke(() =>
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: DisableSource.", Thread.CurrentThread.ManagedThreadId));
|
PlatformInfo.Current.Log.Debug("Thread {0}: DisableSource.", Thread.CurrentThread.ManagedThreadId);
|
||||||
|
|
||||||
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.DisableDS(_twui);
|
rc = ((ITwainSessionInternal)this).DGControl.UserInterface.DisableDS(_twui);
|
||||||
if (rc == ReturnCode.Success)
|
if (rc == ReturnCode.Success)
|
||||||
@ -242,7 +242,7 @@ namespace NTwain
|
|||||||
evt.pEvent = msgPtr;
|
evt.pEvent = msgPtr;
|
||||||
if (handled = (((ITwainSessionInternal)this).DGControl.Event.ProcessEvent(evt) == ReturnCode.DSEvent))
|
if (handled = (((ITwainSessionInternal)this).DGControl.Event.ProcessEvent(evt) == ReturnCode.DSEvent))
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: HandleWndProcMessage at state {1} with MSG={2}.", Thread.CurrentThread.ManagedThreadId, State, evt.TWMessage));
|
PlatformInfo.Current.Log.Debug("Thread {0}: HandleWndProcMessage at state {1} with MSG={2}.", Thread.CurrentThread.ManagedThreadId, State, evt.TWMessage);
|
||||||
|
|
||||||
HandleSourceMsg(evt.TWMessage);
|
HandleSourceMsg(evt.TWMessage);
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ namespace NTwain
|
|||||||
{
|
{
|
||||||
if (origin != null && CurrentSource != null && origin.Id == CurrentSource.Identity.Id && _state >= 5)
|
if (origin != null && CurrentSource != null && origin.Id == CurrentSource.Identity.Id && _state >= 5)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "Thread {0}: CallbackHandler at state {1} with MSG={2}.", Thread.CurrentThread.ManagedThreadId, State, msg));
|
PlatformInfo.Current.Log.Debug("Thread {0}: CallbackHandler at state {1} with MSG={2}.", Thread.CurrentThread.ManagedThreadId, State, msg);
|
||||||
// spec says we must handle this on the thread that enabled the DS.
|
// spec says we must handle this on the thread that enabled the DS.
|
||||||
// by using the internal dispatcher this will be the case.
|
// by using the internal dispatcher this will be the case.
|
||||||
|
|
||||||
@ -282,6 +282,7 @@ namespace NTwain
|
|||||||
// final method that handles msg from the source, whether it's from wndproc or callbacks
|
// final method that handles msg from the source, whether it's from wndproc or callbacks
|
||||||
void HandleSourceMsg(Message msg)
|
void HandleSourceMsg(Message msg)
|
||||||
{
|
{
|
||||||
|
PlatformInfo.Current.Log.Debug("Got TWAIN msg " + msg);
|
||||||
switch (msg)
|
switch (msg)
|
||||||
{
|
{
|
||||||
case Message.XferReady:
|
case Message.XferReady:
|
||||||
@ -301,7 +302,6 @@ namespace NTwain
|
|||||||
break;
|
break;
|
||||||
case Message.CloseDSReq:
|
case Message.CloseDSReq:
|
||||||
case Message.CloseDSOK:
|
case Message.CloseDSOK:
|
||||||
Debug.WriteLine("Got msg " + msg);
|
|
||||||
// even though it says closeDS it's really disable.
|
// even though it says closeDS it's really disable.
|
||||||
// dsok is sent if source is enabled with uionly
|
// dsok is sent if source is enabled with uionly
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user