Removed ICommandsManager and its usages

This commit is contained in:
Chris Bell 2025-01-01 21:15:32 -06:00
parent 83bc55526a
commit c89cd76396
7 changed files with 10 additions and 43 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

View File

@ -8,10 +8,10 @@ public class DeafultCogwheelConsole : ICogwheelConsole
{
public string OpeningMessage { get; set; } = "** COGWHEEL CONSOLE **";
public bool IsRunning { get; set; }
public ICommandsManager CommandsManager { get; set; }
public CommandsManager CommandsManager { get; set; }
public void Initialize(ICommandsManager commandsManager)
public void Initialize(CommandsManager commandsManager)
{
CommandsManager = commandsManager;
CommandsManager.RegisterObject(this);

View File

@ -3,7 +3,7 @@
using Cogwheel;
ICogwheelConsole cogwheelConsole = new DeafultCogwheelConsole();
ICommandsManager commandsManager = new CommandsManager(cogwheelConsole);
CommandsManager commandsManager = new CommandsManager(cogwheelConsole);
COGWHEEL.Initialize(commandsManager, cogwheelConsole);

View File

@ -11,10 +11,10 @@ public static class COGWHEEL
* -[ ]
*/
private static ICommandsManager _commandsManager;
private static CommandsManager _commandsManager;
private static ICogwheelConsole _console;
public static void Initialize(ICommandsManager commandsManager, ICogwheelConsole console)
public static void Initialize(CommandsManager commandsManager, ICogwheelConsole console)
{
_commandsManager = commandsManager;
_console = console;

View File

@ -6,7 +6,7 @@ using Exception = System.Exception;
namespace Cogwheel;
public class CommandsManager : ICommandsManager
public class CommandsManager
{
public ICogwheelConsole CogwheelConsole { get; set; }
@ -74,7 +74,7 @@ public class CommandsManager : ICommandsManager
return ExecuteCommand(CurrentContext, command.Value);
}
CogwheelConsole.LogWarning($"Command '{command.Value.Item1.Name}' is not static and no valid context was provided, searching for first registered context of type '{command.Value.Item1.Method.DeclaringType}'");
//CogwheelConsole.LogWarning($"Command '{command.Value.Item1.Name}' is not static and no valid context was provided, searching for first registered context of type '{command.Value.Item1.Method.DeclaringType}'");
context = GetFirstValidRegisteredContext(command.Value.Item1.Method.DeclaringType);
if (context is null)
{

View File

@ -4,9 +4,9 @@ public interface ICogwheelConsole
{
public string OpeningMessage { get; set; }
public bool IsRunning { get; set; }
public ICommandsManager CommandsManager { get; set; }
public CommandsManager CommandsManager { get; set; }
public void Initialize(ICommandsManager commandsManager); // Make sure to pass the CommandsManager instance to the Console
public void Initialize(CommandsManager commandsManager); // Make sure to pass the CommandsManager instance to the Console
public void Log(string message);
public void LogError(string message);
public void LogWarning(string message);

View File

@ -1,33 +0,0 @@
using System.Reflection;
namespace Cogwheel;
public interface ICommandsManager
{
public ICogwheelConsole CogwheelConsole { get; set; }
public string CommandPattern { get; set; }
public List<Assembly> Assemblies { get; set; }
public Dictionary<string, ICommand> Commands { get; set; }
public Dictionary<Type, Func<string, object>> CustomParsers { get; set; }
public object? CurrentContext { get; set; }
public Guid? CurrentContextGuid { get; set; }
public Dictionary<Guid, object> RegisteredObjectInstances { get; set; }
public Dictionary<object, Guid> RegisteredObjectGuids { get; set; }
public void RegisterObject(object obj);
public (ICommand, List<object>)? GetCommandAndArgsFromString(string input);
public bool RunCommand(string input, object? context = null);
public string GetCommandUsage(ICommand command);
public bool ExecuteCommand(object obj, (ICommand command, List<object> args) command);
public bool TryParseParameter(Type parameterType, string parameterString, out object parsedValue);
public ICommand? GetCommandByName(string commandName);
// Context related stuff
public bool IsCommandContextValid(ICommand command, object? context = null);
public bool SetContext(object context);
public bool SetContext(Guid guid);
public bool SetContext(string guidString);
public object? GetFirstValidRegisteredContext(Type type);
public Guid GetGuidFromContext(object? context = null);
}