RunCommand.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using BO.ProcessServer.Business;
  3. using BO.ProcessServer.Commands.Base;
  4. using Quadarax.Foundation.Core.NLog;
  5. using Quadarax.Foundation.Core.QConsole;
  6. using Quadarax.Foundation.Core.QConsole.Attributes;
  7. using Quadarax.Foundation.Core.Value;
  8. // ReSharper disable InconsistentNaming
  9. namespace BO.ProcessServer.Commands
  10. {
  11. [CommandDefinition]
  12. internal class RunCommand : BaseLocalCommand
  13. {
  14. #region *** Constants ***
  15. private const string CS_CMD_RUN_NAME = "run";
  16. private const string CS_CMD_RUN_DESCR = "Runs entire ProcessServer instance.";
  17. #endregion
  18. #region *** Properties ***
  19. public override string Name => CS_CMD_RUN_NAME;
  20. public override string Description => CS_CMD_RUN_DESCR;
  21. #endregion
  22. #region *** Private fields ***
  23. #endregion
  24. #region *** Constructors ***
  25. public RunCommand(Engine engine) : base(engine)
  26. {
  27. }
  28. #endregion
  29. #region *** EXECUTE ***
  30. protected override Result OnExecute()
  31. {
  32. using (var server = new Server(Configuration, FileSystem, LoggerFactory.Instance))
  33. {
  34. WriteInfo("Starting...");
  35. server.Start();
  36. WriteInfo("Started.");
  37. WriteCaption("Press Esc to exit.");
  38. var exit = false;
  39. while (!exit)
  40. {
  41. var keyInfo = Console.ReadKey();
  42. exit = keyInfo.Key == ConsoleKey.Escape;
  43. }
  44. server.Stop();
  45. }
  46. return new Result();
  47. }
  48. #endregion
  49. #region *** Private operations ***
  50. #endregion
  51. }
  52. }