CommandPattern 1.0.0
This package contains a collection of classes and interfaces to allow for quick and consistent implementation of the command pattern across projects.
|
This is the object that stores commands to be invoked and executes them when told to by the client. It has no knowledge of the implementation of commands beyond their interfaces. More...
Public Member Functions | |
ReadOnlyCollection< ICommand > | GetCommandHistory () |
Get the CommandStream's history of executed Commands, a linear time operation if HistoryCount has reached HistoryDepth More... | |
ReadOnlyCollection< ICommand > | GetCommandQueue () |
Get the queue of commands to be executed by the command stream. More... | |
ReadOnlyCollection< Task > | GetRunningCommandTasks () |
Get the Tasks being being run by AsyncCommands executed by this CommandStream More... | |
CancellationTokenSource | GetRunningTaskCTS (Task task) |
Gets the CancellationTokenSource of a running AsyncCommand's task More... | |
CancellationTokenSource | GetRunningTaskCTS (IAsyncCommand asyncCommand) |
void | CancelRunningCommandTask (Task task) |
Cancels a task if that task is currently running More... | |
void | CancelRunningCommandTask (IAsyncCommand asyncCommand) |
Cancels the task of an IAsyncCommand if that task is currently running. More... | |
ReadOnlyDictionary< Task, Exception > | GetFaultedCommandTasks () |
Get a dictionary of any faulted tasks and the exceptions that they threw More... | |
CommandStream (float _historyDepth=Single.PositiveInfinity) | |
Creates a new CommandStream More... | |
void | QueueCommand (ICommand command) |
This adds a Command to the command Queue More... | |
void | QueueCommands (IEnumerable< ICommand > commands) |
Adds multiple Commands to the queue More... | |
List< ICommand > | DropQueue () |
This will remove all commands from the CommandStream's queue and replace it with a new empty queue. More... | |
ReadOnlyCollection< ICommand > | DropHistory () |
This will remove all commands from the CommandStream's history and replace it with a new empty list. More... | |
bool | TryQueueUndoCommand (IUndoable undoable) |
Attempt to queue's the undo command of a Command object implementing IUndoable if that command exists in this CommandStream's history More... | |
void | ForceQueueUndoCommand (IUndoable undoable) |
Force the stream to queue's the undo command of a Command object implementing IUndoable regardless of whether the command is recorded in this CommandStream's history More... | |
bool | TryPeekNext (out ICommand nextCommand) |
Examine the next command in the commandQueue with out executing it More... | |
void | RequeueNextCommand () |
Removes the next command in the CommandStream's queue, if it has one, and adds it back to the end of the queue. | |
void | SkipNextCommand () |
Removes the next command from the queue without executing it | |
ExecuteCode | TryExecuteNext (out ICommand topCommand) |
Attempts to execute the next command in the queue, returns an enum indicating if it was able to or not or if the queue was empty or the command is async and awaiting completion. More... | |
ExecuteCode | TryExecuteImmediate (ICommand command) |
Bypass the command queue and immediately attempt to execute a command More... | |
ExecuteCode | TryUndoImmediate (IUndoable undoable) |
Bypass the command queue and immediately attempt to execute an IUndoable's undo command if the IUndoable is in the CommandStream's history More... | |
ExecuteCode | ForceTryUndoImmediate (IUndoable undoable) |
Bypass the command queue and immediately attempt to execute an IUndoable's undo command, regardless of wether the IUndoable is in the CommandStream's history More... | |
ExecuteCode | TryExecuteNext () |
Attempts to execute the next command in the queue, returns false if it is empty or the command is IFailable and would fail. More... | |
void | ExecuteFullQueue () |
Execute's Commands from the CommandStream queue until it is empty. Be warned this will not give any indication of commands failing. | |
void | ExecuteFullQueue (out List< ICommand > failedCommands) |
Executes Commands from the CommandStream's queue until it is empty. Returns the a list of any Commands that failed as an out parameter More... | |
Properties | |
bool | QueueEmpty [get] |
Gets commandQueue.Count == 0 | |
float | HistoryDepth [get] |
this is the maximum number of commands that will be recorded in the CommandHistory | |
int | HistoryCount [get] |
Gets the number of Commands currently recorded in the CommandStream's history. | |
int | QueueCount [get] |
Gets the number of Commands currently waiting in the CommandStream's queue. | |
Events | |
Action< Exception > | OnTaskFaulted |
This event will be invoked if one of the tasks from an IAsyncCommand executed by this stream faults. Can be used to throw any exception's caused by tasks rather than storing them on the task object | |
This is the object that stores commands to be invoked and executes them when told to by the client. It has no knowledge of the implementation of commands beyond their interfaces.
SadSapphicGames.CommandPattern.CommandStream.CommandStream | ( | float | _historyDepth = Single.PositiveInfinity | ) |
Creates a new CommandStream
_historyDepth | The depth to which previously executed commands will be recorded. Once this depth is reached the oldest commands will be forgotten first. <remark> To not record history, set to zero. To never forget executed commands, set to positive infinity. </remark> |
void SadSapphicGames.CommandPattern.CommandStream.CancelRunningCommandTask | ( | IAsyncCommand | asyncCommand | ) |
Cancels the task of an IAsyncCommand if that task is currently running.
asyncCommand | The IAsyncCommand to cancel the task off |
void SadSapphicGames.CommandPattern.CommandStream.CancelRunningCommandTask | ( | Task | task | ) |
Cancels a task if that task is currently running
task | The task to cancel |
ReadOnlyCollection< ICommand > SadSapphicGames.CommandPattern.CommandStream.DropHistory | ( | ) |
This will remove all commands from the CommandStream's history and replace it with a new empty list.
<remark> This can be useful if you need the CommandStream to record all of its history but also need it to execute an extremely large number of commands without running out of memory. Even if every command is the same object a CommandStream will run out of memory at 2-3 hundred million commands in its queue or history. </remark>
List< ICommand > SadSapphicGames.CommandPattern.CommandStream.DropQueue | ( | ) |
This will remove all commands from the CommandStream's queue and replace it with a new empty queue.
<remark> This can be useful to rearrange the commands in a queue. Simple preform the needed changes on the returned list and re-queue it </remark>
void SadSapphicGames.CommandPattern.CommandStream.ExecuteFullQueue | ( | out List< ICommand > | failedCommands | ) |
Executes Commands from the CommandStream's queue until it is empty. Returns the a list of any Commands that failed as an out parameter
failedCommands | A list of any Commands in the Queue that failed to execute |
void SadSapphicGames.CommandPattern.CommandStream.ForceQueueUndoCommand | ( | IUndoable | undoable | ) |
Force the stream to queue's the undo command of a Command object implementing IUndoable regardless of whether the command is recorded in this CommandStream's history
<remark>This is equivalent to passing the result of IUndoable.GetUndoCommand() into CommandStream.QueueCommand(Command command) directly</remark>
ExecuteCode SadSapphicGames.CommandPattern.CommandStream.ForceTryUndoImmediate | ( | IUndoable | undoable | ) |
Bypass the command queue and immediately attempt to execute an IUndoable's undo command, regardless of wether the IUndoable is in the CommandStream's history
undoable | the IUndoable to execute the undo command of |
ReadOnlyCollection< ICommand > SadSapphicGames.CommandPattern.CommandStream.GetCommandHistory | ( | ) |
Get the CommandStream's history of executed Commands, a linear time operation if HistoryCount has reached HistoryDepth
ReadOnlyCollection< ICommand > SadSapphicGames.CommandPattern.CommandStream.GetCommandQueue | ( | ) |
Get the queue of commands to be executed by the command stream.
ReadOnlyDictionary< Task, Exception > SadSapphicGames.CommandPattern.CommandStream.GetFaultedCommandTasks | ( | ) |
Get a dictionary of any faulted tasks and the exceptions that they threw
ReadOnlyCollection< Task > SadSapphicGames.CommandPattern.CommandStream.GetRunningCommandTasks | ( | ) |
Get the Tasks being being run by AsyncCommands executed by this CommandStream
CancellationTokenSource SadSapphicGames.CommandPattern.CommandStream.GetRunningTaskCTS | ( | Task | task | ) |
Gets the CancellationTokenSource of a running AsyncCommand's task
task | The task to get the CTS of |
void SadSapphicGames.CommandPattern.CommandStream.QueueCommand | ( | ICommand | command | ) |
void SadSapphicGames.CommandPattern.CommandStream.QueueCommands | ( | IEnumerable< ICommand > | commands | ) |
Adds multiple Commands to the queue
commands | The commands to be queued |
ExecuteCode SadSapphicGames.CommandPattern.CommandStream.TryExecuteImmediate | ( | ICommand | command | ) |
Bypass the command queue and immediately attempt to execute a command
command | The command to immediately be executed |
ExecuteCode SadSapphicGames.CommandPattern.CommandStream.TryExecuteNext | ( | ) |
Attempts to execute the next command in the queue, returns false if it is empty or the command is IFailable and would fail.
ExecuteCode SadSapphicGames.CommandPattern.CommandStream.TryExecuteNext | ( | out ICommand | topCommand | ) |
Attempts to execute the next command in the queue, returns an enum indicating if it was able to or not or if the queue was empty or the command is async and awaiting completion.
topCommand | The command that was next in the queue, null if the queue was empty |
bool SadSapphicGames.CommandPattern.CommandStream.TryPeekNext | ( | out ICommand | nextCommand | ) |
Examine the next command in the commandQueue with out executing it
nextCommand | The next command in the queue, null if empty |
bool SadSapphicGames.CommandPattern.CommandStream.TryQueueUndoCommand | ( | IUndoable | undoable | ) |
Attempt to queue's the undo command of a Command object implementing IUndoable if that command exists in this CommandStream's history
ExecuteCode SadSapphicGames.CommandPattern.CommandStream.TryUndoImmediate | ( | IUndoable | undoable | ) |
Bypass the command queue and immediately attempt to execute an IUndoable's undo command if the IUndoable is in the CommandStream's history
undoable | the IUndoable to execute the undo command of |