|
|
@@ -4,6 +4,7 @@ using System.Linq;
|
|
|
using Quadarax.Foundation.Common.Console;
|
|
|
using Quadarax.Foundation.Common.Value;
|
|
|
using Quadarax.Foundation.QConsole.Argument;
|
|
|
+using Quadarax.Foundation.QConsole.Context;
|
|
|
using Quadarax.Foundation.QConsole.Extensions;
|
|
|
|
|
|
namespace Quadarax.Foundation.QConsole.Command.Base
|
|
|
@@ -13,6 +14,7 @@ namespace Quadarax.Foundation.QConsole.Command.Base
|
|
|
#region *** Private Fields ***
|
|
|
private Engine _engine;
|
|
|
private IDictionary<string, AbstractArgument> _arguments;
|
|
|
+ protected ICommandContext _context;
|
|
|
#endregion
|
|
|
|
|
|
#region *** Properties ***
|
|
|
@@ -29,6 +31,8 @@ namespace Quadarax.Foundation.QConsole.Command.Base
|
|
|
{
|
|
|
_engine = engine ?? throw new ArgumentNullException(nameof(engine));
|
|
|
_arguments = new Dictionary<string, AbstractArgument>();
|
|
|
+ _context = _engine.Context.CreateCommandContext();
|
|
|
+ WriteDebugInfo($"Context for command '{Name}' created: {_context}");
|
|
|
var args = SetupArguments();
|
|
|
foreach (var arg in args)
|
|
|
_arguments.Add(arg.Code, arg);
|
|
|
@@ -50,6 +54,9 @@ namespace Quadarax.Foundation.QConsole.Command.Base
|
|
|
arg.SetValueAsDefault();
|
|
|
ParseInput(input);
|
|
|
|
|
|
+ if (_engine.Configuration.ShowStatusOnEveryCommand)
|
|
|
+ ShowContextStatus(writer);
|
|
|
+
|
|
|
var result = OnExecute();
|
|
|
result = EndExecute(result);
|
|
|
|
|
|
@@ -194,6 +201,23 @@ namespace Quadarax.Foundation.QConsole.Command.Base
|
|
|
debug.WriteDebugLine(text);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void ShowContextStatus(ConsoleWriter writer)
|
|
|
+ {
|
|
|
+ using (var writerBlue = new ConsoleWriter(ConsoleColor.Blue))
|
|
|
+ {
|
|
|
+ using (var writerYellow = new ConsoleWriter(ConsoleColor.Magenta))
|
|
|
+ {
|
|
|
+ writer.WriteLine("Engine context:");
|
|
|
+ writerBlue.Write(_engine.Context.ToString()).Write(" : ");
|
|
|
+ writerYellow.WriteLine(_engine.Context.Status);
|
|
|
+ writer.WriteLine("Command context:");
|
|
|
+ writerBlue.Write(_context.ToString()).Write(" : ");
|
|
|
+ writerYellow.WriteLine(_context.Status);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region *** Protected virtuals ***
|
|
|
@@ -235,6 +259,10 @@ namespace Quadarax.Foundation.QConsole.Command.Base
|
|
|
return _arguments.ContainsKey(code);
|
|
|
}
|
|
|
|
|
|
+ protected TContext GetContext<TContext>() where TContext : class, ICommandContext
|
|
|
+ {
|
|
|
+ return (TContext)_context;
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
}
|