30-11-23
This commit is contained in:
@@ -7,6 +7,18 @@ namespace EnvelopeGenerator.Web.Services
|
||||
{
|
||||
public MSSQLServer MSSQL { get; set; }
|
||||
|
||||
public State State { get; set; }
|
||||
|
||||
public class ServiceContainer
|
||||
{
|
||||
public ActionService actionService;
|
||||
|
||||
public ServiceContainer(State state)
|
||||
{
|
||||
actionService = new(state);
|
||||
}
|
||||
}
|
||||
|
||||
public class ModelContainer
|
||||
{
|
||||
public EnvelopeModel envelopeModel;
|
||||
@@ -31,6 +43,7 @@ namespace EnvelopeGenerator.Web.Services
|
||||
}
|
||||
}
|
||||
public readonly ModelContainer? Models;
|
||||
public readonly ServiceContainer? Services;
|
||||
|
||||
public DatabaseService(IConfiguration Config, LoggingService Logging) : base(Config, Logging)
|
||||
{
|
||||
@@ -41,19 +54,14 @@ namespace EnvelopeGenerator.Web.Services
|
||||
|
||||
if (MSSQL.DBInitialized == true)
|
||||
{
|
||||
logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
||||
|
||||
// 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.
|
||||
logger.Debug("MSSQL Connection established: [{0}]", MSSQL.MaskedConnectionString);
|
||||
|
||||
var state = GetState();
|
||||
var configModel = new ConfigModel(state);
|
||||
state.DbConfig = configModel.LoadConfiguration();
|
||||
|
||||
Models = new(state);
|
||||
Models = new(state);
|
||||
Services = new(state);
|
||||
|
||||
State = state;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -61,13 +69,31 @@ namespace EnvelopeGenerator.Web.Services
|
||||
}
|
||||
}
|
||||
|
||||
public State GetState()
|
||||
/// <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 = 2 // TODO
|
||||
UserId = 0,
|
||||
DbConfig = null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,8 @@ namespace EnvelopeGenerator.Web.Services
|
||||
{
|
||||
public class EnvelopeService : BaseService
|
||||
{
|
||||
private ReceiverModel receiverModel;
|
||||
private EnvelopeModel envelopeModel;
|
||||
private HistoryModel historyModel;
|
||||
private DocumentModel documentModel;
|
||||
private DocumentStatusModel documentStatusModel;
|
||||
private readonly ReceiverModel receiverModel;
|
||||
private readonly EnvelopeModel envelopeModel;
|
||||
|
||||
public EnvelopeService(IConfiguration Config, LoggingService Logging, DatabaseService database) : base(Config, Logging)
|
||||
{
|
||||
@@ -25,9 +22,6 @@ namespace EnvelopeGenerator.Web.Services
|
||||
|
||||
receiverModel = database.Models.receiverModel;
|
||||
envelopeModel = database.Models.envelopeModel;
|
||||
historyModel = database.Models.historyModel;
|
||||
documentModel = database.Models.documentModel;
|
||||
documentStatusModel = database.Models.documentStatusModel;
|
||||
}
|
||||
|
||||
public void EnsureValidEnvelopeKey(string envelopeKey)
|
||||
@@ -48,7 +42,6 @@ namespace EnvelopeGenerator.Web.Services
|
||||
throw new ArgumentNullException("ReceiverSignature");
|
||||
}
|
||||
|
||||
|
||||
public EnvelopeResponse LoadEnvelope(string pEnvelopeKey)
|
||||
{
|
||||
Tuple<string, string> result = Helpers.DecodeEnvelopeReceiverId(pEnvelopeKey);
|
||||
@@ -101,27 +94,6 @@ namespace EnvelopeGenerator.Web.Services
|
||||
return (List<Envelope>)envelopeModel.List(pReceiverId);
|
||||
}
|
||||
|
||||
public bool InsertHistoryEntry(EnvelopeHistoryEntry historyEntry)
|
||||
{
|
||||
return historyModel.Insert(historyEntry);
|
||||
}
|
||||
|
||||
public bool InsertHistoryEntrySigned(EnvelopeResponse response)
|
||||
{
|
||||
return historyModel.Insert(new EnvelopeHistoryEntry()
|
||||
{
|
||||
ActionDate = DateTime.Now,
|
||||
Status = EnvelopeStatus.DocumentSigned,
|
||||
EnvelopeId = response.Envelope.Id,
|
||||
UserReference = response.Receiver.Email
|
||||
});
|
||||
}
|
||||
|
||||
public bool InsertDocumentStatus(Common.DocumentStatus documentStatus)
|
||||
{
|
||||
return documentStatusModel.InsertOrUpdate(documentStatus);
|
||||
}
|
||||
|
||||
public async Task<string?> EnsureValidAnnotationData(HttpRequest request)
|
||||
{
|
||||
try
|
||||
@@ -183,16 +155,6 @@ namespace EnvelopeGenerator.Web.Services
|
||||
return document;
|
||||
}
|
||||
|
||||
public async Task UpdateDocument(Stream fileStream, string filePath)
|
||||
{
|
||||
logger.Debug("Writing document to path [{0}]..", filePath);
|
||||
|
||||
using FileStream fs = new(filePath, FileMode.Open);
|
||||
await fileStream.CopyToAsync(fs);
|
||||
|
||||
logger.Debug("Document written!");
|
||||
}
|
||||
|
||||
public async Task<byte[]> GetDocumentContents(EnvelopeDocument document)
|
||||
{
|
||||
logger.Debug("Loading file [{0}]", document.Filepath);
|
||||
|
||||
Reference in New Issue
Block a user