BaseCommand.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System.Collections.Generic;
  2. using BO.Connector.Console;
  3. using Quadarax.Foundation.Core.QConsole;
  4. using Quadarax.Foundation.Core.QConsole.Argument;
  5. using Quadarax.Foundation.Core.QConsole.Value;
  6. // ReSharper disable InconsistentNaming
  7. namespace BO.Console.Commands.Base
  8. {
  9. internal abstract class BaseCommand : BaseLocalCommand
  10. {
  11. #region *** Constants ***
  12. protected const string CS_ARG_NAME_DUMP = "dump";
  13. private const string CS_ARG_HINT_DUMP = "<is_dump_reponses>";
  14. private const string CS_ARG_DESC_DUMP = "Flag if set dumps incomming json messages.";
  15. protected const string CS_ARG_NAME_DEBUG = "dbg";
  16. private const string CS_ARG_HINT_DEBUG = "<is_debug_mode>";
  17. private const string CS_ARG_DESC_DEBUG = "Flag if set writes debug messages.";
  18. protected const string CS_ARG_NAME_USER = "user";
  19. private const string CS_ARG_HINT_USER = "<user_name>";
  20. private const string CS_ARG_DESC_USER = "User name context. If not specified use default user context (who is logged in console).";
  21. protected const string CS_ARG_NAME_FORCE = "force";
  22. private const string CS_ARG_HINT_FORCE = "<is_force>";
  23. private const string CS_ARG_DESC_FORCE = "Flag if set, then overrite existing entity, otherwise cancel operation.";
  24. #endregion
  25. protected Connection Client { get; private set; }
  26. protected string UserName { get; private set; }
  27. protected BaseCommand(Engine engine) : base(engine)
  28. {
  29. }
  30. protected override void OnInitialize()
  31. {
  32. base.OnInitialize();
  33. Client = new Connection(Configuration.ApiBaseUrl, Configuration.ApiTimeout, this, GetArgumentValueOrDefault<bool>(CS_ARG_NAME_DUMP));
  34. Client.Open(Configuration.ApiUser, Configuration.ApiUserPwd, Configuration.ApiMagic);
  35. }
  36. protected override void OnValidateArguments()
  37. {
  38. base.OnValidateArguments();
  39. if (ContainsArgument(CS_ARG_NAME_USER))
  40. UserName = GetArgumentValueOrDefault<string>(CS_ARG_NAME_USER);
  41. }
  42. protected void AppendUserArgument(IList<AbstractArgument> args, string alternativeUserDescription = null)
  43. {
  44. args.Add(new NamedArgument(CS_ARG_NAME_USER, string.IsNullOrEmpty(alternativeUserDescription)? CS_ARG_DESC_USER : alternativeUserDescription, CS_ARG_HINT_USER, TypeValuesEnum.String, string.Empty, false));
  45. }
  46. }
  47. }