Compare commits
No commits in common. "v1.0.0" and "main" have entirely different histories.
9 changed files with 117 additions and 35 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,6 +2,7 @@
|
||||||
bin/
|
bin/
|
||||||
obj/
|
obj/
|
||||||
publish/
|
publish/
|
||||||
|
*.zip
|
||||||
|
|
||||||
# Skripte aus publish/ im Root behalten
|
# Skripte aus publish/ im Root behalten
|
||||||
!install-service.ps1
|
!install-service.ps1
|
||||||
|
|
|
||||||
22
Directory.Build.props
Normal file
22
Directory.Build.props
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<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>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>
|
||||||
|
|
@ -8,9 +8,10 @@
|
||||||
<RootNamespace>MailPrint</RootNamespace>
|
<RootNamespace>MailPrint</RootNamespace>
|
||||||
<AssemblyName>MailPrint</AssemblyName>
|
<AssemblyName>MailPrint</AssemblyName>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<Version>1.0.0</Version>
|
<SelfContained>true</SelfContained>
|
||||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
<FileVersion>1.0.0.0</FileVersion>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,34 @@ try
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
c.SwaggerDoc("v1", new() { Title = "MailPrint API", Version = "v1" }));
|
{
|
||||||
|
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>()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,14 @@
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<RootNamespace>MailPrintConfig</RootNamespace>
|
<RootNamespace>MailPrintConfig</RootNamespace>
|
||||||
<AssemblyName>MailPrintConfig</AssemblyName>
|
<AssemblyName>MailPrintConfig</AssemblyName>
|
||||||
<Version>1.0.0</Version>
|
<SelfContained>true</SelfContained>
|
||||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
<FileVersion>1.0.0.0</FileVersion>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="System.ServiceProcess.ServiceController" Version="8.0.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -491,6 +491,17 @@ public class MainForm : Form
|
||||||
?? Path.Combine(AppContext.BaseDirectory, "appsettings.json");
|
?? 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)
|
private void BrowseFolder(int rowIndex)
|
||||||
{
|
{
|
||||||
string? result = null;
|
string? result = null;
|
||||||
|
|
@ -714,6 +725,23 @@ public class MainForm : Form
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||||
File.WriteAllText(path, root.ToString(Formatting.Indented));
|
File.WriteAllText(path, root.ToString(Formatting.Indented));
|
||||||
SetStatus($"Gespeichert: {path}", Color.DarkGreen);
|
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); }
|
catch (Exception ex) { SetStatus($"Fehler: {ex.Message}", Color.Red); }
|
||||||
}
|
}
|
||||||
|
|
@ -785,10 +813,10 @@ public class MainForm : Form
|
||||||
|
|
||||||
private async Task ServiceActionAsync(string action)
|
private async Task ServiceActionAsync(string action)
|
||||||
{
|
{
|
||||||
var publishDir = Path.GetDirectoryName(txtConfigPath.Text) ?? AppContext.BaseDirectory;
|
var publishDir = Path.GetDirectoryName(txtConfigPath.Text) ?? AppContext.BaseDirectory;
|
||||||
var exePath = Path.Combine(publishDir, "MailPrint.exe");
|
var exePath = Path.Combine(publishDir, "MailPrint.exe");
|
||||||
var installPs = Path.Combine(publishDir, "..", "install-service.ps1");
|
var installPs = Path.Combine(publishDir, "install-service.ps1");
|
||||||
var uninstallPs= Path.Combine(publishDir, "..", "uninstall-service.ps1");
|
var uninstallPs = Path.Combine(publishDir, "uninstall-service.ps1");
|
||||||
|
|
||||||
// Bestätigung nur bei Install/Deinstall
|
// Bestätigung nur bei Install/Deinstall
|
||||||
if (action is "install" or "uninstall")
|
if (action is "install" or "uninstall")
|
||||||
|
|
@ -818,12 +846,13 @@ public class MainForm : Form
|
||||||
{
|
{
|
||||||
FileName = "powershell",
|
FileName = "powershell",
|
||||||
Arguments = $"-NoProfile -NonInteractive {cmd}",
|
Arguments = $"-NoProfile -NonInteractive {cmd}",
|
||||||
UseShellExecute = true,
|
UseShellExecute = false,
|
||||||
Verb = "runas",
|
CreateNoWindow = true,
|
||||||
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
|
RedirectStandardError = true
|
||||||
};
|
};
|
||||||
|
|
||||||
using var p = System.Diagnostics.Process.Start(psi)!;
|
using var p = System.Diagnostics.Process.Start(psi)!;
|
||||||
|
string err = await p.StandardError.ReadToEndAsync();
|
||||||
await p.WaitForExitAsync();
|
await p.WaitForExitAsync();
|
||||||
|
|
||||||
if (p.ExitCode == 0)
|
if (p.ExitCode == 0)
|
||||||
|
|
@ -840,7 +869,7 @@ public class MainForm : Form
|
||||||
MessageBox.Show(successMsg, "Erfolgreich", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show(successMsg, "Erfolgreich", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SetStatus($"'{action}' fehlgeschlagen (Code {p.ExitCode})", Color.Red);
|
SetStatus($"'{action}' fehlgeschlagen (Code {p.ExitCode}): {err.Trim()}", Color.Red);
|
||||||
}
|
}
|
||||||
catch (Exception ex) { SetStatus($"Fehler: {ex.Message}", Color.Red); }
|
catch (Exception ex) { SetStatus($"Fehler: {ex.Message}", Color.Red); }
|
||||||
finally { DisableServiceButtons(false); RefreshStartStop(); }
|
finally { DisableServiceButtons(false); RefreshStartStop(); }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
using MailPrintConfig;
|
using MailPrintConfig;
|
||||||
|
|
||||||
Application.EnableVisualStyles();
|
class Program
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
{
|
||||||
Application.Run(new MainForm());
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application.Run(new MainForm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
11
MailPrintConfig/app.manifest
Normal file
11
MailPrintConfig/app.manifest
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?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
17
build.bat
|
|
@ -1,17 +0,0 @@
|
||||||
@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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue