mirror of
https://github.com/soukoku/ntwain.git
synced 2025-11-24 08:47:06 +08:00
Added cap value report saver to wpf sample.
This commit is contained in:
@@ -44,7 +44,10 @@
|
|||||||
</ListBox.ItemTemplate>
|
</ListBox.ItemTemplate>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
|
||||||
<Label Content="Caps" Grid.Column="1"></Label>
|
<StackPanel Orientation="Horizontal" Grid.Column="1">
|
||||||
|
<Label Content="Caps" Grid.Column="1"></Label>
|
||||||
|
<Button Content="Save Reported" Command="{Binding SaveCapValuesCommand}" DataContext="{Binding SelectedSource}"></Button>
|
||||||
|
</StackPanel>
|
||||||
<TextBox Text="{Binding CapFilter, UpdateSourceTrigger=PropertyChanged}" DataContext="{Binding SelectedSource}"
|
<TextBox Text="{Binding CapFilter, UpdateSourceTrigger=PropertyChanged}" DataContext="{Binding SelectedSource}"
|
||||||
Grid.Column="1" Grid.Row="1"
|
Grid.Column="1" Grid.Row="1"
|
||||||
modern:TextBoxUI.WatermarkText="Find cap name"></TextBox>
|
modern:TextBoxUI.WatermarkText="Find cap name"></TextBox>
|
||||||
|
|||||||
@@ -34,10 +34,7 @@ namespace Sample.WPF
|
|||||||
Messenger.Default.Register<RefreshCommandsMessage>(this, m => m.HandleIt());
|
Messenger.Default.Register<RefreshCommandsMessage>(this, m => m.HandleIt());
|
||||||
Messenger.Default.Register<ChooseFileMessage>(this, m =>
|
Messenger.Default.Register<ChooseFileMessage>(this, m =>
|
||||||
{
|
{
|
||||||
if (m.Sender == DataContext)
|
|
||||||
{
|
|
||||||
m.HandleWithPlatform(this);
|
m.HandleWithPlatform(this);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
Messenger.Default.Register<MessageBoxMessage>(this, msg =>
|
Messenger.Default.Register<MessageBoxMessage>(this, msg =>
|
||||||
{
|
{
|
||||||
@@ -78,6 +75,7 @@ namespace Sample.WPF
|
|||||||
}
|
}
|
||||||
protected override void OnClosed(EventArgs e)
|
protected override void OnClosed(EventArgs e)
|
||||||
{
|
{
|
||||||
|
Messenger.Default.Unregister(this);
|
||||||
_twainVM.CloseDown();
|
_twainVM.CloseDown();
|
||||||
base.OnClosed(e);
|
base.OnClosed(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,8 +75,6 @@ namespace Sample.WPF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object MyProperty { get; set; }
|
|
||||||
|
|
||||||
public CapabilityId Cap { get; private set; }
|
public CapabilityId Cap { get; private set; }
|
||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
@@ -85,7 +83,7 @@ namespace Sample.WPF
|
|||||||
{
|
{
|
||||||
if (Cap > CapabilityId.CustomBase)
|
if (Cap > CapabilityId.CustomBase)
|
||||||
{
|
{
|
||||||
return "[Custom] " + ((int)Cap - (int)CapabilityId.CustomBase);
|
return "[CustomBase]+" + ((int)Cap - (int)CapabilityId.CustomBase);
|
||||||
}
|
}
|
||||||
return Cap.ToString();
|
return Cap.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
using GalaSoft.MvvmLight;
|
using GalaSoft.MvvmLight;
|
||||||
|
using GalaSoft.MvvmLight.Command;
|
||||||
|
using GalaSoft.MvvmLight.Messaging;
|
||||||
|
using ModernWpf.Messages;
|
||||||
using NTwain;
|
using NTwain;
|
||||||
using NTwain.Data;
|
using NTwain.Data;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace Sample.WPF
|
namespace Sample.WPF
|
||||||
{
|
{
|
||||||
@@ -69,5 +77,55 @@ namespace Sample.WPF
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ObservableCollection<CapVM> Caps { get; private set; }
|
public ObservableCollection<CapVM> Caps { get; private set; }
|
||||||
|
|
||||||
|
private ICommand _saveCapCommand;
|
||||||
|
|
||||||
|
public ICommand SaveCapValuesCommand
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _saveCapCommand ?? (_saveCapCommand = new RelayCommand(() =>
|
||||||
|
{
|
||||||
|
Messenger.Default.Send(new ChooseFileMessage(files =>
|
||||||
|
{
|
||||||
|
StringBuilder report = new StringBuilder();
|
||||||
|
report.Append("Cap values for TWAIN device ").AppendLine(DS.Name);
|
||||||
|
report.Append("Generated on ").AppendLine(DateTime.Now.ToString("yyyy/MM/dd hh:mm tt")).AppendLine();
|
||||||
|
|
||||||
|
foreach (CapVM cap in _capView)
|
||||||
|
{
|
||||||
|
report.Append(cap.Name).AppendLine(":");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
report.Append('\t').Append("Maybe: ").Append(cap.Supports).AppendLine();
|
||||||
|
report.Append('\t').Append("Get: ");
|
||||||
|
foreach (var v in cap.Get())
|
||||||
|
{
|
||||||
|
report.Append(v).Append(',');
|
||||||
|
}
|
||||||
|
report.AppendLine();
|
||||||
|
report.Append('\t').Append("Current: ").Append(cap.GetCurrent()).AppendLine();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
report.Append('\t').Append("Failed: ").Append(ex.Message).AppendLine();
|
||||||
|
}
|
||||||
|
report.AppendLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(files.First(), report.ToString());
|
||||||
|
|
||||||
|
using (Process.Start(files.First())) { }
|
||||||
|
})
|
||||||
|
{
|
||||||
|
Caption = "Choose Save File",
|
||||||
|
Filters = "Text files|*.txt",
|
||||||
|
InitialFileName = DS.Name + " capability",
|
||||||
|
Purpose = FilePurpose.Save,
|
||||||
|
});
|
||||||
|
}, () => DS.IsOpen));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using NTwain.Data;
|
using NTwain.Data;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -111,7 +112,9 @@ namespace NTwain
|
|||||||
if (!_supports.HasValue && _source.IsOpen)
|
if (!_supports.HasValue && _source.IsOpen)
|
||||||
{
|
{
|
||||||
var srcVersion = _source.ProtocolVersion;
|
var srcVersion = _source.ProtocolVersion;
|
||||||
if (srcVersion >= ProtocolVersions.GetMinimumVersion(Capability))
|
var minVer = ProtocolVersions.GetMinimumVersion(Capability);
|
||||||
|
|
||||||
|
if (srcVersion >= minVer)
|
||||||
{
|
{
|
||||||
_supports = _source.Capabilities.QuerySupport(Capability);
|
_supports = _source.Capabilities.QuerySupport(Capability);
|
||||||
|
|
||||||
@@ -137,6 +140,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("Cap " + Capability + " supports set to None due to rc=" + rc + ", cc=" + _source.GetStatus().ConditionCode);
|
||||||
_supports = QuerySupports.None;
|
_supports = QuerySupports.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,6 +148,7 @@ namespace NTwain
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("Cap " + Capability + " supports set to None due to not in required TWAIN version (" + minVer + ") not met by source (" + srcVersion + ").");
|
||||||
_supports = QuerySupports.None;
|
_supports = QuerySupports.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,12 +177,13 @@ namespace NTwain
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
ReturnCode SetValue(TValue value);/// <summary>
|
ReturnCode SetValue(TValue value);
|
||||||
///
|
|
||||||
/// A version of Set that uses an array.
|
/// <summary>
|
||||||
/// </summary>
|
/// A version of Set that uses an array.
|
||||||
/// <param name="value">The value.</param>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <param name="value">The value.</param>
|
||||||
|
/// <returns></returns>
|
||||||
ReturnCode SetValue(TWArray value);
|
ReturnCode SetValue(TWArray value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user