@ -9,87 +9,87 @@ namespace Console.Waterworks.CoOrdinators
{
class CoOrdinator
{
CoOrdinatorAssistant A ssistant = new CoOrdinatorAssistant ( ) ;
ProgramInfoSpecialist P rogInfoSpec = new ProgramInfoSpecialist ( ) ;
ConsoleIOSpecialist C onsoleSpec = new ConsoleIOSpecialist ( ) ;
CommandsSpecialist C ommSpec = new CommandsSpecialist ( ) ;
HelpSpecialist H elpSpec = new HelpSpecialist ( ) ;
CW_Logger L ogger = new CW_Logger ( ) ;
CoOrdinatorAssistant _ a ssistant = new CoOrdinatorAssistant ( ) ;
ProgramInfoSpecialist _ p rogInfoSpec = new ProgramInfoSpecialist ( ) ;
ConsoleIOSpecialist _ c onsoleSpec = new ConsoleIOSpecialist ( ) ;
CommandsSpecialist _ c ommSpec = new CommandsSpecialist ( ) ;
HelpSpecialist _ h elpSpec = new HelpSpecialist ( ) ;
CW_Logger _l ogger = new CW_Logger ( ) ;
internal void PrepareConsoleEnvironment ( )
{
L ogger. LogInfoMessage ( $"Preparing console.." ) ;
C onsoleSpec. PrepareConsoleEnvironment ( ) ;
C onsoleSpec. SetInputPrompt ( $"{P rogInfoSpec.GetProductName()}> " ) ;
L ogger. LogSuccessMessage ( "Console environment is now setup" ) ;
_l ogger . LogInfoMessage ( $"Preparing console.." ) ;
_ c onsoleSpec. PrepareConsoleEnvironment ( ) ;
_ c onsoleSpec. SetInputPrompt ( $"{_p rogInfoSpec.GetProductName()}> " ) ;
_l ogger . LogSuccessMessage ( "Console environment is now setup" ) ;
}
internal void DisplayProgramInfo ( )
{
L ogger. LogInfoMessage ( $"Displaying program information.." ) ;
A ssistant. SetConsoleTitle ( L ogger, ProgInfoSpec , C onsoleSpec) ;
A ssistant. OutputProgramInfo ( L ogger, ProgInfoSpec , C onsoleSpec) ;
_l ogger . LogInfoMessage ( $"Displaying program information.." ) ;
_ a ssistant. SetConsoleTitle ( _l ogger , _ progInfoSpec , _ c onsoleSpec) ;
_ a ssistant. OutputProgramInfo ( _l ogger , _ progInfoSpec , _ c onsoleSpec) ;
}
internal void RunProgram ( string commandsNamespace )
{
L ogger. LogInfoMessage ( "Attempting to building commands library.." ) ;
var commandClasses = C ommSpec. GetCommandClasses ( commandsNamespace ) ;
var commandLibraries = C ommSpec. GetCommandLibraries ( commandClasses ) ;
A ssistant. LogCommandGatheringAttempt ( commandClasses , commandLibraries , L ogger) ;
_l ogger . LogInfoMessage ( "Attempting to building commands library.." ) ;
var commandClasses = _ c ommSpec. GetCommandClasses ( commandsNamespace ) ;
var commandLibraries = _ c ommSpec. GetCommandLibraries ( commandClasses ) ;
_ a ssistant. LogCommandGatheringAttempt ( commandClasses , commandLibraries , _l ogger ) ;
while ( true )
{
var consoleInput = C onsoleSpec. GetInputFromUser ( ) ;
var consoleInput = _ c onsoleSpec. GetInputFromUser ( ) ;
if ( string . IsNullOrEmpty ( consoleInput ) ) continue ;
try
{
L ogger. LogInfoMessage ( "Parsing input from user.." ) ;
_l ogger . LogInfoMessage ( "Parsing input from user.." ) ;
var command = new Command ( consoleInput , commandsNamespace , CW_Constants . COMMAND_CLASS_NAME ) ;
L ogger. LogInfoMessage ( "Attempting to execute command.." ) ;
var result = C ommSpec. ExecuteCommand ( commandsNamespace , command , commandClasses , commandLibraries , C onsoleSpec) ;
C onsoleSpec. WriteOutputToConsole ( result ) ;
L ogger. LogSuccessMessage ( "Command has been executed." ) ;
L ogger. LogNoteMessage ( "An error message does not mean the command did not execute properly or sucessfully." ) ;
_l ogger . LogInfoMessage ( "Attempting to execute command.." ) ;
var result = _ c ommSpec. ExecuteCommand ( commandsNamespace , command , commandClasses , commandLibraries , _ c onsoleSpec) ;
_ c onsoleSpec. WriteOutputToConsole ( result ) ;
_l ogger . LogSuccessMessage ( "Command has been executed." ) ;
_l ogger . LogNoteMessage ( "An error message does not mean the command did not execute properly or sucessfully." ) ;
}
catch ( Exception ex )
{
L ogger. LogErrorMessage ( "Command was not successfully executed. See the error message in console for further details" ) ;
C onsoleSpec. WriteErrorMessage ( ex . Message ) ;
_l ogger . LogErrorMessage ( "Command was not successfully executed. See the error message in console for further details" ) ;
_ c onsoleSpec. WriteErrorMessage ( ex . Message ) ;
}
L ogger. LogInfoMessage ( "Resetting the console's formatting.." ) ;
L ogger. LogNoteMessage ( "This is to make sure no error messages or one-off formating change corrupts the console environment." ) ;
C onsoleSpec. ResetConsoleColour ( ) ;
L ogger. LogSuccessMessage ( "Console's formating has been reset" ) ;
_l ogger . LogInfoMessage ( "Resetting the console's formatting.." ) ;
_l ogger . LogNoteMessage ( "This is to make sure no error messages or one-off formating change corrupts the console environment." ) ;
_ c onsoleSpec. ResetConsoleColour ( ) ;
_l ogger . LogSuccessMessage ( "Console's formating has been reset" ) ;
}
}
internal string DisplayHelpSection ( string commandsNamespace )
{
L ogger. LogInfoMessage ( "Attempting to display help section.." ) ;
var commandClasses = C ommSpec. GetCommandClasses ( commandsNamespace ) ;
_l ogger . LogInfoMessage ( "Attempting to display help section.." ) ;
var commandClasses = _ c ommSpec. GetCommandClasses ( commandsNamespace ) ;
if ( commandClasses . Count = = 0 )
{
L ogger. LogErrorMessage ( "Unable to find any help information. Make sure the commands hace the correct atrributes applied" ) ;
C onsoleSpec. WriteErrorSuffix ( ) ;
_l ogger . LogErrorMessage ( "Unable to find any help information. Make sure the commands hace the correct atrributes applied" ) ;
_ c onsoleSpec. WriteErrorSuffix ( ) ;
return "Unable to find help information" ;
}
L ogger. LogSuccessMessage ( "Found help information" ) ;
L ogger. LogInfoMessage ( "Attempting to display the help information.." ) ;
C onsoleSpec. WriteOutputToConsole ( "Displaying Help section." ) ;
C onsoleSpec. LineBreak ( ) ;
var commandMembers = H elpSpec. GetCommandMembers ( commandClasses ) ;
_l ogger . LogSuccessMessage ( "Found help information" ) ;
_l ogger . LogInfoMessage ( "Attempting to display the help information.." ) ;
_ c onsoleSpec. WriteOutputToConsole ( "Displaying Help section." ) ;
_ c onsoleSpec. LineBreak ( ) ;
var commandMembers = _ h elpSpec. GetCommandMembers ( commandClasses ) ;
foreach ( var command in commandMembers )
{
if ( H elpSpec. ListCommand ( command ) = = true )
if ( _ h elpSpec. ListCommand ( command ) = = true )
{
C onsoleSpec. WriteOutputToConsole ( $"Command Name: {command.Name}" ) ;
C onsoleSpec. WriteOutputToConsole ( $"Parameters: {H elpSpec.GetParametres(command)}" ) ;
C onsoleSpec. WriteOutputToConsole ( $"Description: {H elpSpec.GetDescription(command)}" ) ;
C onsoleSpec. WriteOutputToConsole ( $"Example: {H elpSpec.GetUsageExamples(command)}" ) ;
C onsoleSpec. LineBreak ( ) ;
_ c onsoleSpec. WriteOutputToConsole ( $"Command Name: {command.Name}" ) ;
_ c onsoleSpec. WriteOutputToConsole ( $"Parameters: {_h elpSpec.GetParametres(command)}" ) ;
_ c onsoleSpec. WriteOutputToConsole ( $"Description: {_h elpSpec.GetDescription(command)}" ) ;
_ c onsoleSpec. WriteOutputToConsole ( $"Example: {_h elpSpec.GetUsageExamples(command)}" ) ;
_ c onsoleSpec. LineBreak ( ) ;
}
}
L ogger. LogSuccessMessage ( "Help section displayed in the console" ) ;
_l ogger . LogSuccessMessage ( "Help section displayed in the console" ) ;
return "End of Help section." ;
}
}