AbstractWrkGetCommand.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Quadarax.Foundation.Core.QConsole;
  5. using Quadarax.Foundation.Core.QConsole.Argument;
  6. using Quadarax.Foundation.Core.QConsole.Value;
  7. namespace BO.Console.Commands.Base
  8. {
  9. internal abstract class AbstractWrkGetCommand : AbstractGetCommand
  10. {
  11. #region *** Constants ***
  12. protected const string CS_ARG_NAME_APIK = "akey";
  13. private const string CS_ARG_HINT_APIK = "<api_key>";
  14. private const string CS_ARG_DESC_APIK = "Workspace related API-KEY, if not defined API-KEY is used from config.";
  15. protected const string CS_ARG_NAME_APIKP = "akeyp";
  16. private const string CS_ARG_HINT_APIKP = "<api_key_password>";
  17. private const string CS_ARG_DESC_APIKP = "Workspace related API-KEY password, if not defined API-KEY password is used from config.";
  18. #endregion
  19. #region *** Properties ***
  20. protected string ApiKey { get; private set; }
  21. protected string ApiKeyPassword { get; private set; }
  22. #endregion
  23. #region *** Constructors ***
  24. protected AbstractWrkGetCommand(Engine engine) : base(engine)
  25. {
  26. }
  27. #endregion
  28. #region *** Protected Overrides ***
  29. protected override void BeginExecute()
  30. {
  31. base.BeginExecute();
  32. ApiKey = Configuration.Defaults.Workspace.ApiKey;
  33. ApiKeyPassword = Configuration.Defaults.Workspace.ApiKeyPassword;
  34. var apiKey = GetArgumentValueOrDefault<string>(CS_ARG_NAME_APIK);
  35. var apiKeyPassword = GetArgumentValueOrDefault<string>(CS_ARG_NAME_APIKP);
  36. if (!string.IsNullOrEmpty(apiKey))
  37. ApiKey = apiKey;
  38. if (!string.IsNullOrEmpty(apiKeyPassword))
  39. ApiKey = apiKeyPassword;
  40. if (string.IsNullOrEmpty(ApiKey) || string.IsNullOrEmpty(ApiKeyPassword))
  41. throw new ArgumentException(
  42. $"ApiKey or ApiKeyPassword must be specified by argument {Engine.Configuration.CharacterNamedArgumentSeparator}{CS_ARG_NAME_APIK} or {Engine.Configuration.CharacterNamedArgumentSeparator}{CS_ARG_NAME_APIKP} or specified in configuration file {Constants.CS_CONFIGURATION_FILE} in location 'defaults/workspace/api-key' or 'defaults/workspace/api-key-password'.");
  43. WriteInfo($"Using API-KEY: {ApiKey}");
  44. WriteDebugInfo($"Using API-KEY-PASSWORD: {ApiKeyPassword}");
  45. }
  46. protected override IEnumerable<AbstractArgument> OnSetupArguments()
  47. {
  48. var args = base.OnSetupArguments().ToList();
  49. args.Add(new NamedArgument(CS_ARG_NAME_APIK, CS_ARG_DESC_APIK,CS_ARG_HINT_APIK, TypeValuesEnum.String, string.Empty, false));
  50. args.Add(new NamedArgument(CS_ARG_NAME_APIKP, CS_ARG_DESC_APIKP,CS_ARG_HINT_APIKP, TypeValuesEnum.String, string.Empty, false));
  51. return args;
  52. }
  53. #endregion
  54. }
  55. }