CmdSelection.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Quadarax.Foundation.Core.Console;
  5. using Quadarax.Foundation.Core.QConsole.Argument;
  6. using Quadarax.Foundation.Core.QConsole.Attributes;
  7. using Quadarax.Foundation.Core.QConsole.Command.Base;
  8. using Quadarax.Foundation.Core.QConsole.Value;
  9. using Quadarax.Foundation.Core.Value;
  10. namespace Quadarax.Foundation.Core.QConsole.Command.Defaults
  11. {
  12. [CommandDefinition]
  13. public class CmdSelection : AbstractListCommand
  14. {
  15. #region *** Properties ***
  16. public override string Name => Constants.Commands.Selection.Name;
  17. public override string Description => Constants.Commands.Selection.Description;
  18. #endregion
  19. #region *** Constructors ***
  20. public CmdSelection(Engine engine) : base(engine)
  21. {
  22. }
  23. #endregion
  24. #region *** Protected overrides ***
  25. protected override IEnumerable<AbstractArgument> OnSetupArguments()
  26. {
  27. var arguments = base.OnSetupArguments().ToList();
  28. arguments.AddRange(
  29. new []
  30. {
  31. new FlagArgument(Constants.Arguments.Selection.List.Code,
  32. Constants.Arguments.Selection.List.Description, Constants.Arguments.Selection.List.Hint, true),
  33. new FlagArgument(Constants.Arguments.Selection.Clear.Code,
  34. Constants.Arguments.Selection.Clear.Description, Constants.Arguments.Selection.Clear.Hint,
  35. false),
  36. new NamedArgument(Constants.Arguments.Selection.Delete.Code,
  37. Constants.Arguments.Selection.Delete.Description, Constants.Arguments.Selection.Delete.Hint,
  38. TypeValuesEnum.String, string.Empty, false),
  39. });
  40. return arguments;
  41. }
  42. protected override void OnWriteEntry(ConsoleWriter writer, ISelectionEntry entry)
  43. {
  44. writer.Write("ID: ");
  45. writer.Write(entry.GetIdentifier());
  46. writer.Write("\t");
  47. writer.Write("Value: ");
  48. writer.WriteLine(entry.GetDisplayValue());
  49. }
  50. protected override Result EndExecute(Result incommingResult)
  51. {
  52. var result = base.EndExecute(incommingResult);
  53. using (var writerWhite = new ConsoleWriter(ConsoleColor.White))
  54. {
  55. writerWhite.WriteLine(
  56. $"For selection variable usage use {QConsole.Defaults.RoleCharacters.SelectionVariablePrefixCharacter}<selection_ordinal>.<property_name> in console.");
  57. }
  58. return result;
  59. }
  60. protected override Result OnExecute()
  61. {
  62. SetModel(Engine.Selections);
  63. return new Result();
  64. }
  65. #endregion
  66. }
  67. }