Added cap value report saver to wpf sample.

This commit is contained in:
Eugene Wang
2017-02-03 07:06:44 -05:00
parent 676a4c640a
commit 24bd82670a
6 changed files with 77 additions and 14 deletions

View File

@@ -75,8 +75,6 @@ namespace Sample.WPF
}
}
public object MyProperty { get; set; }
public CapabilityId Cap { get; private set; }
public string Name
@@ -85,7 +83,7 @@ namespace Sample.WPF
{
if (Cap > CapabilityId.CustomBase)
{
return "[Custom] " + ((int)Cap - (int)CapabilityId.CustomBase);
return "[CustomBase]+" + ((int)Cap - (int)CapabilityId.CustomBase);
}
return Cap.ToString();
}

View File

@@ -1,11 +1,19 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using ModernWpf.Messages;
using NTwain;
using NTwain.Data;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Input;
namespace Sample.WPF
{
@@ -69,5 +77,55 @@ namespace Sample.WPF
}
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));
}
}
}
}