Compare commits

..

No commits in common. "main" and "v1.0.0" have entirely different histories.
main ... v1.0.0

9 changed files with 35 additions and 117 deletions

1
.gitignore vendored
View file

@ -2,7 +2,6 @@
bin/
obj/
publish/
*.zip
# Skripte aus publish/ im Root behalten
!install-service.ps1

View file

@ -1,22 +0,0 @@
<Project>
<PropertyGroup>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<!-- Version aus Git-Tag lesen: git tag v1.2.3 → Version 1.2.3 -->
<GitVersion Condition="'$(GitVersion)' == ''">$([System.String]::Copy('1.0.0'))</GitVersion>
</PropertyGroup>
<Target Name="SetVersionFromGit" BeforeTargets="GetAssemblyVersion;Build;Publish">
<Exec Command="git describe --tags --abbrev=0 2&gt;nul" ConsoleToMSBuild="true" IgnoreExitCode="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitTagRaw" />
</Exec>
<PropertyGroup>
<!-- v1.2.3 → 1.2.3 -->
<GitTagClean>$(GitTagRaw.TrimStart('v').Trim())</GitTagClean>
<Version Condition="'$(GitTagClean)' != ''">$(GitTagClean)</Version>
<AssemblyVersion Condition="'$(GitTagClean)' != ''">$(GitTagClean).0</AssemblyVersion>
<FileVersion Condition="'$(GitTagClean)' != ''">$(GitTagClean).0</FileVersion>
</PropertyGroup>
<Message Text="Build-Version: $(Version)" Importance="high" />
</Target>
</Project>

View file

@ -8,10 +8,9 @@
<RootNamespace>MailPrint</RootNamespace>
<AssemblyName>MailPrint</AssemblyName>
<OutputType>Exe</OutputType>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<Version>1.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>

View file

@ -51,34 +51,7 @@ try
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new() { Title = "MailPrint API", Version = "v1" });
// XML-Doku aus /// Kommentaren in OpenAPI uebernehmen
var xmlPath = Path.Combine(AppContext.BaseDirectory, "MailPrint.xml");
if (File.Exists(xmlPath))
c.IncludeXmlComments(xmlPath);
// API-Key-Security im Schema dokumentieren -> generierte Clients
// setzen den Header automatisch, Swagger UI hat Authorize-Button
var scheme = new Microsoft.OpenApi.Models.OpenApiSecurityScheme
{
Name = "X-Api-Key",
Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey,
In = Microsoft.OpenApi.Models.ParameterLocation.Header,
Description = "API-Key fuer alle /api/* Endpunkte. Konfiguriert in MailPrintConfig.",
Reference = new Microsoft.OpenApi.Models.OpenApiReference
{
Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme,
Id = "ApiKey"
}
};
c.AddSecurityDefinition("ApiKey", scheme);
c.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement
{
[scheme] = Array.Empty<string>()
});
});
c.SwaggerDoc("v1", new() { Title = "MailPrint API", Version = "v1" }));
var app = builder.Build();
app.UseSwagger();

View file

@ -8,14 +8,13 @@
<UseWindowsForms>true</UseWindowsForms>
<RootNamespace>MailPrintConfig</RootNamespace>
<AssemblyName>MailPrintConfig</AssemblyName>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>1.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.1" />
</ItemGroup>
</Project>

View file

@ -491,17 +491,6 @@ public class MainForm : Form
?? Path.Combine(AppContext.BaseDirectory, "appsettings.json");
}
private static bool IsServiceRunning()
{
try
{
var svc = System.ServiceProcess.ServiceController.GetServices()
.FirstOrDefault(s => s.ServiceName == ServiceName);
return svc?.Status == System.ServiceProcess.ServiceControllerStatus.Running;
}
catch { return false; }
}
private void BrowseFolder(int rowIndex)
{
string? result = null;
@ -725,23 +714,6 @@ public class MainForm : Form
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
File.WriteAllText(path, root.ToString(Formatting.Indented));
SetStatus($"Gespeichert: {path}", Color.DarkGreen);
// Dienst-Neustart anbieten wenn Dienst läuft
if (IsServiceRunning())
{
if (MessageBox.Show(
"Konfiguration gespeichert.\n\nDienst jetzt neu starten um Änderungen zu übernehmen?",
"Dienst neu starten?",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
{
_ = ServiceActionAsync("stop").ContinueWith(async _ =>
{
await Task.Delay(1500);
await ServiceActionAsync("start");
});
}
}
}
catch (Exception ex) { SetStatus($"Fehler: {ex.Message}", Color.Red); }
}
@ -813,10 +785,10 @@ public class MainForm : Form
private async Task ServiceActionAsync(string action)
{
var publishDir = Path.GetDirectoryName(txtConfigPath.Text) ?? AppContext.BaseDirectory;
var exePath = Path.Combine(publishDir, "MailPrint.exe");
var installPs = Path.Combine(publishDir, "install-service.ps1");
var uninstallPs = Path.Combine(publishDir, "uninstall-service.ps1");
var publishDir = Path.GetDirectoryName(txtConfigPath.Text) ?? AppContext.BaseDirectory;
var exePath = Path.Combine(publishDir, "MailPrint.exe");
var installPs = Path.Combine(publishDir, "..", "install-service.ps1");
var uninstallPs= Path.Combine(publishDir, "..", "uninstall-service.ps1");
// Bestätigung nur bei Install/Deinstall
if (action is "install" or "uninstall")
@ -846,13 +818,12 @@ public class MainForm : Form
{
FileName = "powershell",
Arguments = $"-NoProfile -NonInteractive {cmd}",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardError = true
UseShellExecute = true,
Verb = "runas",
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
};
using var p = System.Diagnostics.Process.Start(psi)!;
string err = await p.StandardError.ReadToEndAsync();
await p.WaitForExitAsync();
if (p.ExitCode == 0)
@ -869,7 +840,7 @@ public class MainForm : Form
MessageBox.Show(successMsg, "Erfolgreich", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
SetStatus($"'{action}' fehlgeschlagen (Code {p.ExitCode}): {err.Trim()}", Color.Red);
SetStatus($"'{action}' fehlgeschlagen (Code {p.ExitCode})", Color.Red);
}
catch (Exception ex) { SetStatus($"Fehler: {ex.Message}", Color.Red); }
finally { DisableServiceButtons(false); RefreshStartStop(); }

View file

@ -1,12 +1,5 @@
using MailPrintConfig;
class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MailPrintConfig.exe"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>

17
build.bat Normal file
View file

@ -0,0 +1,17 @@
@echo off
setlocal
set PROJ=C:\Users\janwu\OneDrive - dimedtec GmbH\Programmierung\MailPrint\MailPrint\MailPrint.csproj
dotnet restore "%PROJ%"
if errorlevel 1 goto :err
dotnet build "%PROJ%" -c Release
if errorlevel 1 goto :err
dotnet publish "%PROJ%" -c Release -r win-x64 --self-contained false -o "C:\Users\janwu\OneDrive - dimedtec GmbH\Programmierung\MailPrint\publish"
if errorlevel 1 goto :err
echo.
echo === BUILD ERFOLGREICH ===
goto :end
:err
echo.
echo === BUILD FEHLGESCHLAGEN ===
exit /b 1
:end