Refactor ReportCreator: DI, logging, and deprecations

Refactored ReportCreator to use constructor injection for dependencies and removed BaseClass inheritance. Marked legacy methods and fields as [Obsolete] to indicate migration to mediator queries. Improved logging by switching to Logger.LogError and updating string interpolation. Removed unused usings and added MergeEnvelope method (also obsolete). These changes modernize the class and highlight areas for further architectural improvement.
This commit is contained in:
2026-02-26 18:57:58 +01:00
parent 15a18b1bfd
commit bdfb973d55

View File

@@ -1,30 +1,24 @@
using System.Data; using System.Data;
using System.IO;
using DigitalData.Modules.Base;
using DigitalData.Modules.Logging;
using EnvelopeGenerator.Domain.Constants; using EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.Domain.Entities;
using EnvelopeGenerator.ServiceHost.Exceptions; using EnvelopeGenerator.ServiceHost.Exceptions;
using EnvelopeGenerator.ServiceHost.Jobs; using EnvelopeGenerator.ServiceHost.Extensions;
namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument; namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
public class ReportCreator : BaseClass [Obsolete("Instead of ReportModel create and use EnvelopeReport mediator queries")]
public class ReportCreator(ReportModel ReportModel, ILogger<ReportCreator> Logger)
{ {
[Obsolete("Solve the spaghetti...")]
private Envelope? _envelope; private Envelope? _envelope;
private readonly ReportModel _reportModel;
public ReportCreator(LogConfig logConfig, State state) : base(logConfig)
{
_reportModel = new ReportModel(state);
}
[Obsolete("Instead of ReportModel create and use EnvelopeReport mediator queries and solve this spaghetti...")]
public byte[] CreateReport(Envelope envelope) public byte[] CreateReport(Envelope envelope)
{ {
try try
{ {
Logger.LogDebug("Loading report data.."); Logger.LogDebug("Loading report data..");
var table = _reportModel.List(envelope.Id); var table = ReportModel.List(envelope.Id);
var items = GetReportSource(table); var items = GetReportSource(table);
_envelope = envelope; _envelope = envelope;
@@ -34,7 +28,7 @@ public class ReportCreator : BaseClass
throw new CreateReportException("No report data found!"); throw new CreateReportException("No report data found!");
} }
Logger.LogDebug("Creating report with [{0}] items..", items.Count); Logger.LogDebug("Creating report with [{count}] items..", items.Count);
var buffer = DoCreateReport(items); var buffer = DoCreateReport(items);
Logger.LogDebug("Report created!"); Logger.LogDebug("Report created!");
@@ -42,7 +36,7 @@ public class ReportCreator : BaseClass
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Error(ex); Logger.LogError(ex);
throw new CreateReportException("Could not prepare report data!", ex); throw new CreateReportException("Could not prepare report data!", ex);
} }
} }
@@ -74,6 +68,7 @@ public class ReportCreator : BaseClass
return stream.ToArray(); return stream.ToArray();
} }
[Obsolete("Solve this spaghetti...")]
private ReportItem MergeEnvelope(ReportItem item) private ReportItem MergeEnvelope(ReportItem item)
{ {
if (item.Envelope is null) if (item.Envelope is null)
@@ -100,8 +95,8 @@ public class ReportCreator : BaseClass
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Error(ex); Logger.LogError(ex);
throw new CreateReportException("Could not read data from database!", ex); throw new CreateReportException("Could not read data from database!", ex);
} }
} }
} }