Create a NAPS2.Remoting namespace and sort out worker/clientserver types

This commit is contained in:
Ben Olden-Cooligan 2019-04-20 21:16:51 -04:00
parent 369637d1ef
commit 117041597f
32 changed files with 81 additions and 80 deletions

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NAPS2.ClientServer;
using NAPS2.Config.Experimental;
using NAPS2.Images;
using NAPS2.ImportExport;
@ -12,6 +11,8 @@ using NAPS2.ImportExport.Images;
using NAPS2.ImportExport.Pdf;
using NAPS2.Ocr;
using NAPS2.Operation;
using NAPS2.Remoting.ClientServer;
using NAPS2.Remoting.Worker;
using NAPS2.Scan;
using NAPS2.Scan.Batch;
using NAPS2.Scan.Sane;
@ -19,7 +20,6 @@ using NAPS2.Scan.Twain;
using NAPS2.Scan.Wia;
using NAPS2.Util;
using NAPS2.WinForms;
using NAPS2.Worker;
using Ninject;
using Ninject.Modules;
using ILogger = NAPS2.Logging.ILogger;

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using NAPS2.Automation;
using NAPS2.Modules;
using NAPS2.Worker;
using NAPS2.Remoting.Worker;
using Ninject;
using Ninject.Parameters;

View File

@ -5,12 +5,12 @@ using System.ServiceModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using NAPS2.ClientServer;
using NAPS2.Logging;
using NAPS2.Modules;
using NAPS2.Remoting.ClientServer;
using NAPS2.Remoting.Worker;
using NAPS2.Util;
using NAPS2.WinForms;
using NAPS2.Worker;
using Ninject;
namespace NAPS2.EntryPoints

View File

@ -6,9 +6,9 @@ using System.Threading.Tasks;
using System.Windows.Forms;
using NAPS2.Logging;
using NAPS2.Modules;
using NAPS2.Remoting.Worker;
using NAPS2.Util;
using NAPS2.WinForms;
using NAPS2.Worker;
using Ninject;
namespace NAPS2.EntryPoints

View File

@ -9,9 +9,10 @@ using System.Windows.Forms;
using Grpc.Core;
using NAPS2.Logging;
using NAPS2.Modules;
using NAPS2.Remoting;
using NAPS2.Remoting.Worker;
using NAPS2.Util;
using NAPS2.WinForms;
using NAPS2.Worker;
using Ninject;
namespace NAPS2.EntryPoints
@ -63,7 +64,7 @@ namespace NAPS2.EntryPoints
// Connect to the main NAPS2 process and listen for assigned work
Server server = new Server
{
Services = { GrpcWorkerService.BindService(kernel.Get<GrpcWorkerServiceImpl>()) },
Services = { GrpcWorkerService.BindService(kernel.Get<WorkerServiceImpl>()) },
Ports = { new ServerPort("localhost", 0, creds) }
};
server.Start();

View File

