Class BaseTransactionProcessor
This is the base transaction processor that all processes for any type of ITransactionalEntity should inherit from
This ensures all transactional items behave consistently such as implementing cancel/correct logic and the correct behaviour for their status
Inheritance
Implements
Inherited Members
Namespace: LemonEdge.API.Core.FinancialServices.Processors.Transactional
Assembly: LemonEdge.API.Core.FinancialServices.dll
Syntax
public abstract class BaseTransactionProcessor : ILockable, ICanBeRevertedTransactionProcessor, IBaseDataSetProcessorWithDBSave, IBaseDataSetProcessor, IProcessor, IDisposable
Constructors
BaseTransactionProcessor(IEntityUpdater, IReadOnlyCache, UserInfo, IServiceContext)
Creates a new base transaction with the standard IBaseDataSetProcessor objects
Declaration
protected BaseTransactionProcessor(IEntityUpdater updater, IReadOnlyCache cache, UserInfo user, IServiceContext services)
Parameters
Type | Name | Description |
---|---|---|
IEntityUpdater | updater | A context for querying and updating all items in the LemonEdge system |
IReadOnlyCache | cache | A local cache context |
UserInfo | user | The current logged in user |
IServiceContext | services | The services demanded from the IServiceProvider. |
BaseTransactionProcessor(IServiceContext)
Creates a new base transaction processor for dynamic construction as part of a task
Declaration
protected BaseTransactionProcessor(IServiceContext services)
Parameters
Type | Name | Description |
---|---|---|
IServiceContext | services |
Properties
AnyChangeRequiresTaskRecalc
If this root transaction item implements IHasSaveProcessingTask then the system will automatically create a task for any existing SavedTaskParam configured for the root transaction
It will modify this task if performing a cancel, cancel/correct or moving to finalized depending on CommitToFinalizeRequiresTask
This indicates that any normal change not against this root entity should not result in it recreating a task stored against SavedTaskParam. By default this is false so it only recreates the task when the root item itself has changed and thus SavedTaskParam will have too.Declaration
protected virtual bool AnyChangeRequiresTaskRecalc { get; }
Property Value
Type | Description |
---|---|
bool |
Cache
A local cache for performance
Declaration
public IReadOnlyCache Cache { get; }
Property Value
Type | Description |
---|---|
IReadOnlyCache |
CanCancel
Indicates that the transaction processor allows the root transaction to be cancelled, by default this is true but can be overridden by implementing processors
Declaration
protected virtual bool CanCancel { get; }
Property Value
Type | Description |
---|---|
bool |
CanLock
Returns true if the root transaction status is Finalized
This indicates the user can modify the transaction in the UI which this will process as a cancel/correct
Declaration
public virtual bool CanLock { get; }
Property Value
Type | Description |
---|---|
bool |
CancelledItems
A collection of all items that have been cancelled by this processor if processing a cancellation or cancel/correct
Declaration
public IReadOnlyDictionary<Guid, (ITransactionalEntity Original, ITransactionalEntity Cancelling)> CancelledItems { get; }
Property Value
Type | Description |
---|---|
IReadOnlyDictionary<Guid, (ITransactionalEntity Original, ITransactionalEntity Cancelling)> |
CommitToFinalizeRequiresTask
If this root transaction item implements IHasSaveProcessingTask then the system will create tasks for processing a transaction automatically when finalized or correcting
By default if a transaction has only changed status from committed to finalized with no other changes then it will set it to finalized, will not call ProcessTransaction() and will not create a task, as it is assumed to still be correct
Changing this to true indicates it should create a task anyway for finalized status changes tooDeclaration
protected virtual bool CommitToFinalizeRequiresTask { get; }
Property Value
Type | Description |
---|---|
bool |
CorrectedItems
A collection of all items that have been corrected by this processor if processing a cancel/correct
Declaration
public IReadOnlyDictionary<Guid, ITransactionalEntity> CorrectedItems { get; }
Property Value
Type | Description |
---|---|
IReadOnlyDictionary<Guid, ITransactionalEntity> |
FinancialDateCalculator
A calculator for providing a valid financial date against an entity taking into account the IEntityPeriodClosing against it and the requested transaction date
Declaration
public IFinancialDateCalculator FinancialDateCalculator { get; }
Property Value
Type | Description |
---|---|
IFinancialDateCalculator |
IgnoreEvents
Indicates the processor should ignore changes to any items within the processor
Normally used when the processor responds to an event and wants to prevent any other responses while it finishes processing that change
Declaration
public virtual bool IgnoreEvents { get; set; }
Property Value
Type | Description |
---|---|
bool |
Loaded
Flag to indicate if the processor has been fully loaded
Declaration
public abstract bool Loaded { get; }
Property Value
Type | Description |
---|---|
bool |
Order
If we have multiple save processors working, this indicates the order in which they will be processed with relation to each other
Declaration
public virtual short Order { get; }
Property Value
Type | Description |
---|---|
short |
Reporter
A reporter to provide feedback to a log, or client depending on the context the process is running under
Declaration
public BusyProgressReporter Reporter { get; set; }
Property Value
Type | Description |
---|---|
BusyProgressReporter |
RootCancelledEntity
If processing a cancel or cancel/correct this holds the new root cancelling transaction
Declaration
public ITransactionalEntity RootCancelledEntity { get; }
Property Value
Type | Description |
---|---|
ITransactionalEntity |
RootCorrectedEntity
If processing a cancel/correct this holds the new root correcting transaction
Declaration
public ITransactionalEntity RootCorrectedEntity { get; }
Property Value
Type | Description |
---|---|
ITransactionalEntity |
RootTransactionEntity
The root transaction entity for this transaction processor
Declaration
public abstract IHeaderTransactionalEntity RootTransactionEntity { get; }
Property Value
Type | Description |
---|---|
IHeaderTransactionalEntity |
SaveProcessed
Indicates the ProcessOnDBSave has already been run. This is set by the system during save, and prevents recursive calls.
It is also released by the system on save completion/failure
Declaration
public bool SaveProcessed { get; set; }
Property Value
Type | Description |
---|---|
bool |
Services
Declaration
public IServiceContext Services { get; }
Property Value
Type | Description |
---|---|
IServiceContext |
SubProcessors
An enumeration of all sub processors for this processor
For instance the IBlendTransactionProcessor will have sub processors for processing each transaction it creates
Declaration
public virtual IEnumerable<BaseTransactionProcessor> SubProcessors { get; }
Property Value
Type | Description |
---|---|
IEnumerable<BaseTransactionProcessor> |
Updater
A context to ensure the process can query, load and modify all LemonEdge data
Declaration
public IEntityUpdater Updater { get; }
Property Value
Type | Description |
---|---|
IEntityUpdater |
User
The current logged in user the process is running under
Declaration
public UserInfo User { get; }
Property Value
Type | Description |
---|---|
UserInfo |
Methods
AddToDataSetToProcess(IBaseEntity, EntityOperation)
If a modified item belongs in the processor (IsChangedItemPartOfDataSet(IBaseEntity)), this adds the item to the processor if it already isn't a member of it
Declaration
public abstract void AddToDataSetToProcess(IBaseEntity item, EntityOperation operationType)
Parameters
Type | Name | Description |
---|---|---|
IBaseEntity | item | The item to add to the processor |
EntityOperation | operationType | The type of operation that modified the item. Useful as deleted items can often be treated differently in a processor. |
CanWrite(IBaseEntity)
Indicates if the processor allows items to be written to depending on the users permission and transaction status
Declaration
public abstract bool CanWrite(IBaseEntity baseEntity)
Parameters
Type | Name | Description |
---|---|---|
IBaseEntity | baseEntity |
Returns
Type | Description |
---|---|
bool |
CustomUpdateCancelCorrectedItem(EntityDescriptor, ITransactionalEntity, ITransactionalEntity, bool)
Provides the implementing class an opportunity to update the cancel, or corrected record generated automatically by the processor
Declaration
protected virtual Task CustomUpdateCancelCorrectedItem(EntityDescriptor type, ITransactionalEntity original, ITransactionalEntity cancelCorrected, bool isCorrectionRecord)
Parameters
Type | Name | Description |
---|---|---|
EntityDescriptor | type | The type of the entity being cancelled or corrected |
ITransactionalEntity | original | The original entity record that has a cancel or corrected record generated for it |
ITransactionalEntity | cancelCorrected | The cancel or corrected record, indicated by |
bool | isCorrectionRecord | Indicates |
Returns
Type | Description |
---|---|
Task |
Dispose()
Declaration
public void Dispose()
Dispose(bool)
Declaration
protected void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
DisposeManagedState()
Declaration
protected virtual void DisposeManagedState()
DisposeUnManagedState()
Declaration
protected virtual void DisposeUnManagedState()
ExecuteFormula<T>(string, IBaseEntity)
Executes the specified formula with the specified context item
Declaration
public Task<T> ExecuteFormula<T>(string formula, IBaseEntity contextItem)
Parameters
Type | Name | Description |
---|---|---|
string | formula | The c# formula/script to dynamically execute |
IBaseEntity | contextItem | A context item that is provided as a FormulaFunctionsWithContext which can be referenced by the formula |
Returns
Type | Description |
---|---|
Task<T> | A task holding the result of the formula being executed |
Type Parameters
Name | Description |
---|---|
T | The type of result expected from executing the formula |
ForceLoad()
Forces the processor to load all items for the calculation.
Some implementations do not run their process during save (such as the ITransferProcessor) and instead run them as tasks, and just use this for the cancel/correct logic
As such the ProcessTransaction() and Load() can do nothing. This should be implemented by such processors to actually load for the system to correctly process cancel/corrects tooDeclaration
protected virtual Task ForceLoad()
Returns
Type | Description |
---|---|
Task | A task indicating the completion of the operation |
GetAllItemsInThisProcessorExcludingSubProcessors()
Returns all items in this base processor - Used by the system when reverting the status of a finalized transaction back to in progress
Declaration
public abstract IEnumerable<IBaseEntity> GetAllItemsInThisProcessorExcludingSubProcessors()
Returns
Type | Description |
---|---|
IEnumerable<IBaseEntity> | An enumeration of all items in this transactional processor |
GetAllItemsInTransactionProcessor(bool)
Returns all items in this base processor - Used by the system when reverting the status of a finalized transaction back to in progress
Declaration
public IEnumerable<IBaseEntity> GetAllItemsInTransactionProcessor(bool includeSubProcessors)
Parameters
Type | Name | Description |
---|---|---|
bool | includeSubProcessors | Indicates if items in any sub processors should also be returned as well |
Returns
Type | Description |
---|---|
IEnumerable<IBaseEntity> | An enumeration of all items in this transactional processor |
IsChangedItemPartOfDataSet(IBaseEntity)
This function returns true if the specified modified item belongs in this processor.
Non modified items will just automatically be loaded by the processor anyway, this is more to keep track of items as they are changed and should be added to the processor without having to reload
Declaration
public abstract bool IsChangedItemPartOfDataSet(IBaseEntity item)
Parameters
Type | Name | Description |
---|---|---|
IBaseEntity | item | The item to check if it belongs in this processor |
Returns
Type | Description |
---|---|
bool | True if the specified item belongs in this processor |
IsLocked(IBaseEntity)
Indicates if this item is currently locked. True if status is finalized or cancelled. Can be changed by the user in the UI to modify finalized transactions which this will process as a cancel/correct
Declaration
public abstract bool IsLocked(IBaseEntity baseEntity)
Parameters
Type | Name | Description |
---|---|---|
IBaseEntity | baseEntity |
Returns
Type | Description |
---|---|
bool | true if it can be unlocked to enable updates, otherwise false |
KeepTransactionDateConsistent()
Declaration
protected virtual bool KeepTransactionDateConsistent()
Returns
Type | Description |
---|---|
bool |
Load()
A thread safe implementation to load all required data for the processor
Once completed Loaded should return true.
Declaration
public abstract Task Load()
Returns
Type | Description |
---|---|
Task | A task indicating the completion of the load operation |
ProcessCancel(ITransactionalEntity, bool, BaseTransactionProcessor)
Goes through all items in the processor and creates cancellation records for them while also resetting any changes they have back to their original values so the original record stays as is for cancellation
Declaration
protected virtual Task ProcessCancel(ITransactionalEntity cancellingRootItem, bool wasCorrected, BaseTransactionProcessor rootOwningProcessor)
Parameters
Type | Name | Description |
---|---|---|
ITransactionalEntity | cancellingRootItem | The new root item for all the cancellation records |
bool | wasCorrected | Indicates that the system also generated correction records for the original transactional entities too |
BaseTransactionProcessor | rootOwningProcessor | The root processor that is performing this cancel/correct operation. If this is a sub processor then it will be different to the current processor |
Returns
Type | Description |
---|---|
Task | A task indicating the completion of the task |
ProcessCorrect(ITransactionalEntity, TransactionStatus, BaseTransactionProcessor)
Goes through all items in the processor and creates correction records for them
Declaration
protected virtual Task ProcessCorrect(ITransactionalEntity correctingRootItem, TransactionStatus correctionStatus, BaseTransactionProcessor rootOwningProcessor)
Parameters
Type | Name | Description |
---|---|---|
ITransactionalEntity | correctingRootItem | The new root item for all the correction records |
TransactionStatus | correctionStatus | |
BaseTransactionProcessor | rootOwningProcessor | The root processor that is performing this cancel/correct operation. If this is a sub processor then it will be different to the current processor |
Returns
Type | Description |
---|---|
Task | A task indicating the completion of the task |
ProcessOnDBSave()
Handles the status of the root transaction item, and all other transactional items in the processor
Also automatically handles cancelling, cancel/corrects, and automatically creating tasks to process the calculation on the service instead of in the save
Declaration
public virtual Task ProcessOnDBSave()
Returns
Type | Description |
---|---|
Task | A task indicating the completion of the operation |
ProcessTransaction()
Calculates the actual transaction work to be done during a IEntityUpdater.SaveChanges(System.Threading.CancellationToken, bool, System.Data.Common.DbTransaction) , called during ProcessOnDBSave()
Any created/updated/deleted items in this process should also be returned in subsequent calls to GetAllItemsInTransaction
Does nothing in base class, this should be overridden by any implementing processor ensuring the process is run during any saveDeclaration
public virtual Task ProcessTransaction()
Returns
Type | Description |
---|---|
Task |
RollbackChanges()
During process on db save, the context can be left in an inconsistent state if it fails any validation. This is called if the transactional save failed and the context must be put back to a consistent state similar to before ProcessOnDBSave was called.
Most processors are fine running again after a failed transaction save has been fixed by the user.
However some require work to be undone such as cancel/correct objects being created for transactions. The cancel/correct transactions need to be removed.Declaration
public Task RollbackChanges()
Returns
Type | Description |
---|---|
Task |
Remarks
When running in a service this will be disposed of anyway, it is only relevant for when the client is directly connected to the database server.
SetLock(IBaseEntity, bool)
Sets the locked status IBaseEntity
Declaration
public abstract void SetLock(IBaseEntity baseEntity, bool value)
Parameters
Type | Name | Description |
---|---|---|
IBaseEntity | baseEntity | |
bool | value |
StatusValidate(IHeaderTransactionalEntity, IEntityUpdater, IReadOnlyCache, UserInfo, IEntityDescriptorFactory, bool, bool)
Validates the current status of a transaction and throws any exceptions for invalid states such as trying to create a cancelled transaction
Is called by the base processor when ProcessOnDBSave() is running, and can be called by any custom processor whenever to ensure valid states
Declaration
public static Task<bool> StatusValidate(IHeaderTransactionalEntity rootTransaction, IEntityUpdater updater, IReadOnlyCache cache, UserInfo user, IEntityDescriptorFactory entityDescriptorFactory, bool allowCancel, bool finalizeOnlyFromUnchangedCommitted)
Parameters
Type | Name | Description |
---|---|---|
IHeaderTransactionalEntity | rootTransaction | The root transaction to validate |
IEntityUpdater | updater | The context to query and update all entities in the lemonedge platform |
IReadOnlyCache | cache | |
UserInfo | user | |
IEntityDescriptorFactory | entityDescriptorFactory | |
bool | allowCancel | Indicates if the validation should allow cancelled transactions (should only be alowed if processing a cancel, or cancel correct) |
bool | finalizeOnlyFromUnchangedCommitted | Indicates that finalization of a transaction should only be allowed if it was moved from committed to finalized with no other changes |
Returns
Type | Description |
---|---|
Task<bool> |
TaskInit(IEntityUpdater, IReadOnlyCache, UserInfo, BusyProgressReporter)
Use if this transaction processor can be run as a server task
Declaration
protected void TaskInit(IEntityUpdater updater, IReadOnlyCache cache, UserInfo user, BusyProgressReporter progressReporter)
Parameters
Type | Name | Description |
---|---|---|
IEntityUpdater | updater | |
IReadOnlyCache | cache | |
UserInfo | user | |
BusyProgressReporter | progressReporter |
UpdateAllStatuses(IHeaderTransactionalEntity)
This updates all the items in the processor to have the same status
By default this relies on the system having fully loaded the processor (as it uses GetAllItemsInTransactionProcessor(bool))
However this can be overridden to provide a quicker method of loading and updating the affected items rather than performing a full Load()Declaration
protected virtual Task UpdateAllStatuses(IHeaderTransactionalEntity rootItem)
Parameters
Type | Name | Description |
---|---|---|
IHeaderTransactionalEntity | rootItem | The root item whose Status every item should be set to |
Returns
Type | Description |
---|---|
Task | A task indicating the completion of the operation |
UpdateCalculatedProperties(ITransactionalEntity)
Updates calculated properties on the entity (and presumably sub affected entities) such as financial date
Declaration
protected virtual Task UpdateCalculatedProperties(ITransactionalEntity tranEntity)
Parameters
Type | Name | Description |
---|---|---|
ITransactionalEntity | tranEntity |
Returns
Type | Description |
---|---|
Task |
UpdateCommonProperties()
Calls UpdateCommonProperties on all items in this processor such as status
Declaration
protected void UpdateCommonProperties()
UpdateCommonProperties(IHeaderTransactionalEntity, ITransactionalEntity)
Sets all commonn properties for items in this transaction set to the same as the root item Status, RecordStatus and transactiondate are kept the same as the root item
Declaration
protected virtual void UpdateCommonProperties(IHeaderTransactionalEntity rootItem, ITransactionalEntity transactionItem)
Parameters
Type | Name | Description |
---|---|---|
IHeaderTransactionalEntity | rootItem | |
ITransactionalEntity | transactionItem |
UpdateFinacialDate(ITransactionalEntity)
Updates the financial date to the correct one based on the transaction date, for the specified transactional entity.
By default this only works with ITransaction and IGLPosting
Can override to update financial dates on other items in the processorDeclaration
public virtual Task UpdateFinacialDate(ITransactionalEntity tranEntity)
Parameters
Type | Name | Description |
---|---|---|
ITransactionalEntity | tranEntity |
Returns
Type | Description |
---|---|
Task |
Validate()
Performs custom validation to validate this processor and all transactional entities within it
Throws an error for any validation failure
Declaration
public virtual Task Validate()
Returns
Type | Description |
---|---|
Task | A task indicating the completion of this operation |