Compare commits
7 Commits
f19251ac1a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de4e9421af | ||
|
|
b622df4187 | ||
|
|
746465d8fe | ||
|
|
559829882a | ||
|
|
bec9ea2356 | ||
|
|
1cc617de42 | ||
|
|
b515b4f523 |
@@ -16,10 +16,8 @@
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DevExpress.AspNetCore.Reporting" Version="25.2.7" />
|
||||
<PackageReference Include="DevExpress.Document.Processor" Version="25.2.7" />
|
||||
<PackageReference Include="DevExpress.Pdf.Drawing" Version="25.2.7" />
|
||||
<PackageReference Include="DevExtreme.AspNet.Core" Version="25.2.7" />
|
||||
<PackageReference Include="DevExtreme.AspNet.Core" Version="25.2.*" />
|
||||
<PackageReference Include="MailKit" Version="4.16.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
using DevExpress.XtraReports.UI;
|
||||
using DevExpress.XtraReports.Web.Extensions;
|
||||
using DXApp.TemplateKitProject.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DXApp.TemplateKitProject.DevExpressExtensions;
|
||||
|
||||
public class CustomReportStorageWebExtension : ReportStorageWebExtension
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
private readonly ILogger<CustomReportStorageWebExtension> _logger;
|
||||
|
||||
public CustomReportStorageWebExtension(
|
||||
AppDbContext db,
|
||||
ILogger<CustomReportStorageWebExtension> logger)
|
||||
{
|
||||
_db = db;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public override bool CanSetData(string url)
|
||||
{
|
||||
// Wir erlauben KEIN Speichern von Änderungen über den Viewer
|
||||
// PDFs sind bei uns Read-Only im Viewer
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool IsValidUrl(string url)
|
||||
{
|
||||
// Prüfen ob URL dem Format entspricht: "invoice-{id}"
|
||||
return url.StartsWith("invoice-", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public override byte[] GetData(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogDebug("GetData aufgerufen für URL: {Url}", url);
|
||||
|
||||
// URL-Format: "invoice-123" → ID extrahieren
|
||||
if (!url.StartsWith("invoice-", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_logger.LogWarning("Ungültige URL: {Url}", url);
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
var idString = url.Substring("invoice-".Length);
|
||||
if (!int.TryParse(idString, out var invoiceId))
|
||||
{
|
||||
_logger.LogWarning("Ungültige Invoice-ID in URL: {Url}", url);
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
// Rechnung aus Datenbank laden
|
||||
var invoice = _db.ZugferdInvoices
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(i => i.Id == invoiceId);
|
||||
|
||||
if (invoice == null)
|
||||
{
|
||||
_logger.LogWarning("Rechnung mit ID {Id} nicht gefunden.", invoiceId);
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
// Prüfen ob ResultFilePath existiert
|
||||
if (string.IsNullOrEmpty(invoice.ResultFilePath))
|
||||
{
|
||||
_logger.LogWarning(
|
||||
"Rechnung {Id} hat keine Result-PDF (ResultFilePath ist leer).",
|
||||
invoiceId);
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
// Datei vom Dateisystem laden
|
||||
if (!File.Exists(invoice.ResultFilePath))
|
||||
{
|
||||
_logger.LogError(
|
||||
"Result-PDF-Datei nicht gefunden: {Path}",
|
||||
invoice.ResultFilePath);
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
var pdfBytes = File.ReadAllBytes(invoice.ResultFilePath);
|
||||
|
||||
_logger.LogInformation(
|
||||
"Result-PDF geladen: Invoice {Id}, Größe: {Size} Bytes",
|
||||
invoiceId,
|
||||
pdfBytes.Length);
|
||||
|
||||
return pdfBytes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Fehler beim Laden der PDF für URL: {Url}", url);
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
}
|
||||
|
||||
public override Dictionary<string, string> GetUrls()
|
||||
{
|
||||
// Diese Methode wird verwendet um eine Liste aller verfügbaren Reports zu liefern
|
||||
// Für unseren Use-Case nicht benötigt (wir laden immer spezifisch eine Invoice)
|
||||
return new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public override void SetData(XtraReport report, string url)
|
||||
{
|
||||
// Nicht implementiert - wir erlauben kein Speichern über den Viewer
|
||||
throw new NotSupportedException(
|
||||
"Das Speichern von Reports über den Document Viewer ist nicht unterstützt.");
|
||||
}
|
||||
|
||||
public override string SetNewData(XtraReport report, string defaultUrl)
|
||||
{
|
||||
// Nicht implementiert - wir erstellen keine neuen Reports über den Viewer
|
||||
throw new NotSupportedException(
|
||||
"Das Erstellen neuer Reports über den Document Viewer ist nicht unterstützt.");
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,11 @@
|
||||
using DXApp.TemplateKitProject.Data;
|
||||
using DXApp.TemplateKitProject.DevExpressExtensions;
|
||||
using DXApp.TemplateKitProject.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DevExpress.AspNetCore;
|
||||
using DevExpress.AspNetCore.Reporting;
|
||||
using DevExpress.XtraReports.Web.Extensions;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddRazorPages();
|
||||
|
||||
// DevExpress Controls und Reporting Services
|
||||
builder.Services.AddDevExpressControls();
|
||||
builder.Services.AddScoped<ReportStorageWebExtension, CustomReportStorageWebExtension>();
|
||||
|
||||
// Datenbank
|
||||
var connectionString = builder.Configuration.GetConnectionString("EcmContext")
|
||||
?? throw new InvalidOperationException("Connection string 'EcmContext' not found.");
|
||||
@@ -38,18 +30,12 @@ if (!app.Environment.IsDevelopment())
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
// MIME-Types für PDF.js UND DevExpress registrieren
|
||||
// MIME-Types für PDF.js registrieren (einmaliger UseStaticFiles-Aufruf)
|
||||
var provider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider();
|
||||
provider.Mappings[".mjs"] = "text/javascript";
|
||||
provider.Mappings[".ftl"] = "text/plain";
|
||||
provider.Mappings[".woff2"] = "font/woff2";
|
||||
provider.Mappings[".woff"] = "font/woff";
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider });
|
||||
|
||||
// DevExpress Middleware
|
||||
app.UseDevExpressControls();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseAuthorization();
|
||||
app.MapRazorPages();
|
||||
|
||||
Reference in New Issue
Block a user