mirror of
https://github.com/cyanfish/naps2.git
synced 2024-11-13 06:27:11 +03:00
Start adding form tests
This commit is contained in:
parent
656e07bd5a
commit
4e7c565b32
@ -12,6 +12,7 @@ using NAPS2.ImportExport.Pdf;
|
||||
using NAPS2.Ocr;
|
||||
using NAPS2.Operation;
|
||||
using NAPS2.Scan;
|
||||
using NAPS2.Scan.Batch;
|
||||
using NAPS2.Scan.Sane;
|
||||
using NAPS2.Scan.Twain;
|
||||
using NAPS2.Scan.Wia;
|
||||
@ -44,6 +45,7 @@ namespace NAPS2.Modules
|
||||
|
||||
// Scan
|
||||
Bind<IScanPerformer>().To<ScanPerformer>();
|
||||
Bind<IBatchScanPerformer>().To<BatchScanPerformer>();
|
||||
#if DEBUG && false
|
||||
Bind<IScanDriverFactory>().To<Scan.Stub.StubScanDriverFactory>();
|
||||
#else
|
||||
@ -57,6 +59,7 @@ namespace NAPS2.Modules
|
||||
|
||||
// Config
|
||||
Bind<ConfigScopes>().ToSelf().InSingletonScope();
|
||||
Bind<ScopeSetConfigProvider<CommonConfig>>().ToMethod(ctx => ctx.Kernel.Get<ConfigScopes>().Provider);
|
||||
Bind<ConfigProvider<CommonConfig>>().ToMethod(ctx => ctx.Kernel.Get<ConfigScopes>().Provider);
|
||||
Bind<ConfigProvider<PdfSettings>>().ToMethod(ctx => ctx.Kernel.Get<ConfigProvider<CommonConfig>>().Child(c => c.PdfSettings));
|
||||
Bind<ConfigProvider<ImageSettings>>().ToMethod(ctx => ctx.Kernel.Get<ConfigProvider<CommonConfig>>().Child(c => c.ImageSettings));
|
||||
|
@ -21,7 +21,7 @@ namespace NAPS2
|
||||
var form = kernel.Get<T>();
|
||||
form.FormFactory = kernel.Get<IFormFactory>();
|
||||
form.ConfigScopes = kernel.Get<ConfigScopes>();
|
||||
form.ConfigProvider = kernel.Get<ConfigProvider<CommonConfig>>();
|
||||
form.ConfigProvider = kernel.Get<ScopeSetConfigProvider<CommonConfig>>();
|
||||
return form;
|
||||
}
|
||||
}
|
||||
|
43
NAPS2.Sdk.Tests/Asserts/FormAsserts.cs
Normal file
43
NAPS2.Sdk.Tests/Asserts/FormAsserts.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using Xunit;
|
||||
|
||||
namespace NAPS2.Sdk.Tests.Asserts
|
||||
{
|
||||
public static class FormAsserts
|
||||
{
|
||||
public static void Visible(Control control)
|
||||
{
|
||||
Form form = null;
|
||||
for (var node = control; node != null; node = node.Parent)
|
||||
{
|
||||
if (node is Form f)
|
||||
{
|
||||
form = f;
|
||||
break;
|
||||
}
|
||||
Assert.True(node.Visible);
|
||||
}
|
||||
Assert.NotNull(form);
|
||||
}
|
||||
|
||||
public static void NotVisible(Control control)
|
||||
{
|
||||
Form form = null;
|
||||
bool someInvisible = false;
|
||||
for (var node = control; node != null; node = node.Parent)
|
||||
{
|
||||
if (node is Form f)
|
||||
{
|
||||
form = f;
|
||||
break;
|
||||
}
|
||||
someInvisible = someInvisible || !node.Visible;
|
||||
}
|
||||
Assert.True(someInvisible);
|
||||
Assert.NotNull(form);
|
||||
}
|
||||
}
|
||||
}
|
36
NAPS2.Sdk.Tests/Config/ConfigCopierTests.cs
Normal file
36
NAPS2.Sdk.Tests/Config/ConfigCopierTests.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NAPS2.Config.Experimental;
|
||||
using NAPS2.Scan;
|
||||
using Xunit;
|
||||
|
||||
namespace NAPS2.Sdk.Tests.Config
|
||||
{
|
||||
public class ConfigCopierTests
|
||||
{
|
||||
[Fact]
|
||||
public void Copies()
|
||||
{
|
||||
var src = new CommonConfig
|
||||
{
|
||||
Culture = "fr",
|
||||
PdfSettings =
|
||||
{
|
||||
DefaultFileName = "test_name"
|
||||
},
|
||||
DefaultProfileSettings = new ScanProfile
|
||||
{
|
||||
DriverName = "test_driver"
|
||||
}
|
||||
};
|
||||
var dst = new CommonConfig();
|
||||
ConfigCopier.Copy(src, dst);
|
||||
Assert.Equal("fr", dst.Culture);
|
||||
Assert.Equal("test_name", dst.PdfSettings.DefaultFileName);
|
||||
Assert.Equal("test_driver", dst.DefaultProfileSettings.DriverName);
|
||||
Assert.False(ReferenceEquals(src.PdfSettings, dst.PdfSettings));
|
||||
Assert.True(ReferenceEquals(src.DefaultProfileSettings, dst.DefaultProfileSettings));
|
||||
}
|
||||
}
|
||||
}
|
@ -70,6 +70,7 @@
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@ -90,9 +91,11 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Asserts\FormAsserts.cs" />
|
||||
<Compile Include="Asserts\ImageAsserts.cs" />
|
||||
<Compile Include="Asserts\PdfAsserts.cs" />
|
||||
<Compile Include="Config\CommonConfigTests.cs" />
|
||||
<Compile Include="Config\ConfigCopierTests.cs" />
|
||||
<Compile Include="Config\ConfigScopeTests.cs" />
|
||||
<Compile Include="Config\ProfileSerializerTests.cs" />
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
@ -119,6 +122,7 @@
|
||||
<Compile Include="Util\SliceTests.cs" />
|
||||
<Compile Include="Util\SslHelperTests.cs" />
|
||||
<Compile Include="Util\TestingContextTests.cs" />
|
||||
<Compile Include="WinForms\BatchFormTests.cs" />
|
||||
<Compile Include="Worker\WorkerChannelTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -199,6 +203,7 @@
|
||||
<ItemGroup>
|
||||
<None Include="Resources\color_image_s_n300.jpg" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
|
88
NAPS2.Sdk.Tests/WinForms/BatchFormTests.cs
Normal file
88
NAPS2.Sdk.Tests/WinForms/BatchFormTests.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NAPS2.Config;
|
||||
using NAPS2.Config.Experimental;
|
||||
using NAPS2.ImportExport;
|
||||
using NAPS2.Scan;
|
||||
using NAPS2.Scan.Batch;
|
||||
using NAPS2.Util;
|
||||
using NAPS2.WinForms;
|
||||
using Xunit;
|
||||
|
||||
namespace NAPS2.Sdk.Tests.WinForms
|
||||
{
|
||||
public class BatchFormTests : ContextualTexts
|
||||
{
|
||||
[Fact]
|
||||
public void LoadUserConfig()
|
||||
{
|
||||
var ctx = CreateForm();
|
||||
ctx.ConfigScopes.User.SetAll(new CommonConfig
|
||||
{
|
||||
BatchSettings =
|
||||
{
|
||||
OutputType = BatchOutputType.MultipleFiles,
|
||||
SaveSeparator = SaveSeparator.PatchT,
|
||||
ScanType = BatchScanType.MultipleWithDelay,
|
||||
SavePath = "test_path",
|
||||
ScanIntervalSeconds = 2.3,
|
||||
ScanCount = 2,
|
||||
ProfileDisplayName = "test_name"
|
||||
}
|
||||
});
|
||||
ProfileManager.Current.Profiles.Add(new ScanProfile
|
||||
{
|
||||
DisplayName = "bad_name",
|
||||
IsDefault = true
|
||||
});
|
||||
ProfileManager.Current.Profiles.Add(new ScanProfile {
|
||||
DisplayName = "test_name"
|
||||
});
|
||||
ctx.Form.Show();
|
||||
try
|
||||
{
|
||||
Assert.True(ctx.Form.rdSaveToMultipleFiles.Checked);
|
||||
Assert.True(ctx.Form.rdSeparateByPatchT.Checked);
|
||||
Assert.True(ctx.Form.rdMultipleScansDelay.Checked);
|
||||
Assert.Equal("test_path", ctx.Form.txtFilePath.Text);
|
||||
Assert.Equal("2.3", ctx.Form.txtTimeBetweenScans.Text);
|
||||
Assert.Equal("2", ctx.Form.txtNumberOfScans.Text);
|
||||
Assert.Equal("test_name", ctx.Form.comboProfile.Text);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ctx.Form.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private FormContext CreateForm()
|
||||
{
|
||||
var ctx = new FormContext();
|
||||
ctx.Performer = new Mock<IBatchScanPerformer>();
|
||||
ctx.ErrorOutput = new Mock<ErrorOutput>();
|
||||
ctx.DialogHelper = new Mock<DialogHelper>();
|
||||
ctx.ConfigScopes = ConfigScopes.Stub();
|
||||
ctx.Form = new FBatchScan(ctx.Performer.Object, ctx.ErrorOutput.Object, ctx.DialogHelper.Object)
|
||||
{
|
||||
ConfigScopes = ctx.ConfigScopes,
|
||||
ConfigProvider = ctx.ConfigScopes.Provider
|
||||
};
|
||||
return ctx;
|
||||
}
|
||||
|
||||
private class FormContext
|
||||
{
|
||||
public Mock<IBatchScanPerformer> Performer { get; set; }
|
||||
|
||||
public Mock<ErrorOutput> ErrorOutput { get; set; }
|
||||
|
||||
public Mock<DialogHelper> DialogHelper { get; set; }
|
||||
|
||||
public ConfigScopes ConfigScopes { get; set; }
|
||||
|
||||
public FBatchScan Form { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@ namespace NAPS2.Automation
|
||||
this.configScopes = configScopes;
|
||||
|
||||
userTransact = configScopes.User.BeginTransaction();
|
||||
configProvider = configScopes.WithTransactions(userTransact);
|
||||
configProvider = configScopes.Provider.Replace(configScopes.User, userTransact);
|
||||
pdfSettingsProvider = configProvider.Child(c => c.PdfSettings);
|
||||
imageSettingsProvider = configProvider.Child(c => c.ImageSettings);
|
||||
}
|
||||
|
@ -1,15 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using NAPS2.Util;
|
||||
|
||||
namespace NAPS2.Config.Experimental
|
||||
{
|
||||
public static class ConfigCopier
|
||||
{
|
||||
public static void Copy<T>(T src, T dst)
|
||||
private static readonly Dictionary<Type, (PropertyInfo, bool)[]> PropCache = new Dictionary<Type, (PropertyInfo, bool)[]>();
|
||||
|
||||
public static void Copy<T>(T src, T dst) =>
|
||||
Copy(src, dst, typeof(T));
|
||||
|
||||
private static void Copy(object src, object dst, Type t)
|
||||
{
|
||||
// TODO
|
||||
throw new NotImplementedException();
|
||||
(PropertyInfo, bool)[] GetPropData() => t.GetProperties()
|
||||
.Select(x => (x, IsChildProp(x))).ToArray();
|
||||
|
||||
foreach (var (prop, isChild) in PropCache.Get(t, GetPropData))
|
||||
{
|
||||
if (isChild)
|
||||
{
|
||||
Copy(prop.GetValue(src), prop.GetValue(dst), prop.PropertyType);
|
||||
}
|
||||
else
|
||||
{
|
||||
prop.SetValue(dst, prop.GetValue(src));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsChildProp(PropertyInfo x)
|
||||
{
|
||||
return x.GetCustomAttributes().Any(y => y is ChildAttribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,5 @@ namespace NAPS2.Config.Experimental
|
||||
|
||||
public static ConfigProvider<T> Child<TParent, T>(this ConfigProvider<TParent> parentProvider, Func<TParent, T> childSelector) =>
|
||||
new ChildConfigProvider<TParent,T>(parentProvider, childSelector);
|
||||
|
||||
public static ConfigProvider<CommonConfig> WithTransactions(this ConfigScopes configScopes, TransactionConfigScope<CommonConfig> userTransact = null, TransactionConfigScope<CommonConfig> runTransact = null) =>
|
||||
new ScopeSetConfigProvider<CommonConfig>(configScopes.AppLocked, runTransact ?? configScopes.Run, userTransact ?? configScopes.User, configScopes.AppDefault, configScopes.InternalDefault);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,15 @@ using System.Linq;
|
||||
|
||||
namespace NAPS2.Config.Experimental
|
||||
{
|
||||
public static class ConfigProvider
|
||||
{
|
||||
public static StubConfigProvider<T> Stub<T>(T value) =>
|
||||
new StubConfigProvider<T>(value);
|
||||
|
||||
public static ScopeSetConfigProvider<T> Set<T>(params ConfigScope<T>[] scopes) =>
|
||||
new ScopeSetConfigProvider<T>(scopes);
|
||||
}
|
||||
|
||||
// TODO: It is pretty ugly to have ConfigProvider<CommonConfig> everywhere.
|
||||
// TODO: Maybe a CommonConfigProvider subclass. Or maybe give in and remove generics.
|
||||
public abstract class ConfigProvider<TConfig>
|
||||
|
@ -1,9 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NAPS2.Serialization;
|
||||
|
||||
namespace NAPS2.Config.Experimental
|
||||
{
|
||||
public static class ConfigScope
|
||||
{
|
||||
public static ObjectConfigScope<T> Object<T>(T value) =>
|
||||
new ObjectConfigScope<T>(value, ConfigScopeMode.ReadWrite);
|
||||
|
||||
public static ObjectConfigScope<T> Object<T>(T value, ConfigScopeMode mode) =>
|
||||
new ObjectConfigScope<T>(value, mode);
|
||||
|
||||
public static FileConfigScope<T> File<T>(string filePath, Func<T> factory, ISerializer<T> serializer, ConfigScopeMode mode) =>
|
||||
new FileConfigScope<T>(filePath, factory, serializer, mode);
|
||||
}
|
||||
|
||||
public abstract class ConfigScope<TConfig>
|
||||
{
|
||||
protected ConfigScope(ConfigScopeMode mode)
|
||||
|
@ -23,18 +23,38 @@ namespace NAPS2.Config.Experimental
|
||||
set => _current = value;
|
||||
}
|
||||
|
||||
public static ConfigScopes Stub() =>
|
||||
new ConfigScopes(
|
||||
ConfigScope.Object(new CommonConfig()),
|
||||
ConfigScope.Object(new CommonConfig()),
|
||||
ConfigScope.Object(new CommonConfig()),
|
||||
ConfigScope.Object(new CommonConfig()),
|
||||
ConfigScope.Object(InternalDefaults.GetCommonConfig()));
|
||||
|
||||
public ConfigScopes(string appConfigPath, string userConfigPath)
|
||||
{
|
||||
AppLocked = new FileConfigScope<CommonConfig>(appConfigPath, CommonConfig.Create, new ConfigSerializer(ConfigReadMode.LockedOnly), ConfigScopeMode.ReadOnly);
|
||||
Run = new ObjectConfigScope<CommonConfig>(new CommonConfig(), ConfigScopeMode.ReadWrite);
|
||||
User = new FileConfigScope<CommonConfig>(userConfigPath, CommonConfig.Create, new ConfigSerializer(ConfigReadMode.All), ConfigScopeMode.ReadWrite);
|
||||
AppDefault = new FileConfigScope<CommonConfig>(appConfigPath, CommonConfig.Create, new ConfigSerializer(ConfigReadMode.DefaultOnly), ConfigScopeMode.ReadOnly);
|
||||
InternalDefault = new ObjectConfigScope<CommonConfig>(InternalDefaults.GetCommonConfig(), ConfigScopeMode.ReadOnly);
|
||||
AppLocked = ConfigScope.File(appConfigPath, CommonConfig.Create, new ConfigSerializer(ConfigReadMode.LockedOnly), ConfigScopeMode.ReadOnly);
|
||||
Run = ConfigScope.Object(new CommonConfig(), ConfigScopeMode.ReadWrite);
|
||||
User = ConfigScope.File(userConfigPath, CommonConfig.Create, new ConfigSerializer(ConfigReadMode.All), ConfigScopeMode.ReadWrite);
|
||||
AppDefault = ConfigScope.File(appConfigPath, CommonConfig.Create, new ConfigSerializer(ConfigReadMode.DefaultOnly), ConfigScopeMode.ReadOnly);
|
||||
InternalDefault = ConfigScope.Object(InternalDefaults.GetCommonConfig(), ConfigScopeMode.ReadOnly);
|
||||
|
||||
Provider = new ScopeSetConfigProvider<CommonConfig>(AppLocked, Run, User, AppDefault, InternalDefault);
|
||||
Provider = ConfigProvider.Set(AppLocked, Run, User, AppDefault, InternalDefault);
|
||||
}
|
||||
|
||||
public ConfigProvider<CommonConfig> Provider { get; }
|
||||
public ConfigScopes(ConfigScope<CommonConfig> appLocked, ConfigScope<CommonConfig> run, ConfigScope<CommonConfig> user,
|
||||
ConfigScope<CommonConfig> appDefault, ConfigScope<CommonConfig> internalDefault)
|
||||
{
|
||||
AppLocked = appLocked;
|
||||
Run = run;
|
||||
User = user;
|
||||
AppDefault = appDefault;
|
||||
InternalDefault = internalDefault;
|
||||
|
||||
Provider = ConfigProvider.Set(AppLocked, Run, User, AppDefault, InternalDefault);
|
||||
}
|
||||
|
||||
public ScopeSetConfigProvider<CommonConfig> Provider { get; }
|
||||
|
||||
public ConfigScope<CommonConfig> AppLocked { get; }
|
||||
public ConfigScope<CommonConfig> Run { get; }
|
||||
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
|
||||
namespace NAPS2.Config.Experimental
|
||||
{
|
||||
public class ScopeSetConfigProvider<TConfig> : ConfigProvider<TConfig> where TConfig : new()
|
||||
public class ScopeSetConfigProvider<TConfig> : ConfigProvider<TConfig>
|
||||
{
|
||||
private readonly ConfigScope<TConfig>[] scopes;
|
||||
|
||||
@ -13,6 +13,11 @@ namespace NAPS2.Config.Experimental
|
||||
this.scopes = scopes.ToArray();
|
||||
}
|
||||
|
||||
public ScopeSetConfigProvider(IEnumerable<ConfigScope<TConfig>> scopes)
|
||||
{
|
||||
this.scopes = scopes.ToArray();
|
||||
}
|
||||
|
||||
protected override T GetInternal<T>(Func<TConfig, T> func)
|
||||
{
|
||||
foreach (var scope in scopes)
|
||||
@ -26,5 +31,8 @@ namespace NAPS2.Config.Experimental
|
||||
// TODO: Consider throwing an exception
|
||||
return default;
|
||||
}
|
||||
|
||||
public ScopeSetConfigProvider<TConfig> Replace(ConfigScope<TConfig> original, ConfigScope<TConfig> replacement) =>
|
||||
new ScopeSetConfigProvider<TConfig>(scopes.Select(x => x == original ? replacement : x));
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ namespace NAPS2.Images
|
||||
if (outputSize == 0)
|
||||
{
|
||||
// TODO: Set this from the caller
|
||||
// outputSize = UserConfig.Current.ThumbnailSize;
|
||||
// outputSize = ConfigScopes.User.Current.ThumbnailSize;
|
||||
outputSize = 256;
|
||||
}
|
||||
using (var bitmap = await imageRenderer.Render(snapshot, snapshot.Metadata.TransformList.Count == 0 ? 0 : outputSize * OVERSAMPLE))
|
||||
|
@ -11,7 +11,7 @@ namespace NAPS2.Images.Transforms
|
||||
{
|
||||
// TODO: Set this from the clients
|
||||
Size = 256;
|
||||
//Size = UserConfig.Current.ThumbnailSize;
|
||||
//Size = ConfigScopes.User.Current.ThumbnailSize;
|
||||
}
|
||||
|
||||
public ThumbnailTransform(int size)
|
||||
|
@ -237,6 +237,7 @@
|
||||
<Compile Include="Recovery\RecoveryIndexSerializer.cs" />
|
||||
<Compile Include="Scan\Batch\BatchOutputType.cs" />
|
||||
<Compile Include="Scan\Batch\BatchScanType.cs" />
|
||||
<Compile Include="Scan\Batch\IBatchScanPerformer.cs" />
|
||||
<Compile Include="Scan\Exceptions\DriverNotSupportedException.cs" />
|
||||
<Compile Include="Images\ScannedImageSource.cs" />
|
||||
<Compile Include="Images\Storage\GdiTransformers.cs" />
|
||||
|
@ -20,7 +20,7 @@ using NAPS2.WinForms;
|
||||
|
||||
namespace NAPS2.Scan.Batch
|
||||
{
|
||||
public class BatchScanPerformer
|
||||
public class BatchScanPerformer : IBatchScanPerformer
|
||||
{
|
||||
private readonly IScanPerformer scanPerformer;
|
||||
private readonly PdfExporter pdfExporter;
|
||||
|
14
NAPS2.Sdk/Scan/Batch/IBatchScanPerformer.cs
Normal file
14
NAPS2.Sdk/Scan/Batch/IBatchScanPerformer.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NAPS2.Config.Experimental;
|
||||
using NAPS2.Images;
|
||||
using NAPS2.WinForms;
|
||||
|
||||
namespace NAPS2.Scan.Batch
|
||||
{
|
||||
public interface IBatchScanPerformer
|
||||
{
|
||||
Task PerformBatchScan(ConfigProvider<BatchSettings> settings, FormBase batchForm, Action<ScannedImage> imageCallback, Action<string> progressCallback, CancellationToken cancelToken);
|
||||
}
|
||||
}
|
70
NAPS2.Sdk/WinForms/FBatchScan.Designer.cs
generated
70
NAPS2.Sdk/WinForms/FBatchScan.Designer.cs
generated
@ -342,40 +342,40 @@ namespace NAPS2.WinForms
|
||||
|
||||
#endregion
|
||||
|
||||
private ILProfileIcons ilProfileIcons;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
|
||||
private System.Windows.Forms.Label lblStatus;
|
||||
private System.Windows.Forms.Button btnCancel;
|
||||
private System.Windows.Forms.Button btnStart;
|
||||
private System.Windows.Forms.GroupBox groupboxScanConfig;
|
||||
private System.Windows.Forms.Button btnAddProfile;
|
||||
private System.Windows.Forms.Button btnEditProfile;
|
||||
private System.Windows.Forms.ComboBox comboProfile;
|
||||
private System.Windows.Forms.Label lblProfile;
|
||||
private System.Windows.Forms.Panel panelScanType;
|
||||
private System.Windows.Forms.RadioButton rdMultipleScansDelay;
|
||||
private System.Windows.Forms.RadioButton rdSingleScan;
|
||||
private System.Windows.Forms.Panel panelScanDetails;
|
||||
private System.Windows.Forms.Label lblNumberOfScans;
|
||||
private System.Windows.Forms.TextBox txtNumberOfScans;
|
||||
private System.Windows.Forms.TextBox txtTimeBetweenScans;
|
||||
private System.Windows.Forms.Label lblTimeBetweenScans;
|
||||
private System.Windows.Forms.GroupBox groupboxOutput;
|
||||
private System.Windows.Forms.Panel panelSaveTo;
|
||||
private System.Windows.Forms.Button btnChooseFolder;
|
||||
private System.Windows.Forms.LinkLabel linkPlaceholders;
|
||||
private System.Windows.Forms.TextBox txtFilePath;
|
||||
private System.Windows.Forms.Label lblFilePath;
|
||||
private System.Windows.Forms.Panel panelSaveType;
|
||||
private System.Windows.Forms.RadioButton rdSaveToMultipleFiles;
|
||||
private System.Windows.Forms.RadioButton rdSaveToSingleFile;
|
||||
private System.Windows.Forms.RadioButton rdLoadIntoNaps2;
|
||||
private System.Windows.Forms.Panel panelSaveSeparator;
|
||||
private System.Windows.Forms.LinkLabel linkPatchCodeInfo;
|
||||
private System.Windows.Forms.RadioButton rdSeparateByPatchT;
|
||||
private System.Windows.Forms.RadioButton rdFilePerPage;
|
||||
private System.Windows.Forms.RadioButton rdFilePerScan;
|
||||
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
|
||||
private System.Windows.Forms.RadioButton rdMultipleScansPrompt;
|
||||
internal ILProfileIcons ilProfileIcons;
|
||||
internal System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
|
||||
internal System.Windows.Forms.Label lblStatus;
|
||||
internal System.Windows.Forms.Button btnCancel;
|
||||
internal System.Windows.Forms.Button btnStart;
|
||||
internal System.Windows.Forms.GroupBox groupboxScanConfig;
|
||||
internal System.Windows.Forms.Button btnAddProfile;
|
||||
internal System.Windows.Forms.Button btnEditProfile;
|
||||
internal System.Windows.Forms.ComboBox comboProfile;
|
||||
internal System.Windows.Forms.Label lblProfile;
|
||||
internal System.Windows.Forms.Panel panelScanType;
|
||||
internal System.Windows.Forms.RadioButton rdMultipleScansDelay;
|
||||
internal System.Windows.Forms.RadioButton rdSingleScan;
|
||||
internal System.Windows.Forms.Panel panelScanDetails;
|
||||
internal System.Windows.Forms.Label lblNumberOfScans;
|
||||
internal System.Windows.Forms.TextBox txtNumberOfScans;
|
||||
internal System.Windows.Forms.TextBox txtTimeBetweenScans;
|
||||
internal System.Windows.Forms.Label lblTimeBetweenScans;
|
||||
internal System.Windows.Forms.GroupBox groupboxOutput;
|
||||
internal System.Windows.Forms.Panel panelSaveTo;
|
||||
internal System.Windows.Forms.Button btnChooseFolder;
|
||||
internal System.Windows.Forms.LinkLabel linkPlaceholders;
|
||||
internal System.Windows.Forms.TextBox txtFilePath;
|
||||
internal System.Windows.Forms.Label lblFilePath;
|
||||
internal System.Windows.Forms.Panel panelSaveType;
|
||||
internal System.Windows.Forms.RadioButton rdSaveToMultipleFiles;
|
||||
internal System.Windows.Forms.RadioButton rdSaveToSingleFile;
|
||||
internal System.Windows.Forms.RadioButton rdLoadIntoNaps2;
|
||||
internal System.Windows.Forms.Panel panelSaveSeparator;
|
||||
internal System.Windows.Forms.LinkLabel linkPatchCodeInfo;
|
||||
internal System.Windows.Forms.RadioButton rdSeparateByPatchT;
|
||||
internal System.Windows.Forms.RadioButton rdFilePerPage;
|
||||
internal System.Windows.Forms.RadioButton rdFilePerScan;
|
||||
internal System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
|
||||
internal System.Windows.Forms.RadioButton rdMultipleScansPrompt;
|
||||
}
|
||||
}
|
||||
|
@ -23,14 +23,16 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
public const string PATCH_CODE_INFO_URL = "http://www.naps2.com/doc-batch-scan.html#patch-t";
|
||||
|
||||
private readonly BatchScanPerformer batchScanPerformer;
|
||||
private readonly IBatchScanPerformer batchScanPerformer;
|
||||
private readonly ErrorOutput errorOutput;
|
||||
private readonly DialogHelper dialogHelper;
|
||||
private TransactionConfigScope<CommonConfig> userTransact;
|
||||
private ConfigProvider<CommonConfig> transactProvider;
|
||||
|
||||
private bool batchRunning;
|
||||
private CancellationTokenSource cts = new CancellationTokenSource();
|
||||
|
||||
public FBatchScan(BatchScanPerformer batchScanPerformer, ErrorOutput errorOutput, DialogHelper dialogHelper)
|
||||
public FBatchScan(IBatchScanPerformer batchScanPerformer, ErrorOutput errorOutput, DialogHelper dialogHelper)
|
||||
{
|
||||
this.batchScanPerformer = batchScanPerformer;
|
||||
this.errorOutput = errorOutput;
|
||||
@ -42,8 +44,6 @@ namespace NAPS2.WinForms
|
||||
|
||||
public Action<ScannedImage> ImageCallback { get; set; }
|
||||
|
||||
private BatchSettings BatchSettings { get; set; }
|
||||
|
||||
protected override void OnLoad(object sender, EventArgs eventArgs)
|
||||
{
|
||||
new LayoutManager(this)
|
||||
@ -60,7 +60,8 @@ namespace NAPS2.WinForms
|
||||
ConditionalControls.LockHeight(this);
|
||||
|
||||
// TODO: Granular
|
||||
BatchSettings = ConfigProvider.Get(c => c.BatchSettings);
|
||||
userTransact = ConfigScopes.User.BeginTransaction();
|
||||
transactProvider = ConfigProvider.Replace(ConfigScopes.User, userTransact);
|
||||
UpdateUIFromSettings();
|
||||
}
|
||||
|
||||
@ -68,39 +69,39 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
UpdateProfiles();
|
||||
|
||||
rdSingleScan.Checked = BatchSettings.ScanType == BatchScanType.Single;
|
||||
rdMultipleScansPrompt.Checked = BatchSettings.ScanType == BatchScanType.MultipleWithPrompt;
|
||||
rdMultipleScansDelay.Checked = BatchSettings.ScanType == BatchScanType.MultipleWithDelay;
|
||||
rdSingleScan.Checked = transactProvider.Get(c => c.BatchSettings.ScanType) == BatchScanType.Single;
|
||||
rdMultipleScansPrompt.Checked = transactProvider.Get(c => c.BatchSettings.ScanType) == BatchScanType.MultipleWithPrompt;
|
||||
rdMultipleScansDelay.Checked = transactProvider.Get(c => c.BatchSettings.ScanType) == BatchScanType.MultipleWithDelay;
|
||||
|
||||
// TODO: Verify culture (+ vaildation ofc)
|
||||
txtNumberOfScans.Text = (BatchSettings.ScanCount ?? 1).ToString(CultureInfo.CurrentCulture);
|
||||
txtTimeBetweenScans.Text = (BatchSettings.ScanIntervalSeconds ?? 0).ToString(CultureInfo.CurrentCulture);
|
||||
txtNumberOfScans.Text = transactProvider.Get(c => c.BatchSettings.ScanCount).ToString(CultureInfo.CurrentCulture);
|
||||
txtTimeBetweenScans.Text = transactProvider.Get(c => c.BatchSettings.ScanIntervalSeconds).ToString(CultureInfo.CurrentCulture);
|
||||
|
||||
rdLoadIntoNaps2.Checked = BatchSettings.OutputType == BatchOutputType.Load;
|
||||
rdSaveToSingleFile.Checked = BatchSettings.OutputType == BatchOutputType.SingleFile;
|
||||
rdSaveToMultipleFiles.Checked = BatchSettings.OutputType == BatchOutputType.MultipleFiles;
|
||||
rdLoadIntoNaps2.Checked = transactProvider.Get(c => c.BatchSettings.OutputType) == BatchOutputType.Load;
|
||||
rdSaveToSingleFile.Checked = transactProvider.Get(c => c.BatchSettings.OutputType) == BatchOutputType.SingleFile;
|
||||
rdSaveToMultipleFiles.Checked = transactProvider.Get(c => c.BatchSettings.OutputType) == BatchOutputType.MultipleFiles;
|
||||
|
||||
rdFilePerScan.Checked = BatchSettings.SaveSeparator == SaveSeparator.FilePerScan;
|
||||
rdFilePerPage.Checked = BatchSettings.SaveSeparator == SaveSeparator.FilePerPage;
|
||||
rdSeparateByPatchT.Checked = BatchSettings.SaveSeparator == SaveSeparator.PatchT;
|
||||
rdFilePerScan.Checked = transactProvider.Get(c => c.BatchSettings.SaveSeparator) == SaveSeparator.FilePerScan;
|
||||
rdFilePerPage.Checked = transactProvider.Get(c => c.BatchSettings.SaveSeparator) == SaveSeparator.FilePerPage;
|
||||
rdSeparateByPatchT.Checked = transactProvider.Get(c => c.BatchSettings.SaveSeparator) == SaveSeparator.PatchT;
|
||||
|
||||
txtFilePath.Text = BatchSettings.SavePath;
|
||||
txtFilePath.Text = transactProvider.Get(c => c.BatchSettings.SavePath);
|
||||
}
|
||||
|
||||
private bool ValidateSettings()
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
BatchSettings.ProfileDisplayName = comboProfile.Text;
|
||||
userTransact.Set(c => c.BatchSettings.ProfileDisplayName = comboProfile.Text);
|
||||
if (comboProfile.SelectedIndex == -1)
|
||||
{
|
||||
ok = false;
|
||||
comboProfile.Focus();
|
||||
}
|
||||
|
||||
BatchSettings.ScanType = rdMultipleScansPrompt.Checked ? BatchScanType.MultipleWithPrompt
|
||||
userTransact.Set(c => c.BatchSettings.ScanType = rdMultipleScansPrompt.Checked ? BatchScanType.MultipleWithPrompt
|
||||
: rdMultipleScansDelay.Checked ? BatchScanType.MultipleWithDelay
|
||||
: BatchScanType.Single;
|
||||
: BatchScanType.Single);
|
||||
|
||||
if (rdMultipleScansDelay.Checked)
|
||||
{
|
||||
@ -110,7 +111,7 @@ namespace NAPS2.WinForms
|
||||
scanCount = 0;
|
||||
txtNumberOfScans.Focus();
|
||||
}
|
||||
BatchSettings.ScanCount = scanCount;
|
||||
userTransact.Set(c => c.BatchSettings.ScanCount = scanCount);
|
||||
|
||||
if (!double.TryParse(txtTimeBetweenScans.Text, out double scanInterval) || scanInterval < 0)
|
||||
{
|
||||
@ -118,19 +119,19 @@ namespace NAPS2.WinForms
|
||||
scanInterval = 0;
|
||||
txtTimeBetweenScans.Focus();
|
||||
}
|
||||
BatchSettings.ScanIntervalSeconds = scanInterval;
|
||||
userTransact.Set(c => c.BatchSettings.ScanIntervalSeconds = scanInterval);
|
||||
}
|
||||
|
||||
BatchSettings.OutputType = rdSaveToSingleFile.Checked ? BatchOutputType.SingleFile
|
||||
userTransact.Set(c => c.BatchSettings.OutputType = rdSaveToSingleFile.Checked ? BatchOutputType.SingleFile
|
||||
: rdSaveToMultipleFiles.Checked ? BatchOutputType.MultipleFiles
|
||||
: BatchOutputType.Load;
|
||||
: BatchOutputType.Load);
|
||||
|
||||
BatchSettings.SaveSeparator = rdFilePerScan.Checked ? SaveSeparator.FilePerScan
|
||||
userTransact.Set(c => c.BatchSettings.SaveSeparator = rdFilePerScan.Checked ? SaveSeparator.FilePerScan
|
||||
: rdSeparateByPatchT.Checked ? SaveSeparator.PatchT
|
||||
: SaveSeparator.FilePerPage;
|
||||
: SaveSeparator.FilePerPage);
|
||||
|
||||
BatchSettings.SavePath = txtFilePath.Text;
|
||||
if (BatchSettings.OutputType != BatchOutputType.Load && string.IsNullOrWhiteSpace(BatchSettings.SavePath))
|
||||
userTransact.Set(c => c.BatchSettings.SavePath = txtFilePath.Text);
|
||||
if (transactProvider.Get(c => c.BatchSettings.OutputType) != BatchOutputType.Load && string.IsNullOrWhiteSpace(transactProvider.Get(c => c.BatchSettings.SavePath)))
|
||||
{
|
||||
ok = false;
|
||||
txtFilePath.Focus();
|
||||
@ -143,10 +144,10 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
comboProfile.Items.Clear();
|
||||
comboProfile.Items.AddRange(ProfileManager.Current.Profiles.Cast<object>().ToArray());
|
||||
if (BatchSettings.ProfileDisplayName != null &&
|
||||
ProfileManager.Current.Profiles.Any(x => x.DisplayName == BatchSettings.ProfileDisplayName))
|
||||
if (!string.IsNullOrEmpty(transactProvider.Get(c => c.BatchSettings.ProfileDisplayName)) &&
|
||||
ProfileManager.Current.Profiles.Any(x => x.DisplayName == transactProvider.Get(c => c.BatchSettings.ProfileDisplayName)))
|
||||
{
|
||||
comboProfile.Text = BatchSettings.ProfileDisplayName;
|
||||
comboProfile.Text = transactProvider.Get(c => c.BatchSettings.ProfileDisplayName);
|
||||
}
|
||||
else if (ProfileManager.Current.DefaultProfile != null)
|
||||
{
|
||||
@ -216,7 +217,7 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
ProfileManager.Current.Profiles[comboProfile.SelectedIndex] = fedit.ScanProfile;
|
||||
ProfileManager.Current.Save();
|
||||
BatchSettings.ProfileDisplayName = fedit.ScanProfile.DisplayName;
|
||||
userTransact.Set(c => c.BatchSettings.ProfileDisplayName = fedit.ScanProfile.DisplayName);
|
||||
UpdateProfiles();
|
||||
}
|
||||
}
|
||||
@ -233,7 +234,7 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
ProfileManager.Current.Profiles.Add(fedit.ScanProfile);
|
||||
ProfileManager.Current.Save();
|
||||
BatchSettings.ProfileDisplayName = fedit.ScanProfile.DisplayName;
|
||||
userTransact.Set(c => c.BatchSettings.ProfileDisplayName = fedit.ScanProfile.DisplayName);
|
||||
UpdateProfiles();
|
||||
}
|
||||
}
|
||||
@ -264,7 +265,7 @@ namespace NAPS2.WinForms
|
||||
DoBatchScan().AssertNoAwait();
|
||||
|
||||
// Save settings for next time (could also do on form close)
|
||||
ConfigScopes.User.Set(c => c.BatchSettings = BatchSettings);
|
||||
userTransact.Commit();
|
||||
}
|
||||
|
||||
private void EnableDisableSettings(bool enabled)
|
||||
|
@ -35,7 +35,7 @@ namespace NAPS2.WinForms
|
||||
|
||||
userTransact = ConfigScopes.User.BeginTransaction();
|
||||
runTransact = ConfigScopes.Run.BeginTransaction();
|
||||
transactProvider = ConfigScopes.WithTransactions(userTransact, runTransact);
|
||||
transactProvider = ConfigProvider.Replace(ConfigScopes.User, userTransact).Replace(ConfigScopes.Run, runTransact);
|
||||
UpdateProvider();
|
||||
UpdateValues();
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ namespace NAPS2.WinForms
|
||||
|
||||
userTransact = ConfigScopes.User.BeginTransaction();
|
||||
runTransact = ConfigScopes.Run.BeginTransaction();
|
||||
transactProvider = ConfigScopes.WithTransactions(userTransact, runTransact);
|
||||
transactProvider = ConfigProvider.Replace(ConfigScopes.User, userTransact).Replace(ConfigScopes.Run, runTransact);
|
||||
UpdateValues();
|
||||
UpdateEnabled();
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace NAPS2.WinForms
|
||||
|
||||
userTransact = ConfigScopes.User.BeginTransaction();
|
||||
runTransact = ConfigScopes.Run.BeginTransaction();
|
||||
transactProvider = ConfigScopes.WithTransactions(userTransact, runTransact);
|
||||
transactProvider = ConfigProvider.Replace(ConfigScopes.User, userTransact).Replace(ConfigScopes.Run, runTransact);
|
||||
UpdateValues();
|
||||
UpdateEnabled();
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
comboName.Items.Clear();
|
||||
// TODO: Fix this (once we actually get around to implementing scanner sharing for real)
|
||||
//foreach (var proxyConfig in UserConfig.Current.SavedProxies.OrderBy(x => x.Name))
|
||||
//foreach (var proxyConfig in ConfigScopes.User.Current.SavedProxies.OrderBy(x => x.Name))
|
||||
//{
|
||||
// comboName.Items.Add(proxyConfig.Name);
|
||||
//}
|
||||
@ -82,7 +82,7 @@ namespace NAPS2.WinForms
|
||||
|
||||
private void comboName_SelectionChangeCommitted(object sender, EventArgs e)
|
||||
{
|
||||
//var savedProxies = UserConfig.Current.SavedProxies;
|
||||
//var savedProxies = ConfigScopes.User.Current.SavedProxies;
|
||||
//var proxyConfig = savedProxies.FirstOrDefault(x => x.Name == (string)comboName.SelectedItem);
|
||||
//if (proxyConfig != null)
|
||||
//{
|
||||
@ -93,7 +93,7 @@ namespace NAPS2.WinForms
|
||||
|
||||
private void comboName_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
//var savedProxies = UserConfig.Current.SavedProxies;
|
||||
//var savedProxies = ConfigScopes.User.Current.SavedProxies;
|
||||
//btnDelete.Enabled = savedProxies.Any(x => x.Name == comboName.Text);
|
||||
}
|
||||
|
||||
@ -131,10 +131,10 @@ namespace NAPS2.WinForms
|
||||
};
|
||||
if (!string.IsNullOrWhiteSpace(comboName.Text))
|
||||
{
|
||||
//var savedProxies = UserConfig.Current.SavedProxies;
|
||||
//var savedProxies = ConfigScopes.User.Current.SavedProxies;
|
||||
//savedProxies.RemoveAll(x => x.Name == ProxyConfig.Name);
|
||||
//savedProxies.Add(ProxyConfig);
|
||||
//UserConfig.Manager.Save();
|
||||
//ConfigScopes.User.Manager.Save();
|
||||
}
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
@ -144,9 +144,9 @@ namespace NAPS2.WinForms
|
||||
{
|
||||
if (MessageBox.Show(string.Format(MiscResources.ConfirmDelete, comboName.Text), MiscResources.Delete, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
|
||||
{
|
||||
//var savedProxies = UserConfig.Current.SavedProxies;
|
||||
//var savedProxies = ConfigScopes.User.Current.SavedProxies;
|
||||
//savedProxies.RemoveAll(x => x.Name == comboName.Text);
|
||||
//UserConfig.Manager.Save();
|
||||
//ConfigScopes.User.Manager.Save();
|
||||
|
||||
ProxyConfig = new ScanProxyConfig();
|
||||
UpdateDropdown();
|
||||
|
@ -10,7 +10,7 @@ using NAPS2.Util;
|
||||
|
||||
namespace NAPS2.WinForms
|
||||
{
|
||||
// TODO: Remove UserConfig dependency from reusable forms
|
||||
// TODO: Remove ConfigScopes.User dependency from reusable forms
|
||||
public class FormBase : Form, IInvoker
|
||||
{
|
||||
private bool loaded;
|
||||
@ -33,7 +33,7 @@ namespace NAPS2.WinForms
|
||||
|
||||
public ConfigScopes ConfigScopes { get; set; }
|
||||
|
||||
public ConfigProvider<CommonConfig> ConfigProvider { get; set; }
|
||||
public ScopeSetConfigProvider<CommonConfig> ConfigProvider { get; set; }
|
||||
|
||||
protected bool RestoreFormState { get; set; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user