| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Quadarax.Foundation.Core.QConsole;
- using Quadarax.Foundation.Core.QConsole.Argument;
- using Quadarax.Foundation.Core.QConsole.Value;
- namespace BO.Console.Commands.Base
- {
- internal abstract class AbstractWorkspaceCommand : BaseCommand
- {
- #region *** Constants ***
- protected const string CS_ARG_NAME_APIK = "akey";
- private const string CS_ARG_HINT_APIK = "<api_key>";
- private const string CS_ARG_DESC_APIK = "Workspace related API-KEY, if not defined API-KEY is used from config.";
- protected const string CS_ARG_NAME_APIKP = "akeyp";
- private const string CS_ARG_HINT_APIKP = "<api_key_password>";
- private const string CS_ARG_DESC_APIKP = "Workspace related API-KEY password, if not defined API-KEY password is used from config.";
- #endregion
- #region *** Properties ***
- protected string ApiKey { get; private set; }
- protected string ApiKeyPassword { get; private set; }
- #endregion
- #region *** Constructors ***
- protected AbstractWorkspaceCommand(Engine engine) : base(engine)
- {
- }
- #endregion
- #region *** Protected Overrides ***
- protected override void BeginExecute()
- {
- base.BeginExecute();
- ApiKey = Configuration.Defaults.Workspace.ApiKey;
- ApiKeyPassword = Configuration.Defaults.Workspace.ApiKeyPassword;
- var apiKey = GetArgumentValueOrDefault<string>(CS_ARG_NAME_APIK);
- var apiKeyPassword = GetArgumentValueOrDefault<string>(CS_ARG_NAME_APIKP);
- if (!string.IsNullOrEmpty(apiKey))
- ApiKey = apiKey;
- if (!string.IsNullOrEmpty(apiKeyPassword))
- ApiKeyPassword = apiKeyPassword;
- if (string.IsNullOrEmpty(ApiKey) || string.IsNullOrEmpty(ApiKeyPassword))
- throw new ArgumentException(
- $"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'.");
- WriteInfo($"Using API-KEY: {ApiKey}");
- WriteDebugInfo($"Using API-KEY-PASSWORD: {ApiKeyPassword}");
- }
- protected override IEnumerable<AbstractArgument> OnSetupArguments()
- {
- var args = base.OnSetupArguments().ToList();
- args.Add(new NamedArgument(CS_ARG_NAME_APIK, CS_ARG_DESC_APIK,CS_ARG_HINT_APIK, TypeValuesEnum.String, string.Empty, false));
- args.Add(new NamedArgument(CS_ARG_NAME_APIKP, CS_ARG_DESC_APIKP,CS_ARG_HINT_APIKP, TypeValuesEnum.String, string.Empty, false));
- return args;
- }
- #endregion
- }
- }
|