Table of Contents

Class AbstractCommand

Namespace
Core.CliniCore.Commands
Assembly
Core.CliniCore.dll

Base implementation for all commands providing common infrastructure

public abstract class AbstractCommand : ICommand
Inheritance
AbstractCommand
Implements
Derived
Inherited Members

Constructors

AbstractCommand()

Initializes a new instance of the AbstractCommand class with a unique command identifier and default role-based authorization service.

protected AbstractCommand()

Remarks

The CommandId property is assigned a new Guid value for each instance. The command is configured to use a role-based authorization service by default.

Fields

_lastExecutionParameters

Stores the parameters used in the most recent command execution.

protected CommandParameters? _lastExecutionParameters

Field Value

CommandParameters

Remarks

This field is intended for use by derived classes to access or track the parameters passed to the last executed command. The value may be null if no command has been executed yet or if the parameters were not specified.

_lastExecutionSession

Stores the session context from the most recent execution.

protected SessionContext? _lastExecutionSession

Field Value

SessionContext

Remarks

This field is intended for use by derived classes to access or track the session associated with the last operation. The value may be null if no execution has occurred or if the session is unavailable.

_previousState

Stores the previous state of the object to support undo operations.

protected object? _previousState

Field Value

object

Remarks

This field is used to retain the state prior to a change, enabling the ability to revert to an earlier state if needed.

Properties

CanUndo

Whether this command can be undone - defaults to false

public virtual bool CanUndo { get; }

Property Value

bool

CommandId

Unique identifier for this command instance

public Guid CommandId { get; }

Property Value

Guid

CommandKey

Unique key identifier for this command type Generated from the class name, converted to lowercase without "Command" suffix E.g., "LoginCommand" becomes "login", "CreatePatientCommand" becomes "createpatient"

public virtual string CommandKey { get; }

Property Value

string

CommandName

Name of the command - defaults to class name without "Command" suffix

public virtual string CommandName { get; }

Property Value

string

Description

Description of what this command does

public abstract string Description { get; }

Property Value

string

Methods

CaptureStateForUndo(CommandParameters, SessionContext?)

Captures state before execution for undo - override if undo is supported

protected virtual object? CaptureStateForUndo(CommandParameters parameters, SessionContext? session)

Parameters

parameters CommandParameters
session SessionContext

Returns

object

Execute(CommandParameters, SessionContext?)

Executes the command

public CommandResult Execute(CommandParameters parameters, SessionContext? session)

Parameters

parameters CommandParameters
session SessionContext

Returns

CommandResult

ExecuteCore(CommandParameters, SessionContext?)

Executes the core command logic - must be implemented by derived classes

protected abstract CommandResult ExecuteCore(CommandParameters parameters, SessionContext? session)

Parameters

parameters CommandParameters
session SessionContext

Returns

CommandResult

GetRequiredPermission()

Gets the required permission to execute this command

public abstract Permission? GetRequiredPermission()

Returns

Permission?

LogExecution(SessionContext?)

Logs command execution for audit trail

protected virtual void LogExecution(SessionContext? session)

Parameters

session SessionContext

ToString()

Returns a string that represents the current command, including its name and identifier in a formatted form.

public override string ToString()

Returns

string

A string containing the command name followed by the command identifier in a hyphenated, 32-digit format.

Undo(SessionContext?)

Undoes the command if possible

public virtual CommandResult Undo(SessionContext? session)

Parameters

session SessionContext

Returns

CommandResult

UndoCore(object, SessionContext?)

Performs the undo operation - override if undo is supported

protected virtual CommandResult UndoCore(object previousState, SessionContext? session)

Parameters

previousState object
session SessionContext

Returns

CommandResult

Validate(CommandParameters, SessionContext?)

Validates that the command can be executed

public virtual CommandValidationResult Validate(CommandParameters parameters, SessionContext? session)

Parameters

parameters CommandParameters
session SessionContext

Returns

CommandValidationResult

ValidateAuthorization(SessionContext?)

Validates authorization for the command

protected virtual CommandValidationResult ValidateAuthorization(SessionContext? session)

Parameters

session SessionContext

Returns

CommandValidationResult

ValidateParameters(CommandParameters)

Validates command parameters - override in derived classes

protected abstract CommandValidationResult ValidateParameters(CommandParameters parameters)

Parameters

parameters CommandParameters

The parameters to validate (never null, but may be empty)

Returns

CommandValidationResult

Validation result indicating success or failure with error messages

ValidateSpecific(CommandParameters, SessionContext?)

Performs command-specific validation - override in derived classes if needed

protected virtual CommandValidationResult ValidateSpecific(CommandParameters parameters, SessionContext? session)

Parameters

parameters CommandParameters
session SessionContext

Returns

CommandValidationResult