@ -9,11 +9,12 @@ using Moq;
using NAPS2.Images;
using NAPS2.Images.Storage;
using NAPS2.ImportExport.Email.Mapi;
using NAPS2.Remoting;
using NAPS2.Remoting.Worker;
using NAPS2.Scan;
using NAPS2.Scan.Exceptions;
using NAPS2.Scan.Twain;
using NAPS2.Util;
using NAPS2.Worker;
using Xunit;
namespace NAPS2.Sdk.Tests.Worker
@ -24,11 +25,11 @@ namespace NAPS2.Sdk.Tests.Worker
{
Server server = new Server
{
Services = { GrpcWorkerService.BindService(new GrpcWorkerServiceImpl(twainWrapper, thumbnailRenderer, mapiWrapper)) },
Services = { GrpcWorkerService.BindService(new WorkerServiceImpl(twainWrapper, thumbnailRenderer, mapiWrapper)) },
Ports = { new ServerPort("localhost", 0, serverCreds ?? ServerCredentials.Insecure) }
};
server.Start();
var client = new GrpcWorkerServiceAdapter(server.Ports.First().BoundPort, clientCreds ?? ChannelCredentials.Insecure);
var client = new WorkerServiceAdapter(server.Ports.First().BoundPort, clientCreds ?? ChannelCredentials.Insecure);
return new Channel
{
Server = server,
@ -182,7 +183,7 @@ namespace NAPS2.Sdk.Tests.Worker
{
public Server Server { get; set; }
public GrpcWorkerServiceAdapter Client { get; set; }
public WorkerServiceAdapter Client { get; set; }
public void Dispose()
{

View File

@ -6,8 +6,8 @@ using System.Threading.Tasks;
using NAPS2.Lang.Resources;
using NAPS2.Logging;
using NAPS2.Platform;
using NAPS2.Remoting.Worker;
using NAPS2.Util;
using NAPS2.Worker;
namespace NAPS2.ImportExport.Email.Mapi
{

View File

@ -139,14 +139,14 @@
<DesignTime>True</DesignTime>
<DependentUpon>ClientCreds.resx</DependentUpon>
</Compile>
<Compile Include="ClientServer\ClientContext.cs" />
<Compile Include="ClientServer\ClientContextFactory.cs" />
<Compile Include="ClientServer\IScanCallback.cs" />
<Compile Include="ClientServer\IScanService.cs" />
<Compile Include="ClientServer\ProxiedScanDriver.cs" />
<Compile Include="ClientServer\ScanCallback.cs" />
<Compile Include="ClientServer\ScanService.cs" />
<Compile Include="ClientServer\ServerDiscovery.cs" />
<Compile Include="Remoting\ClientServer\ClientContext.cs" />
<Compile Include="Remoting\ClientServer\ClientContextFactory.cs" />
<Compile Include="Remoting\ClientServer\IScanCallback.cs" />
<Compile Include="Remoting\ClientServer\IScanService.cs" />
<Compile Include="Remoting\ClientServer\ProxiedScanDriver.cs" />
<Compile Include="Remoting\ClientServer\ScanCallback.cs" />
<Compile Include="Remoting\ClientServer\ScanService.cs" />
<Compile Include="Remoting\ClientServer\ServerDiscovery.cs" />
<Compile Include="Config\Experimental\ChildAttribute.cs" />
<Compile Include="Config\Experimental\ConfigExtensions.cs" />
<Compile Include="Config\Experimental\ObsoleteTypes\ExtendedScanSettingsV0.cs" />
@ -298,7 +298,7 @@
<Compile Include="Util\ExpFallback.cs" />
<Compile Include="Util\NativeLibrary.cs" />
<Compile Include="WinForms\ImageClipboard.cs" />
<Compile Include="Worker\GrpcHelper.cs" />
<Compile Include="Remoting\GrpcHelper.cs" />
<Compile Include="Util\IInvoker.cs" />
<Compile Include="Util\ImageExtensions.cs" />
<Compile Include="Util\Invoker.cs" />
@ -349,9 +349,9 @@
<Compile Include="WinForms\BackgroundForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Worker\GrpcWorkerServiceImpl.cs" />
<Compile Include="Worker\GrpcWorkerServiceAdapter.cs" />
<Compile Include="Worker\WorkerContext.cs" />
<Compile Include="Remoting\Worker\WorkerServiceImpl.cs" />
<Compile Include="Remoting\Worker\WorkerServiceAdapter.cs" />
<Compile Include="Remoting\Worker\WorkerContext.cs" />
<Compile Include="Icons.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@ -444,7 +444,7 @@
</Compile>
<Compile Include="Util\ConditionalControls.cs" />
<Compile Include="Operation\IOperation.cs" />
<Compile Include="Worker\IWorkerServiceFactory.cs" />
<Compile Include="Remoting\Worker\IWorkerServiceFactory.cs" />
<Compile Include="Util\OverwritePrompt.cs" />
<Compile Include="Util\ISaveNotify.cs" />
<Compile Include="Util\Lifecycle.cs" />
@ -531,7 +531,7 @@
<Compile Include="Util\PathHelper.cs" />
<Compile Include="Util\Pipeline.cs" />
<Compile Include="Util\Pipes.cs" />
<Compile Include="Worker\ProcessJob.cs" />
<Compile Include="Remoting\Worker\ProcessJob.cs" />
<Compile Include="ImportExport\DirectImageTransfer.cs" />
<Compile Include="Util\KeyboardShortcutManager.cs" />
<Compile Include="Serialization\SecureStorage.cs" />
@ -541,7 +541,7 @@
<Compile Include="Util\Unmanaged.cs" />
<Compile Include="Util\UnmanagedArray.cs" />
<Compile Include="Util\UnmanagedBase.cs" />
<Compile Include="Worker\WorkerManager.cs" />
<Compile Include="Remoting\Worker\WorkerManager.cs" />
<Compile Include="Util\Win32.cs" />
<Compile Include="WinForms\DialogHelper.cs">
<SubType>Code</SubType>
@ -801,7 +801,7 @@
<Compile Include="WinForms\WinFormsOverwritePrompt.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Worker\WorkerServiceFactory.cs" />
<Compile Include="Remoting\Worker\WorkerServiceFactory.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ClientCreds.resx">
@ -6185,8 +6185,9 @@
<None Include="naps2-public.cer" />
<None Include="Icons\accept-small.png" />
<None Include="packages.config" />
<ProtoBuf Include="Serialization\common.proto" />
<Protobuf Include="Worker\worker.proto" />
<ProtoBuf Include="Remoting\Error.proto" />
<ProtoBuf Include="Serialization\SerializedImage.proto" />
<Protobuf Include="Remoting\Worker\WorkerService.proto" />
</ItemGroup>
<ItemGroup>
<None Include="Icons\accept.png" />

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.ServiceModel;
using NAPS2.Logging;
namespace NAPS2.ClientServer
namespace NAPS2.Remoting.ClientServer
{
public class ClientContext : IDisposable
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.ServiceModel;
using NAPS2.Scan;
namespace NAPS2.ClientServer
namespace NAPS2.Remoting.ClientServer
{
public class ClientContextFactory
{

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.ServiceModel;
using NAPS2.Recovery;
namespace NAPS2.ClientServer
namespace NAPS2.Remoting.ClientServer
{
[ServiceContract]
public interface IScanCallback

View File

@ -5,7 +5,7 @@ using System.ServiceModel;
using System.Threading.Tasks;
using NAPS2.Scan;
namespace NAPS2.ClientServer
namespace NAPS2.Remoting.ClientServer
{
[ServiceContract(CallbackContract = typeof(IScanCallback))]
public interface IScanService

View File

@ -3,14 +3,14 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NAPS2.Logging;
using NAPS2.Scan;
using NAPS2.Images;
using NAPS2.ImportExport;
using NAPS2.Logging;
using NAPS2.Scan;
using NAPS2.Util;
using NAPS2.WinForms;
namespace NAPS2.ClientServer
namespace NAPS2.Remoting.ClientServer
{
public class ProxiedScanDriver : ScanDriverBase
{

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using NAPS2.Recovery;
namespace NAPS2.ClientServer
namespace NAPS2.Remoting.ClientServer
{
public class ScanCallback : IScanCallback
{

View File

@ -10,7 +10,7 @@ using NAPS2.Scan.Sane;
using NAPS2.Scan.Twain;
using NAPS2.Scan.Wia;
namespace NAPS2.ClientServer
namespace NAPS2.Remoting.ClientServer
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession,
IncludeExceptionDetailInFaults = true,

View File

@ -8,7 +8,7 @@ using System.Text;
using System.Threading;
using NAPS2.Util;
namespace NAPS2.ClientServer
namespace NAPS2.Remoting.ClientServer
{
public class ServerDiscovery
{

View File

@ -0,0 +1,9 @@
syntax = "proto3";
package NAPS2.Remoting;
message Error {
string type = 1;
string message = 2;
string stackTrace = 3;
}

View File

@ -5,10 +5,9 @@ using System.Reflection;
using System.Threading.Tasks;
using Grpc.Core;
using NAPS2.Scan.Exceptions;
using NAPS2.Serialization;
using NAPS2.Util;
namespace NAPS2.Worker
namespace NAPS2.Remoting
{
public static class GrpcHelper
{

View File

@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
namespace NAPS2.Worker
namespace NAPS2.Remoting.Worker
{
/// <summary>
/// A factory interface to spawn NAPS2.Worker.exe instances as needed.

View File

@ -4,7 +4,7 @@ using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
namespace NAPS2.Worker
namespace NAPS2.Remoting.Worker
{
/// <summary>
/// A helper class to provide access to Job Objects. This is used to group NAPS2.Worker.exe processes with

View File

@ -2,17 +2,16 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using NAPS2.Logging;
namespace NAPS2.Worker
namespace NAPS2.Remoting.Worker
{
/// <summary>
/// A class storing the objects the client needs to use a NAPS2.Worker.exe instance.
/// </summary>
public class WorkerContext : IDisposable
{
public GrpcWorkerServiceAdapter Service { get; set; }
public WorkerServiceAdapter Service { get; set; }
public Process Process { get; set; }

View File

@ -5,14 +5,12 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Grpc.Core;
using NAPS2.Platform;
using NAPS2.Util;
namespace NAPS2.Worker
namespace NAPS2.Remoting.Worker
{
/// <summary>
/// A class to manage the lifecycle of NAPS2.Worker.exe instances and hook up the WCF channels.
@ -103,7 +101,7 @@ namespace NAPS2.Worker
{
var (proc, port, cert, privateKey) = StartWorkerProcess();
var creds = GrpcHelper.GetClientCreds(cert, privateKey);
_workerQueue.Add(new WorkerContext { Service = new GrpcWorkerServiceAdapter(port, creds), Process = proc });
_workerQueue.Add(new WorkerContext { Service = new WorkerServiceAdapter(port, creds), Process = proc });
});
}

View File

@ -1,8 +1,9 @@
syntax = "proto3";
package NAPS2.Worker;
package NAPS2.Remoting.Worker;
import "Serialization/common.proto";
import "Remoting/Error.proto";
import "Serialization/SerializedImage.proto";
service GrpcWorkerService {
rpc Init (InitRequest) returns (InitResponse) {}
@ -18,7 +19,7 @@ message InitRequest {
}
message InitResponse {
NAPS2.Serialization.Error error = 1;
NAPS2.Remoting.Error error = 1;
}
message Wia10NativeUiRequest {
@ -27,7 +28,7 @@ message Wia10NativeUiRequest {
}
message Wia10NativeUiResponse {
NAPS2.Serialization.Error error = 1;
NAPS2.Remoting.Error error = 1;
string wiaConfigurationXml = 2;
}
@ -36,7 +37,7 @@ message TwainGetDeviceListRequest {
}
message TwainGetDeviceListResponse {
NAPS2.Serialization.Error error = 1;
NAPS2.Remoting.Error error = 1;
string deviceListXml = 2;
}
@ -48,7 +49,7 @@ message TwainScanRequest {
}
message TwainScanResponse {
NAPS2.Serialization.Error error = 1;
NAPS2.Remoting.Error error = 1;
NAPS2.Serialization.SerializedImage image = 2;
}
@ -57,7 +58,7 @@ message SendMapiEmailRequest {
}
message SendMapiEmailResponse {
NAPS2.Serialization.Error error = 1;
NAPS2.Remoting.Error error = 1;
string returnCodeXml = 2;
}
@ -67,6 +68,6 @@ message RenderThumbnailRequest {
}
message RenderThumbnailResponse {
NAPS2.Serialization.Error error = 1;
NAPS2.Remoting.Error error = 1;
bytes thumbnail = 2;
}

View File

@ -10,15 +10,14 @@ using NAPS2.ImportExport.Email.Mapi;
using NAPS2.Scan;
using NAPS2.Scan.Wia;
using NAPS2.Serialization;
using NAPS2.Util;
namespace NAPS2.Worker
namespace NAPS2.Remoting.Worker
{
public class GrpcWorkerServiceAdapter
public class WorkerServiceAdapter
{
private readonly GrpcWorkerService.GrpcWorkerServiceClient client;
public GrpcWorkerServiceAdapter(int port, ChannelCredentials creds)
public WorkerServiceAdapter(int port, ChannelCredentials creds)
{
client = new GrpcWorkerService.GrpcWorkerServiceClient(new Channel("localhost", port, creds));
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.ServiceModel;
using NAPS2.Images.Storage;
namespace NAPS2.Worker
namespace NAPS2.Remoting.Worker
{
public class WorkerServiceFactory : IWorkerServiceFactory
{

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -17,9 +16,9 @@ using NAPS2.Scan.Wia.Native;
using NAPS2.Serialization;
using NAPS2.Util;
namespace NAPS2.Worker
namespace NAPS2.Remoting.Worker
{
public class GrpcWorkerServiceImpl : GrpcWorkerService.GrpcWorkerServiceBase
public class WorkerServiceImpl : GrpcWorkerService.GrpcWorkerServiceBase
{
private readonly ITwainWrapper twainWrapper;
private readonly ThumbnailRenderer thumbnailRenderer;
@ -27,7 +26,7 @@ namespace NAPS2.Worker
private CancellationTokenSource twainScanCts = new CancellationTokenSource();
public GrpcWorkerServiceImpl(ITwainWrapper twainWrapper, ThumbnailRenderer thumbnailRenderer, IMapiWrapper mapiWrapper)
public WorkerServiceImpl(ITwainWrapper twainWrapper, ThumbnailRenderer thumbnailRenderer, IMapiWrapper mapiWrapper)
{
this.twainWrapper = twainWrapper;
this.thumbnailRenderer = thumbnailRenderer;

View File

@ -6,8 +6,8 @@ using System.Threading.Tasks;
using NAPS2.Platform;
using NAPS2.Images;
using NAPS2.ImportExport;
using NAPS2.Remoting.Worker;
using NAPS2.Util;
using NAPS2.Worker;
namespace NAPS2.Scan.Twain
{

View File

@ -9,9 +9,9 @@ using NAPS2.Operation;
using NAPS2.Scan.Exceptions;
using NAPS2.Images;
using NAPS2.Images.Storage;
using NAPS2.Remoting.Worker;
using NAPS2.Scan.Wia.Native;
using NAPS2.Util;
using NAPS2.Worker;
namespace NAPS2.Scan.Wia
{

View File

@ -2,12 +2,6 @@
package NAPS2.Serialization;
message Error {
string type = 1;
string message = 2;
string stackTrace = 3;
}
message SerializedImage {
bool transferOwnership = 1;
oneof image {

View File

@ -27,10 +27,10 @@ using NAPS2.Recovery;
using NAPS2.Scan;
using NAPS2.Images;
using NAPS2.Images.Storage;
using NAPS2.Remoting.Worker;
using NAPS2.Scan.Wia.Native;
using NAPS2.Update;
using NAPS2.Util;
using NAPS2.Worker;
#endregion

View File

@ -3,11 +3,11 @@ using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using NAPS2.ClientServer;
using NAPS2.Config;
using NAPS2.Lang.Resources;
using NAPS2.Logging;
using NAPS2.Platform;
using NAPS2.Remoting.ClientServer;
using NAPS2.Scan;
using NAPS2.Scan.Exceptions;
using NAPS2.Scan.Sane;

View File

@ -4,9 +4,9 @@ using System.Globalization;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using NAPS2.ClientServer;
using NAPS2.Config;
using NAPS2.Lang.Resources;
using NAPS2.Remoting.ClientServer;
using NAPS2.Scan;
namespace NAPS2.WinForms