v1.0.0 - Version, Ordner-Tab, Duplex, Dienst-Buttons, Passwort-Maskierung, README
This commit is contained in:
parent
a35b4ada20
commit
aa38762021
6 changed files with 208 additions and 57 deletions
|
|
@ -8,6 +8,9 @@
|
|||
<RootNamespace>MailPrint</RootNamespace>
|
||||
<AssemblyName>MailPrint</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<Version>1.0.0</Version>
|
||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||
<FileVersion>1.0.0.0</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ public class PrinterProfile
|
|||
public string PrinterName { get; set; } = "";
|
||||
public string PaperSource { get; set; } = "";
|
||||
public int Copies { get; set; } = 1;
|
||||
/// <summary>Leer = globale Liste verwenden. Gesetzt = überschreibt globale Liste.</summary>
|
||||
/// <summary>none | long | short</summary>
|
||||
public string Duplex { get; set; } = "none";
|
||||
public List<string> AllowedSenders { get; set; } = new();
|
||||
public List<string> BlockedSenders { get; set; } = new();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class PrintService
|
|||
try
|
||||
{
|
||||
for (int i = 0; i < copies; i++)
|
||||
PrintOnce(job.FilePath, printerName, paperSource);
|
||||
PrintOnce(job.FilePath, printerName, paperSource, profile.Duplex);
|
||||
_logger.LogInformation("Druck OK: {File}", job.FilePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -65,22 +65,14 @@ public class PrintService
|
|||
return _options.PrinterProfiles.FirstOrDefault() ?? new PrinterProfile();
|
||||
}
|
||||
|
||||
private void PrintOnce(string pdfPath, string printerName, string paperSource)
|
||||
private void PrintOnce(string pdfPath, string printerName, string paperSource, string duplex = "none")
|
||||
{
|
||||
if (string.IsNullOrEmpty(paperSource))
|
||||
var sumatra = ResolveSumatra();
|
||||
if (sumatra != null)
|
||||
{
|
||||
if (TryPrintViaSumatra(pdfPath, printerName)) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// SumatraPDF mit bin=<FachName>
|
||||
var sumatra = ResolveSumatra();
|
||||
if (sumatra != null)
|
||||
{
|
||||
RunAndWait(sumatra,
|
||||
$"-print-to \"{printerName}\" -print-settings \"bin={paperSource},noscale\" -silent \"{pdfPath}\"");
|
||||
return;
|
||||
}
|
||||
var settings = BuildPrintSettings(paperSource, duplex);
|
||||
RunAndWait(sumatra, $"-print-to \"{printerName}\" -print-settings \"{settings}\" -silent \"{pdfPath}\"");
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback Shell-Print
|
||||
|
|
@ -90,12 +82,12 @@ public class PrintService
|
|||
p.WaitForExit(30_000);
|
||||
}
|
||||
|
||||
private bool TryPrintViaSumatra(string pdfPath, string printerName)
|
||||
private static string BuildPrintSettings(string paperSource, string duplex)
|
||||
{
|
||||
var s = ResolveSumatra();
|
||||
if (s == null) return false;
|
||||
RunAndWait(s, $"-print-to \"{printerName}\" -print-settings \"noscale\" -silent \"{pdfPath}\"");
|
||||
return true;
|
||||
var parts = new List<string> { "noscale" };
|
||||
if (!string.IsNullOrEmpty(paperSource)) parts.Add($"bin={paperSource}");
|
||||
if (!string.IsNullOrEmpty(duplex) && duplex != "none") parts.Add($"duplex{duplex}");
|
||||
return string.Join(",", parts);
|
||||
}
|
||||
|
||||
private string? ResolveSumatra()
|
||||
|
|
@ -110,7 +102,7 @@ public class PrintService
|
|||
_logger.LogDebug("Exec: {Exe} {Args}", exe, args);
|
||||
var psi = new ProcessStartInfo(exe, args) { UseShellExecute = false, CreateNoWindow = true };
|
||||
using var p = Process.Start(psi) ?? throw new InvalidOperationException($"Nicht startbar: {exe}");
|
||||
if (!p.WaitForExit(60_000)) { p.Kill(); throw new TimeoutException($"Timeout: {exe}"); }
|
||||
if (!p.WaitForExit(300_000)) { p.Kill(); throw new TimeoutException($"Timeout: {exe}"); }
|
||||
if (p.ExitCode != 0) _logger.LogWarning("ExitCode {Code}: {Exe}", p.ExitCode, exe);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue