Browse Source

Added comments, fixed spelling mistakes and deleted unused code.

merge-requests/1/head
Craig Oates 7 years ago
parent
commit
0373bcc6f8
  1. 2
      Console.Waterworks/CW_Console/ConsoleCommands.cs
  2. 6
      Console.Waterworks/Console.Waterworks/Assistants/CoOrdinatorAssistant.cs
  3. 29
      Console.Waterworks/Console.Waterworks/CW_Liaison.cs
  4. 92
      Console.Waterworks/Console.Waterworks/CoOrdinators/CoOrdinator.cs
  5. 7
      Console.Waterworks/Console.Waterworks/Constants/CW_Constants.cs
  6. 5
      Console.Waterworks/Console.Waterworks/Properties/AssemblyInfo.cs
  7. 26
      Console.Waterworks/Console.Waterworks/Specialists/CommandsSpecialist.cs

2
Console.Waterworks/CW_Console/ConsoleCommands.cs

@ -43,7 +43,7 @@ namespace CW_Console
[ListCommand()]
[Description("Take the int and double and adds them together.")]
[Parameters("<int> int1, <double1> double1")]
[Usage("CW_Console> 31 25.4")]
[Usage("CW_Console> Command5 31 25.4")]
public static string Command5(int int1, double double1) => $"Command5 has completed... {int1} and {double1} was entered and make {int1 + double1} when added together";
[ListCommand()]

6
Console.Waterworks/Console.Waterworks/Assistants/CoOrdinatorAssistant.cs

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using Console.Waterworks.Constants;
using Console.Waterworks.Loggers;
using Console.Waterworks.Specialists;
using System;
using System.Collections.Generic;
using System.Reflection;
using Console.Waterworks.Constants;
namespace Console.Waterworks.Assistants
{

29
Console.Waterworks/Console.Waterworks/CW_Liaison.cs

@ -1,23 +1,32 @@
using Console.Waterworks.CoOrdinators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Console.Waterworks
{
public class CW_Liaison
{
CoOrdinator kevin = new CoOrdinator();
CoOrdinator _kevin = new CoOrdinator();
/// <summary>
/// Hands control over to Console.Waterworks so the program can "run" as intended.
/// </summary>
/// <param name="consoleCommandsNamespace">The place where the program's command-methods are.</param>
/// <param name="includeProgramInfo">Information about the console program, stated in Assembly Information.</param>
public void Run(string consoleCommandsNamespace,bool includeProgramInfo)
{
kevin.PrepareConsoleEnvironment();
if (includeProgramInfo == true) kevin.DisplayProgramInfo();
kevin.RunProgram(consoleCommandsNamespace);
_kevin.PrepareConsoleEnvironment();
if (includeProgramInfo == true) _kevin.DisplayProgramInfo();
_kevin.RunProgram(consoleCommandsNamespace);
}
public string RequestHelpDocumentation(string consoleCommandsNamespace) => kevin.DisplayHelpSection(consoleCommandsNamespace);
/// <summary>
/// Displays all the attribute information it can find, attached to the command-methods, at run-time.
/// </summary>
/// <remarks>
/// The returned string does not include the "help" information.
/// It returns a string to indicate the method has finished collating the attribute information and displaying the information in the console.
/// This method is intended to be use in a command-method. So, it aims to be compatible with command-method behaviour
/// </remarks>
/// <param name="consoleCommandsNamespace">The location of the programs command-method.</param>
public string RequestHelpDocumentation(string consoleCommandsNamespace) => _kevin.DisplayHelpSection(consoleCommandsNamespace);
}
}

92
Console.Waterworks/Console.Waterworks/CoOrdinators/CoOrdinator.cs

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

7
Console.Waterworks/Console.Waterworks/Constants/CW_Constants.cs

@ -3,12 +3,15 @@
class CW_Constants
{
/// <summary>
/// This represents the maximum number of properties the console can display when the client "DisplayProgramInfo" to true. This is used mostly for logging purposes.
/// This represents the maximum number of properties the console can display when the client "DisplayProgramInfo" to true.
/// This is used mostly for logging purposes.
/// </summary>
public const int PROGRAM_INFO_PROPERTIES_COUNT = 4;
/// <summary>
/// This specifies the name of the class WaterWorks looks for when it tries to build its command library. This class should not be in WaterWorks. It should be in the clients console program.
/// This specifies the name of the class Console.WaterWorks looks for when it tries to build its command library.
/// This class should not be in Console.WaterWorks.
/// It should be in the clients console program.
/// </summary>
public const string COMMAND_CLASS_NAME = "ConsoleCommands";
}

5
Console.Waterworks/Console.Waterworks/Properties/AssemblyInfo.cs

@ -1,6 +1,5 @@
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following

26
Console.Waterworks/Console.Waterworks/Specialists/CommandsSpecialist.cs

@ -1,15 +1,15 @@
using System;
using Console.Waterworks.Assistants;
using Console.Waterworks.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using Console.Waterworks.Models;
using System.Reflection;
using Console.Waterworks.Assistants;
namespace Console.Waterworks.Specialists
{
class CommandsSpecialist
{
CommandsAssistant Assistant = new CommandsAssistant();
CommandsAssistant _assistant = new CommandsAssistant();
internal List<Type> GetCommandClasses(string commandsNameSpace)
{
@ -39,21 +39,21 @@ namespace Console.Waterworks.Specialists
internal string ExecuteCommand(string commandsNamespace, Command command, List<Type> commandClasses, Dictionary<string, Dictionary<string, IEnumerable<ParameterInfo>>> commandLibraries, ConsoleIOSpecialist consoleSpec)
{
var classValidated = Assistant.ValidateClass(command, commandLibraries);
var commandNameValidated = Assistant.ValidateCommand(command, commandLibraries);
var classValidated = _assistant.ValidateClass(command, commandLibraries);
var commandNameValidated = _assistant.ValidateCommand(command, commandLibraries);
Dictionary<string, IEnumerable<ParameterInfo>> methodDictionary;
if (classValidated != true || commandNameValidated != true)
return Assistant.ExecuteBadCommandProcedure(command, consoleSpec);
return _assistant.ExecuteBadCommandProcedure(command, consoleSpec);
else
methodDictionary = commandLibraries[command.ClassName];
var paramInfoList = methodDictionary[command.Name].ToList();
var paramsValidated = Assistant.ValidateParamArguments(command, paramInfoList);
var paramsValidated = _assistant.ValidateParamArguments(command, paramInfoList);
if (paramsValidated == false)
return Assistant.ExecuteMissingArgumentProcedure(command, paramInfoList, consoleSpec);
var methodParametreValueList = Assistant.GetParametreValueList(command, paramInfoList);
var typeInfo = Assistant.BuildCommandLibraryClass(command, commandsNamespace);
var inputArguments = Assistant.GetInputArguments(methodParametreValueList);
var result = Assistant.InvokeCommand(command, typeInfo, inputArguments);
return _assistant.ExecuteMissingArgumentProcedure(command, paramInfoList, consoleSpec);
var methodParametreValueList = _assistant.GetParametreValueList(command, paramInfoList);
var typeInfo = _assistant.BuildCommandLibraryClass(command, commandsNamespace);
var inputArguments = _assistant.GetInputArguments(methodParametreValueList);
var result = _assistant.InvokeCommand(command, typeInfo, inputArguments);
return result;
}
}

Loading…
Cancel
Save