Alle Entitäten wurden mit Attributen erstellt und zu EFCore DBContex hinzugefügt.

This commit is contained in:
Developer 02
2024-04-02 14:53:25 +02:00
parent 6fc210132d
commit b65766ce24
30 changed files with 772 additions and 269 deletions

View File

@@ -1,18 +0,0 @@
using DigitalData.Modules.Logging;
namespace EnvelopeGenerator.Web.Services
{
public class BaseService
{
internal readonly LogConfig logConfig;
internal readonly IConfiguration config;
internal Logger logger;
public BaseService(IConfiguration Config, LoggingService Logging)
{
logConfig = Logging.LogConfig;
logger = Logging.LogConfig.GetLogger();
config = Config;
}
}
}

View File

@@ -1,14 +1,16 @@
using DigitalData.Modules.Database;
using DigitalData.Modules.Logging;
using EnvelopeGenerator.Common;
namespace EnvelopeGenerator.Web.Services
{
public class DatabaseService: BaseService
public class DatabaseService
{
public MSSQLServer MSSQL { get; set; }
public IConfiguration Config { get; set; }
public State State { get; set; }
ILogger<DatabaseService> _logger;
public State? State { get; set; }
public class ServiceContainer
{
@@ -48,62 +50,43 @@ namespace EnvelopeGenerator.Web.Services
public readonly ModelContainer? Models;
public readonly ServiceContainer? Services;
public DatabaseService(IConfiguration pConfig, LoggingService pLogging) : base(pConfig, pLogging)
public DatabaseService(ILogger<DatabaseService> logger, IConfiguration config)
{
logger = pLogging.LogConfig.GetLogger();
Config = pConfig;
LogConfig logConfig = new LogConfig(LogConfig.PathType.CustomPath, config["Config:LogPath"], null, "Digital Data", "ECM.EnvelopeGenerator.Web");
_logger = logger;
logger.Debug("Establishing MSSQL Database connection..");
MSSQL = new MSSQLServer(logConfig, pConfig["Config:ConnectionString"]);
_logger.LogInformation("Establishing MSSQL Database connection..");
MSSQL = new MSSQLServer(logConfig, config["Config:ConnectionString"]);
if (MSSQL.DBInitialized == true)
{
logger.Debug("MSSQL Connection established: [{0}]", MSSQL.MaskedConnectionString);
var state = GetState();
_logger.LogInformation("MSSQL Connection established: [{0}]", MSSQL.MaskedConnectionString);
Models = new(state);
Services = new(state);
/// <summary>
/// There is a circular dependency between state and models
/// All models need a state object, including the config Model
/// The state object needs to be filled with the DbConfig property,
/// which is obtained by the config Model.
/// So first, the config model is initialized with an incomplete state object,
/// then all the other models with the DbConfig property filled.
/// </summary>
State = new State
{
Database = MSSQL,
LogConfig = logConfig,
UserId = 0,
DbConfig = null
};
var configModel = new ConfigModel(State);
State.DbConfig = configModel.LoadConfiguration();
State = state;
Models = new(State);
Services = new(State);
}
else
{
logger.Error("Connection could not be established!");
_logger.LogInformation("Connection could not be established!");
}
}
public string? GetAppSetting(string key)
{
return Config[key];
}
/// <summary>
/// There is a circular dependency between state and models
/// All models need a state object, including the config Model
/// The state object needs to be filled with the DbConfig property,
/// which is obtained by the config Model.
/// So first, the config model is initialized with an incomplete state object,
/// then all the other models with the DbConfig property filled.
/// </summary>
private State GetState()
{
var state = GetInitialState();
var configModel = new ConfigModel(state);
state.DbConfig = configModel.LoadConfiguration();
return state;
}
private State GetInitialState()
{
return new State
{
Database = MSSQL,
LogConfig = logConfig,
UserId = 0,
DbConfig = null
};
}
}
}

View File

@@ -1,11 +1,10 @@
using EnvelopeGenerator.Application.Contracts;
using EnvelopeGenerator.Common;
using Microsoft.Extensions.Primitives;
using System.Text;
namespace EnvelopeGenerator.Web.Services
{
public class EnvelopeService : BaseService
public class EnvelopeService
{
private readonly ReceiverModel receiverModel;
private readonly EnvelopeModel envelopeModel;
@@ -13,16 +12,15 @@ namespace EnvelopeGenerator.Web.Services
private readonly DocumentStatusModel documentStatusModel;
private IConfigService _configService;
private readonly IConfigService _configService;
private readonly ILogger<EnvelopeService> _logger;
public EnvelopeService(IConfiguration Config, LoggingService Logging, DatabaseService database, IConfigService configService) : base(Config, Logging)
public EnvelopeService(DatabaseService database, IConfigService configService, ILogger<EnvelopeService> logger)
{
logger = Logging.LogConfig.GetLogger();
_logger = logger;
if (database.Models == null)
{
if (database.Models is null)
throw new ArgumentNullException("Models not loaded.");
}
receiverModel = database.Models.receiverModel;
envelopeModel = database.Models.envelopeModel;
@@ -34,14 +32,14 @@ namespace EnvelopeGenerator.Web.Services
public void EnsureValidEnvelopeKey(string envelopeKey)
{
logger.Debug("Parsing EnvelopeKey..");
_logger.LogInformation("Parsing EnvelopeKey..");
if (string.IsNullOrEmpty(envelopeKey))
throw new ArgumentNullException("EnvelopeKey");
Tuple<string, string> result = Helpers.DecodeEnvelopeReceiverId(envelopeKey);
logger.Debug("EnvelopeUUID: [{0}]", result.Item1);
logger.Debug("ReceiverSignature: [{0}]", result.Item2);
_logger.LogInformation("EnvelopeUUID: [{0}]", result.Item1);
_logger.LogInformation("ReceiverSignature: [{0}]", result.Item2);
if (string.IsNullOrEmpty(result.Item1))
throw new ArgumentNullException("EnvelopeUUID");
@@ -52,43 +50,43 @@ namespace EnvelopeGenerator.Web.Services
public async Task<EnvelopeResponse> LoadEnvelope(string pEnvelopeKey)
{
logger.Debug("Loading Envelope by Key [{0}]", pEnvelopeKey);
_logger.LogInformation("Loading Envelope by Key [{0}]", pEnvelopeKey);
Tuple<string, string> result = Helpers.DecodeEnvelopeReceiverId(pEnvelopeKey);
var envelopeUuid = result.Item1;
var receiverSignature = result.Item2;
var receiverId = receiverModel.GetReceiverIdBySignature(receiverSignature);
logger.Debug("Resolved receiver signature to receiverId [{0}]", receiverId);
_logger.LogInformation("Resolved receiver signature to receiverId [{0}]", receiverId);
logger.Debug("Loading envelope..");
_logger.LogInformation("Loading envelope..");
Envelope? envelope = envelopeModel.GetByUuid(envelopeUuid);
if (envelope == null)
{
logger.Warn("Envelope not found");
_logger.LogWarning("Envelope not found");
throw new NullReferenceException("Envelope not found");
}
logger.Debug("Envelope loaded");
_logger.LogInformation("Envelope loaded");
if (envelope.Receivers == null)
{
logger.Warn("Receivers for envelope not loaded");
_logger.LogWarning("Receivers for envelope not loaded");
throw new NullReferenceException("Receivers for envelope not loaded");
}
logger.Debug("Envelope receivers found: [{0}]", envelope.Receivers.Count);
_logger.LogInformation("Envelope receivers found: [{0}]", envelope.Receivers.Count);
EnvelopeReceiver? receiver = envelope.Receivers.Where(r => r.Id == receiverId).SingleOrDefault();
if (receiver == null)
{
logger.Warn("Receiver [{0}] not found", receiverId);
_logger.LogWarning("Receiver [{0}] not found", receiverId);
throw new NullReferenceException("Receiver not found");
}
logger.Debug("Loading documents for receiver [{0}]", receiver.Email);
_logger.LogInformation("Loading documents for receiver [{0}]", receiver.Email);
// filter elements by receiver
envelope.Documents = envelope.Documents.Select((document) =>
@@ -111,7 +109,7 @@ namespace EnvelopeGenerator.Web.Services
}
else
{
logger.Error(configResult.Messages);
_logger.LogError(string.Join(". ", configResult.Messages));
throw new InvalidOperationException(String.Join(". ", configResult.Messages));
}
@@ -150,52 +148,28 @@ namespace EnvelopeGenerator.Web.Services
{
try
{
logger.Debug("Parsing annotation data from request..");
_logger.LogInformation("Parsing annotation data from request..");
using MemoryStream ms = new();
await request.BodyReader.CopyToAsync(ms);
var bytes = ms.ToArray();
logger.Debug("Annotation data parsed, size: [{0}]", bytes.Length);
_logger.LogInformation("Annotation data parsed, size: [{0}]", bytes.Length);
return Encoding.UTF8.GetString(bytes);
}
catch (Exception e)
{
logger.Error(e);
_logger.LogError(e, "Inner Service Error");
throw new ArgumentNullException("AnnotationData");
}
}
public int EnsureValidDocumentIndex(HttpRequest request)
{
if (!request.Query.TryGetValue("index", out StringValues documentIndexStringList))
{
logger.Warn("There is no query parameter called index");
throw new ArgumentNullException("DocumentIndex");
}
if (documentIndexStringList.FirstOrDefault() == null)
{
logger.Warn("There is no query parameter called index");
throw new ArgumentNullException("DocumentIndex");
}
if (!int.TryParse(documentIndexStringList.First(), out int documentIndex))
{
logger.Warn("Invalid document index [{0}]", documentIndexStringList.First());
throw new ArgumentNullException("DocumentIndex");
}
return documentIndex;
}
public async Task<EnvelopeDocument> GetDocument(HttpRequest request, string envelopeKey)
public async Task<EnvelopeDocument> GetDocument(int documentId, string envelopeKey)
{
EnvelopeResponse response = await LoadEnvelope(envelopeKey);
int documentId = EnsureValidDocumentIndex(request);
logger.Debug("Loading document for Id [{0}]", documentId);
_logger.LogInformation("Loading document for Id [{0}]", documentId);
var document = response.Envelope.Documents.
Where(d => d.Id == documentId).
@@ -203,25 +177,25 @@ namespace EnvelopeGenerator.Web.Services
if (document == null)
throw new ArgumentException("DocumentId");
logger.Debug("Document [{0}] loaded!", documentId);
_logger.LogInformation("Document [{0}] loaded!", documentId);
return document;
}
public bool InsertDocumentStatus(Common.DocumentStatus documentStatus)
{
logger.Debug("Saving annotation data..");
_logger.LogInformation("Saving annotation data..");
return documentStatusModel.InsertOrUpdate(documentStatus);
}
public async Task<byte[]> GetDocumentContents(EnvelopeDocument document)
{
logger.Debug("Loading file [{0}]", document.Filepath);
_logger.LogInformation("Loading file [{0}]", document.Filepath);
var bytes = await File.ReadAllBytesAsync(document.Filepath);
logger.Info("File loaded, size: [{0}]", bytes.Length);
_logger.LogInformation("File loaded, size: [{0}]", bytes.Length);
return bytes;
}
}
}
}

View File

@@ -1,25 +0,0 @@
using DigitalData.Modules.Logging;
namespace EnvelopeGenerator.Web.Services
{
public class LoggingService
{
public LogConfig LogConfig { get; set; }
public LoggingService(IConfiguration Config)
{
LogConfig = new LogConfig(LogConfig.PathType.CustomPath, Config["Config:LogPath"], null, "Digital Data", "ECM.EnvelopeGenerator.Web");
var logger = LogConfig.GetLogger();
logger.Info("Logging initialized!");
var debugLog = bool.Parse(Config["Config:LogDebug"]);
logger.Info("Setting DEBUG Logging to: [{0}]", debugLog);
LogConfig.Debug = debugLog;
var jsonLog = bool.Parse(Config["Config:LogJson"]);
logger.Info("Setting JSON Logging to: [{0}]", jsonLog);
LogConfig.Debug = jsonLog;
}
}
}