DocumentsGetCommand.cs 2.5 KB

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