Search Results for

    Show / Hide Table of Contents

    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
    System.Object
    BaseTransactionProcessor
    Implements
    ILockable
    ICanBeRevertedTransactionProcessor
    IBaseDataSetProcessorWithDBSave
    IBaseDataSetProcessor
    IProcessor
    System.IDisposable
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: LemonEdge.API.Processors.Transactional
    Assembly: API.dll
    Syntax
    public abstract class BaseTransactionProcessor : ILockable, ICanBeRevertedTransactionProcessor, IBaseDataSetProcessorWithDBSave, IBaseDataSetProcessor, IProcessor, IDisposable

    Constructors

    BaseTransactionProcessor()

    Creates a new base transaction processor for dynamic construction as part of a task

    Declaration
    public BaseTransactionProcessor()

    BaseTransactionProcessor(IEntityUpdater, IReadOnlyCache, UserInfo)

    Creates a new base transaction with the standard IBaseDataSetProcessor objects

    Declaration
    public BaseTransactionProcessor(IEntityUpdater updater, IReadOnlyCache cache, UserInfo user)
    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

    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 performin 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
    System.Boolean

    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
    System.Boolean

    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
    System.Collections.Generic.IReadOnlyDictionary<System.Guid, System.ValueTuple<ITransactionalEntity, ITransactionalEntity>>

    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
    System.Boolean

    CanWrite

    Indicates if the processor allows items to be written to depending on the users permission and transaction status

    Declaration
    public abstract bool CanWrite { get; }
    Property Value
    Type Description
    System.Boolean

    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 too
    Declaration
    protected virtual bool CommitToFinalizeRequiresTask { get; }
    Property Value
    Type Description
    System.Boolean

    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
    System.Collections.Generic.IReadOnlyDictionary<System.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 FinancialDateCalculator FinancialDateCalculator { get; }
    Property Value
    Type Description
    FinancialDateCalculator

    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
    System.Boolean

    Loaded

    Flag to indicate if the processor has been fully loaded

    Declaration
    public abstract bool Loaded { get; }
    Property Value
    Type Description
    System.Boolean

    Locked

    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 Locked { get; set; }
    Property Value
    Type Description
    System.Boolean

    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
    System.Int16

    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
    System.Boolean

    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
    System.Collections.Generic.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.

    CustomUpdateCancelCorrectedItem(EntityDescriptor, ITransactionalEntity, ITransactionalEntity, Boolean)

    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 isCorrectionRecord

    System.Boolean isCorrectionRecord

    Indicates cancelCorrected is a correction record. It is a cancelling record otherwise.

    Returns
    Type Description
    System.Threading.Tasks.Task

    Dispose()

    Declaration
    public void Dispose()

    Dispose(Boolean)

    Declaration
    protected void Dispose(bool disposing)
    Parameters
    Type Name Description
    System.Boolean 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
    System.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
    System.Threading.Tasks.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 too
    Declaration
    protected virtual Task ForceLoad()
    Returns
    Type Description
    System.Threading.Tasks.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
    System.Collections.Generic.IEnumerable<IBaseEntity>

    An enumeration of all items in this transactional processor

    GetAllItemsInTransactionProcessor(Boolean)

    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
    System.Boolean includeSubProcessors

    Indicates if items in any sub processors should also be returned as well

    Returns
    Type Description
    System.Collections.Generic.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
    System.Boolean

    True if the specified item belongs in this processor

    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
    System.Threading.Tasks.Task

    A task indicating the completion of the load operation

    ProcessCancel(ITransactionalEntity, Boolean, 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

    System.Boolean 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
    System.Threading.Tasks.Task

    A task indicating the completion of the task

    ProcessCorrect(ITransactionalEntity, BaseTransactionProcessor)

    Goes through all items in the processor and creates correction records for them

    Declaration
    protected virtual Task ProcessCorrect(ITransactionalEntity correctingRootItem, BaseTransactionProcessor rootOwningProcessor)
    Parameters
    Type Name Description
    ITransactionalEntity correctingRootItem

    The new root item for all the correction records

    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
    System.Threading.Tasks.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 Task ProcessOnDBSave()
    Returns
    Type Description
    System.Threading.Tasks.Task

    A task indicating the completion of the operation

    ProcessTransaction()

    Calculates the actual transaction work to be done during a SaveChanges(CancellationToken, Boolean, 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 save
    Declaration
    public virtual Task ProcessTransaction()
    Returns
    Type Description
    System.Threading.Tasks.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
    System.Threading.Tasks.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.

    StatusValidate(IHeaderTransactionalEntity, IEntityUpdater, Boolean, Boolean)

    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 void StatusValidate(IHeaderTransactionalEntity rootTransaction, IEntityUpdater updater, 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

    System.Boolean allowCancel

    Indicates if the validation should allow cancelled transactions (should only be alowed if processing a cancel, or cancel correct)

    System.Boolean finalizeOnlyFromUnchangedCommitted

    Indicates that finalization of a transaction should only be allowed if it was moved from committed to finalized with no other changes

    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(Boolean))

    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
    System.Threading.Tasks.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
    System.Threading.Tasks.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 processor
    Declaration
    public virtual Task UpdateFinacialDate(ITransactionalEntity tranEntity)
    Parameters
    Type Name Description
    ITransactionalEntity tranEntity
    Returns
    Type Description
    System.Threading.Tasks.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
    System.Threading.Tasks.Task

    A task indicating the completion of this operation

    Explicit Interface Implementations

    ICanBeRevertedTransactionProcessor.LoadForRevertion()

    Loads all the items in the processor so all their statuses can be reset back to in progress

    Declaration
    Task ICanBeRevertedTransactionProcessor.LoadForRevertion()
    Returns
    Type Description
    System.Threading.Tasks.Task

    A task indicating the completion of the operation

    Implements

    ILockable
    ICanBeRevertedTransactionProcessor
    IBaseDataSetProcessorWithDBSave
    IBaseDataSetProcessor
    IProcessor
    System.IDisposable

    Extension Methods

    MiscExtensions.SetIfNotEqual<T, P>(T, Expression<Func<T, P>>, P)
    ReflectionExtensions.ClearEventInvocations(Object, String)
    StringExtensions.ToCSVFormatString(Object, Type)
    SQLExtensions.ToSQLValue(Object, Boolean)
    In This Article
    Back to top © LemonEdge Technology. All rights reserved.