WorkspacesGetCommand.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using BO.AppServer.Metadata.Enums;
  4. using BO.Console.Commands.Base;
  5. using Microsoft.VisualBasic;
  6. using Quadarax.Foundation.Core.QConsole;
  7. using Quadarax.Foundation.Core.QConsole.Argument;
  8. using Quadarax.Foundation.Core.QConsole.Attributes;
  9. using Quadarax.Foundation.Core.QConsole.Value;
  10. using Quadarax.Foundation.Core.Value;
  11. namespace BO.Console.Commands.Workspace
  12. {
  13. [CommandDefinition]
  14. internal class WorkspacesGetCommand : AbstractListScopedCommand<AppServer.Metadata.Enums.WorkspaceScopeEnums>
  15. {
  16. #region *** Constants ***
  17. private const string CS_CMD_WRKSPGET_NAME = "workspace_list";
  18. private const string CS_CMD_WRKSPGET_DESCR = "Get list of workspaces by specification scope.";
  19. private const string CS_ARG_NAME_USER = "user";
  20. private const string CS_ARG_HINT_USER = "<user_name>";
  21. private const string CS_ARG_DESC_USER = "User name context when scope 'My' is selected. If not specified, use current user context.";
  22. #endregion
  23. #region *** Properties ***
  24. public override string Name => CS_CMD_WRKSPGET_NAME;
  25. public override string Description => CS_CMD_WRKSPGET_DESCR;
  26. #endregion
  27. #region *** Constructor ***
  28. public WorkspacesGetCommand(Engine engine) : base(engine)
  29. {
  30. }
  31. #endregion
  32. #region *** EXECUTE ***
  33. protected override Result OnExecute()
  34. {
  35. var workspaces = Client.GetWorkspacesAsync(Scope,GetArgumentValueOrDefault<string>(CS_ARG_NAME_USER), Paging).Result;
  36. WriteDtoToConsole(workspaces,"Id","Name","Created","DocumentsCount", "ApiKey", "ApiPassword");
  37. return new Result();
  38. }
  39. #endregion
  40. #region *** Private operations ***
  41. protected override void OnValidateArguments()
  42. {
  43. base.OnValidateArguments();
  44. if (Scope != WorkspaceScopeEnums.My && WasArgumentSpecified(CS_ARG_NAME_USER))
  45. {
  46. WriteWarning($"Argument {Engine.Configuration.CharacterNamedArgumentSeparator}{CS_ARG_NAME_USER} is not allowed in scope '{Scope}'. Skipped.");
  47. var arg = GetArgument(CS_ARG_NAME_USER);
  48. arg.SetValueAsDefault();
  49. }
  50. }
  51. protected override IEnumerable<AbstractArgument> OnSetupArguments()
  52. {
  53. var args = base.OnSetupArguments().ToList();
  54. args.Add(new NamedArgument(CS_ARG_NAME_USER, CS_ARG_DESC_USER, CS_ARG_HINT_USER, TypeValuesEnum.String, string.Empty, false));
  55. return args;
  56. }
  57. #endregion
  58. }
  59. }