|
@@ -1,8 +1,8 @@
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
-using System.Text;
|
|
|
|
|
using Quadarax.Foundation.Core.Console;
|
|
using Quadarax.Foundation.Core.Console;
|
|
|
|
|
+using Quadarax.Foundation.Core.Logging;
|
|
|
using Quadarax.Foundation.Core.QConsole.Argument;
|
|
using Quadarax.Foundation.Core.QConsole.Argument;
|
|
|
using Quadarax.Foundation.Core.QConsole.Context;
|
|
using Quadarax.Foundation.Core.QConsole.Context;
|
|
|
using Quadarax.Foundation.Core.QConsole.Extensions;
|
|
using Quadarax.Foundation.Core.QConsole.Extensions;
|
|
@@ -24,9 +24,10 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Base
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Private Fields ***
|
|
#region *** Private Fields ***
|
|
|
- private Engine _engine;
|
|
|
|
|
- private IDictionary<string, AbstractArgument> _arguments;
|
|
|
|
|
|
|
+ private readonly Engine _engine;
|
|
|
|
|
+ private readonly IDictionary<string, AbstractArgument> _arguments;
|
|
|
protected ICommandContext _context;
|
|
protected ICommandContext _context;
|
|
|
|
|
+ private readonly ILog? _log;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Properties ***
|
|
#region *** Properties ***
|
|
@@ -42,9 +43,10 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Base
|
|
|
|
|
|
|
|
#region *** Constructor ***
|
|
#region *** Constructor ***
|
|
|
|
|
|
|
|
- public AbstractCommand(Engine engine)
|
|
|
|
|
|
|
+ protected AbstractCommand(Engine engine)
|
|
|
{
|
|
{
|
|
|
_engine = engine ?? throw new ArgumentNullException(nameof(engine));
|
|
_engine = engine ?? throw new ArgumentNullException(nameof(engine));
|
|
|
|
|
+ _log = engine.Configuration.DefaultLoggerFactory?.GetLogger(GetType());
|
|
|
_arguments = new Dictionary<string, AbstractArgument>();
|
|
_arguments = new Dictionary<string, AbstractArgument>();
|
|
|
_context = _engine.Context.CreateCommandContext();
|
|
_context = _engine.Context.CreateCommandContext();
|
|
|
WriteDebugInfo($"Context for command '{Name}' created: {_context}");
|
|
WriteDebugInfo($"Context for command '{Name}' created: {_context}");
|
|
@@ -92,6 +94,7 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Base
|
|
|
{
|
|
{
|
|
|
return "Command: " + Name;
|
|
return "Command: " + Name;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Private operations ***
|
|
#region *** Private operations ***
|
|
@@ -110,7 +113,7 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Base
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
- for (int i = 1; i < args.Length; i++)
|
|
|
|
|
|
|
+ for (var i = 1; i < args.Length; i++)
|
|
|
{
|
|
{
|
|
|
var arg = args[i];
|
|
var arg = args[i];
|
|
|
var index = i - 1;
|
|
var index = i - 1;
|
|
@@ -257,7 +260,7 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Base
|
|
|
DumpException(e, string.Empty);
|
|
DumpException(e, string.Empty);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void DumpException(Exception e, string prefix)
|
|
|
|
|
|
|
+ private void DumpException(Exception? e, string prefix)
|
|
|
{
|
|
{
|
|
|
while (e != null)
|
|
while (e != null)
|
|
|
{
|
|
{
|
|
@@ -296,7 +299,7 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Base
|
|
|
}
|
|
}
|
|
|
protected virtual IEnumerable<AbstractArgument> OnSetupArguments()
|
|
protected virtual IEnumerable<AbstractArgument> OnSetupArguments()
|
|
|
{
|
|
{
|
|
|
- return new AbstractArgument[0];
|
|
|
|
|
|
|
+ return Array.Empty<AbstractArgument>();
|
|
|
//{
|
|
//{
|
|
|
// new FlagArgument(Constants.Arguments.General.DebugMode.Code, Constants.Arguments.General.DebugMode.Description, Constants.Arguments.General.DebugMode.Hint, true),
|
|
// new FlagArgument(Constants.Arguments.General.DebugMode.Code, Constants.Arguments.General.DebugMode.Description, Constants.Arguments.General.DebugMode.Hint, true),
|
|
|
//};
|
|
//};
|
|
@@ -330,6 +333,17 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Base
|
|
|
{
|
|
{
|
|
|
return incommingResult;
|
|
return incommingResult;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ protected virtual void Log(LogSeverityEnum type, int code, string message, Exception e = null)
|
|
|
|
|
+ {
|
|
|
|
|
+ _log?.Log(type, code, message,e);
|
|
|
|
|
+ }
|
|
|
|
|
+ protected void Log(LogSeverityEnum type, string message, Exception e = null)
|
|
|
|
|
+ {
|
|
|
|
|
+ Log(type,0, message,e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region *** Protected operations ***
|
|
#region *** Protected operations ***
|
|
@@ -339,7 +353,7 @@ namespace Quadarax.Foundation.Core.QConsole.Command.Base
|
|
|
throw new Exception($"Argument '{code}' is not defined.");
|
|
throw new Exception($"Argument '{code}' is not defined.");
|
|
|
return _arguments[code];
|
|
return _arguments[code];
|
|
|
}
|
|
}
|
|
|
- protected AbstractArgument GetArgument(int ordinalPosition)
|
|
|
|
|
|
|
+ protected AbstractArgument? GetArgument(int ordinalPosition)
|
|
|
{
|
|
{
|
|
|
return _arguments.Values.Where(x => x.IsPositional()).Skip(ordinalPosition).FirstOrDefault();
|
|
return _arguments.Values.Where(x => x.IsPositional()).Skip(ordinalPosition).FirstOrDefault();
|
|
|
}
|
|
}
|