From 49ee9b1079799fc1d2afdeaadb1741f709144366 Mon Sep 17 00:00:00 2001 From: Gerrit Date: Thu, 3 Aug 2023 10:34:31 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20Error=20Handling=20of=20Jo?= =?UTF-8?q?b=20Factory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Misc/JobFactory.cs | 2 +- .../Misc/VirtualTcpInputPrinter.cs | 25 +++++++++++-------- .../RegistryRepository.cs | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Common/AmagnoVirtualPrinter.Agent.Lib/Misc/JobFactory.cs b/Common/AmagnoVirtualPrinter.Agent.Lib/Misc/JobFactory.cs index f2938d8..1271159 100644 --- a/Common/AmagnoVirtualPrinter.Agent.Lib/Misc/JobFactory.cs +++ b/Common/AmagnoVirtualPrinter.Agent.Lib/Misc/JobFactory.cs @@ -147,7 +147,7 @@ namespace AmagnoVirtualPrinter.Agent.Lib.Misc var machine = job.MachineName?.TrimStart('\\'); var username = job.UserName; - LogDebug($"Searching for session of {domain}\\{username} on {machine} !"); + LogDebug($"Searching for session of {domain}\\{username} on {machine}!"); if (domain == null || machine == null || username == null) { diff --git a/Common/AmagnoVirtualPrinter.Agent.Lib/Misc/VirtualTcpInputPrinter.cs b/Common/AmagnoVirtualPrinter.Agent.Lib/Misc/VirtualTcpInputPrinter.cs index bdfc50e..b1a6ca1 100644 --- a/Common/AmagnoVirtualPrinter.Agent.Lib/Misc/VirtualTcpInputPrinter.cs +++ b/Common/AmagnoVirtualPrinter.Agent.Lib/Misc/VirtualTcpInputPrinter.cs @@ -30,7 +30,9 @@ namespace AmagnoVirtualPrinter.Agent.Lib.Misc [NotNull] private readonly IJobProcessor _jobProcessor; - private IDirectoryHelper _directoryHelper; + [NotNull] + private readonly IDirectoryHelper _directoryHelper; + private TcpListener _socket; private FileSystemWatcher _watcher; private string _outputDir; @@ -101,19 +103,20 @@ namespace AmagnoVirtualPrinter.Agent.Lib.Misc LogDebug($"{remote} --> {local}"); job = _jobFactory.Create(printer, client.GetStream()); - if (job == null) - { - LogError("Job could not be created."); - return; - } } - LogDebug($"Temporarily printed '{job.RawDataPath}'!"); socket.BeginAcceptTcpClient(HandleClient, ar.AsyncState); - - _jobService.Start(job); - - RestartFileWatcherIfNeeded(job.SessionInfo.Sid); + + if (job == null) + { + LogError("Job could not be created. Check your Printer Settings."); + } + else + { + LogDebug($"Temporarily printed '{job.RawDataPath}'!"); + _jobService.Start(job); + RestartFileWatcherIfNeeded(job.SessionInfo.Sid); + } } private void RestartFileWatcherIfNeeded(string sid) diff --git a/Common/AmagnoVirtualPrinter.Utils/RegistryRepository.cs b/Common/AmagnoVirtualPrinter.Utils/RegistryRepository.cs index bed3fed..b0f9663 100644 --- a/Common/AmagnoVirtualPrinter.Utils/RegistryRepository.cs +++ b/Common/AmagnoVirtualPrinter.Utils/RegistryRepository.cs @@ -97,7 +97,7 @@ namespace AmagnoVirtualPrinter.Utils } [ContractAnnotation("key:null => void")] - private void CheckForNull(RegistryKey key, string keyName) + private static void CheckForNull(RegistryKey key, string keyName) { if (key == null) {