StartupConfiguration.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Reflection;
  3. using System.Xml.XPath;
  4. namespace Quadarax.Foundation.QConsole.Configuration
  5. {
  6. public class StartupConfiguration
  7. {
  8. #region *** Private Fields ***
  9. private bool _isConsoleDebug;
  10. #endregion
  11. #region *** Properties ***
  12. /// <summary>
  13. /// Name of console application, If not defined uses default name from entryAssembly.
  14. /// </summary>
  15. public string ConsoleName { get; }
  16. /// <summary>
  17. /// Console application version. If not defined uses version of entryAssembly.
  18. /// </summary>
  19. public Version ConsoleVersion { get; }
  20. /// <summary>
  21. /// Defines if console is initialized from XML definition.
  22. /// </summary>
  23. public bool IsInitFromXml { get; }
  24. /// <summary>
  25. /// Left introducing of interactive mode character.
  26. /// </summary>
  27. public string CharacterLineIntroduce { get; set; }
  28. /// <summary>
  29. /// Separator between two ordinal arguments
  30. /// </summary>
  31. public string CharacterOrdinalArgumentSeparator { get; set; }
  32. /// <summary>
  33. /// Named argument prefix character.
  34. /// </summary>
  35. public string CharacterNamedArgumentSeparator { get; set; }
  36. /// <summary>
  37. /// Named argument postfix character {defines end of argument code and value)
  38. /// </summary>
  39. public string CharacterNamedArgumentValueSeparator { get; set; }
  40. /// <summary>
  41. /// Start end end string value character
  42. /// </summary>
  43. public string CharacterTextValueBraceSeparator { get; set; }
  44. /// <summary>
  45. /// Separator between two selection inputs
  46. /// </summary>
  47. public string CharacterSelectionInputValueSeparator { get; set; }
  48. /// <summary>
  49. /// Date input/output value format
  50. /// </summary>
  51. public string DateFormat { get; set; }
  52. /// <summary>
  53. /// Time input/output value format
  54. /// </summary>
  55. public string TimeFormat { get; set; }
  56. /// <summary>
  57. /// Defines if interactive mode is enabled
  58. /// </summary>
  59. public bool AllowInteractive { get; set; }
  60. /// <summary>
  61. /// Defines if initial variables is allowed for interactive mode.
  62. /// </summary>
  63. public bool AllowPreset { get; set; }
  64. /// <summary>
  65. /// Defines assembly list where custom commands are defined (in case explicit command definition).
  66. /// </summary>
  67. public Assembly[] CommandDefinitionAssebmly { get; set; }
  68. /// <summary>
  69. /// Defines if default (build-in) commands CLEAR,EXIT,PRINT,SELECTION will be disabled (hidden).
  70. /// </summary>
  71. public bool DisableDefaultCommands { get; set; }
  72. /// <summary>
  73. /// Defines if waits on key at the end of process in non-interactive mode (inline mode)
  74. /// </summary>
  75. public bool WaitOnKeyInNonInteractiveMode { get; set; }
  76. public bool IsConsoleDebug {
  77. get
  78. {
  79. return _isConsoleDebug;
  80. }
  81. set
  82. {
  83. _isConsoleDebug = value;
  84. DebugConsoleWriter.IsWriteDebugEnabled = value;
  85. }
  86. }
  87. #endregion
  88. #region *** Constructor ***
  89. public StartupConfiguration(string consoleName, Version consoleVersion)
  90. {
  91. ConsoleName = consoleName;
  92. ConsoleVersion = consoleVersion;
  93. IsInitFromXml = false;
  94. InitDefaults();
  95. }
  96. public StartupConfiguration(string consoleXmlFileName)
  97. {
  98. IsInitFromXml = true;
  99. InitDefaults();
  100. }
  101. public StartupConfiguration(XPathNavigator configurationNavigator)
  102. {
  103. IsInitFromXml = true;
  104. InitDefaults();
  105. }
  106. #endregion
  107. #region *** Public Operations ***
  108. public StartupConfiguration EnableDebugMode()
  109. {
  110. IsConsoleDebug = true;
  111. return this;
  112. }
  113. public StartupConfiguration DisableDebugMode()
  114. {
  115. IsConsoleDebug = false;
  116. return this;
  117. }
  118. #endregion
  119. #region *** Private Operations ***
  120. private void InitDefaults()
  121. {
  122. CharacterLineIntroduce = Defaults.RoleCharacters.ConsoleLineIntroduce;
  123. CharacterOrdinalArgumentSeparator = Defaults.RoleCharacters.OrdinalArgumentSeparator;
  124. CharacterNamedArgumentSeparator = Defaults.RoleCharacters.NamedArgumentSeparator;
  125. CharacterNamedArgumentValueSeparator = Defaults.RoleCharacters.NamedArgumentValueSeparator;
  126. CharacterTextValueBraceSeparator = Defaults.RoleCharacters.TextValueBraceSeparator;
  127. CharacterSelectionInputValueSeparator = Defaults.RoleCharacters.InputSelectionValueSeparator;
  128. DateFormat = Defaults.Formats.DateFormat;
  129. TimeFormat = Defaults.Formats.TimeFormat;
  130. AllowInteractive = Defaults.Console.InteractiveAllowed;
  131. AllowPreset = Defaults.Console.PresetAllowed;
  132. IsConsoleDebug = Defaults.Console.ConsoleDebugMode;
  133. DisableDefaultCommands = Defaults.Console.DisableDefaultCommands;
  134. WaitOnKeyInNonInteractiveMode = Defaults.Console.WaitOnKeyInNonInteractiveMode;
  135. }
  136. #endregion
  137. }
  138. }