Pārlūkot izejas kodu

QConsole:

26.12.2019 v.1.0.0.2
      New
      - Add contexts support to engine (infrastructure)
      - Add contexts support to command
      - Extends configuration ShowStatusOnEveryCommand
Dalibor Votruba 6 gadi atpakaļ
vecāks
revīzija
12fa04b920

+ 3 - 1
QConsole/QConsole.DevBench/Program.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
 using Quadarax.Foundation.QConsole.Configuration;
+using Quadarax.Foundation.QConsole.Context;
 
 namespace Quadarax.Foundation.QConsole.DevBench
 {
@@ -18,8 +19,9 @@ namespace Quadarax.Foundation.QConsole.DevBench
             config.WaitOnKeyInNonInteractiveMode = true;
             config.CommandDefinitionAssebmly = new Assembly[]{Assembly.GetEntryAssembly()};
             config.DisableDefaultCommands();
+            config.ShowStatusOnEveryCommand = false;
 
-             var console = new Engine(config, args);
+             var console = new Engine(config, new DefualtEngineContext(), args);
             console.Start();
 
             Console.WriteLine("Press any key to exit (external wait)...");

+ 28 - 0
QConsole/QConsole/Command/Base/AbstractCommand.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using Quadarax.Foundation.Common.Console;
 using Quadarax.Foundation.Common.Value;
 using Quadarax.Foundation.QConsole.Argument;
+using Quadarax.Foundation.QConsole.Context;
 using Quadarax.Foundation.QConsole.Extensions;
 
 namespace Quadarax.Foundation.QConsole.Command.Base
@@ -13,6 +14,7 @@ namespace Quadarax.Foundation.QConsole.Command.Base
         #region *** Private Fields ***
         private Engine _engine;
         private IDictionary<string, AbstractArgument> _arguments;
+        protected ICommandContext _context;
         #endregion
 
         #region *** Properties ***
@@ -29,6 +31,8 @@ namespace Quadarax.Foundation.QConsole.Command.Base
         {
             _engine = engine ?? throw new ArgumentNullException(nameof(engine));
             _arguments = new Dictionary<string, AbstractArgument>();
+            _context = _engine.Context.CreateCommandContext();
+            WriteDebugInfo($"Context for command '{Name}' created: {_context}");
             var args = SetupArguments();
             foreach (var arg in args)
                 _arguments.Add(arg.Code, arg);
@@ -50,6 +54,9 @@ namespace Quadarax.Foundation.QConsole.Command.Base
                     arg.SetValueAsDefault();
                 ParseInput(input);
 
+                if (_engine.Configuration.ShowStatusOnEveryCommand)
+                    ShowContextStatus(writer);
+
                 var result = OnExecute();
                 result = EndExecute(result);
                 
@@ -194,6 +201,23 @@ namespace Quadarax.Foundation.QConsole.Command.Base
                 debug.WriteDebugLine(text);
             }
         }
+
+        private void ShowContextStatus(ConsoleWriter writer)
+        {
+            using (var writerBlue = new ConsoleWriter(ConsoleColor.Blue))
+            {
+                using (var writerYellow = new ConsoleWriter(ConsoleColor.Magenta))
+                {
+                    writer.WriteLine("Engine context:");
+                    writerBlue.Write(_engine.Context.ToString()).Write(" : ");
+                    writerYellow.WriteLine(_engine.Context.Status);
+                    writer.WriteLine("Command context:");
+                    writerBlue.Write(_context.ToString()).Write(" : ");
+                    writerYellow.WriteLine(_context.Status);
+                }
+            }
+        }
+
         #endregion
 
         #region *** Protected virtuals ***
@@ -235,6 +259,10 @@ namespace Quadarax.Foundation.QConsole.Command.Base
             return _arguments.ContainsKey(code);
         }
 
+        protected TContext GetContext<TContext>() where TContext : class, ICommandContext
+        {
+            return (TContext)_context;
+        }
         #endregion
 
     }

+ 6 - 0
QConsole/QConsole/Configuration/StartupConfiguration.cs

@@ -89,6 +89,11 @@ namespace Quadarax.Foundation.QConsole.Configuration
         /// </summary>
         public bool WaitOnKeyInNonInteractiveMode { get; set; }
 
+        /// <summary>
+        /// Defines if show status of engine and command context before every command executed.
+        /// </summary>
+        public bool ShowStatusOnEveryCommand { get; set; }
+
         public bool IsConsoleDebug {
             get
             {
@@ -192,6 +197,7 @@ namespace Quadarax.Foundation.QConsole.Configuration
             AllowPreset = Defaults.Console.PresetAllowed;
             IsConsoleDebug = Defaults.Console.ConsoleDebugMode;
             WaitOnKeyInNonInteractiveMode = Defaults.Console.WaitOnKeyInNonInteractiveMode;
+            ShowStatusOnEveryCommand = Defaults.Console.ShowStatusOnEveryCommand;
 
         }
         #endregion

+ 18 - 0
QConsole/QConsole/Context/DefaultCommandContext.cs

@@ -0,0 +1,18 @@
+using Quadarax.Foundation.Common.Object;
+
+namespace Quadarax.Foundation.QConsole.Context
+{
+    public class DefaultCommandContext : DisposableObject, ICommandContext
+    {
+        protected override void OnDisposing()
+        {
+        }
+
+        public string Status => "READY";
+
+        public override string ToString()
+        {
+            return "Default empty command context";
+        }
+    }
+}

+ 23 - 0
QConsole/QConsole/Context/DefualtEngineContext.cs

@@ -0,0 +1,23 @@
+using Quadarax.Foundation.Common.Object;
+
+namespace Quadarax.Foundation.QConsole.Context
+{
+    public class DefualtEngineContext : DisposableObject, IEngineContext
+    {
+        protected override void OnDisposing()
+        {
+        }
+
+        public ICommandContext CreateCommandContext()
+        {
+            return new DefaultCommandContext();
+        }
+
+        public string Status => "READY";
+
+        public override string ToString()
+        {
+            return "Default empty engine context";
+        }
+    }
+}

+ 6 - 0
QConsole/QConsole/Context/ICommandContext.cs

@@ -0,0 +1,6 @@
+namespace Quadarax.Foundation.QConsole.Context
+{
+    public interface ICommandContext : IQConsoleContext
+    {
+    }
+}

+ 7 - 0
QConsole/QConsole/Context/IEngineContext.cs

@@ -0,0 +1,7 @@
+namespace Quadarax.Foundation.QConsole.Context
+{
+    public interface IEngineContext : IQConsoleContext
+    {
+        ICommandContext CreateCommandContext();
+    }
+}

+ 9 - 0
QConsole/QConsole/Context/IQConsoleContext.cs

@@ -0,0 +1,9 @@
+using System;
+
+namespace Quadarax.Foundation.QConsole.Context
+{
+    public interface IQConsoleContext : IDisposable
+    {
+        string Status { get; }
+    }
+}

+ 1 - 0
QConsole/QConsole/Defaults.cs

@@ -16,6 +16,7 @@ namespace Quadarax.Foundation.QConsole
             internal const ConsoleColor ConsoleDebugForeColor = ConsoleColor.DarkGray;
             internal const bool DisableDefaultCommands = false;
             internal const bool WaitOnKeyInNonInteractiveMode = false;
+            internal const bool ShowStatusOnEveryCommand = false;
         }
 
         internal class Formats

+ 6 - 1
QConsole/QConsole/Engine.cs

@@ -7,6 +7,7 @@ using Quadarax.Foundation.QConsole.Attributes;
 using Quadarax.Foundation.QConsole.Command.Base;
 using Quadarax.Foundation.QConsole.Command.Defaults;
 using Quadarax.Foundation.QConsole.Configuration;
+using Quadarax.Foundation.QConsole.Context;
 
 namespace Quadarax.Foundation.QConsole
 {
@@ -25,12 +26,15 @@ namespace Quadarax.Foundation.QConsole
         public StartupConfiguration Configuration => _configuration;
         public AbstractCommand[] Commands => _commands.ToArray();
         public ISelectionEntry[] Selections => _selections.ToArray();
+
+        public IEngineContext Context { get; }
         #endregion
 
         #region *** Constructor ***
-        public Engine(StartupConfiguration configuration, string[] args)
+        public Engine(StartupConfiguration configuration, IEngineContext context, string[] args)
         {
             _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
+            Context = context ?? throw new ArgumentNullException(nameof(context));
 
             if (args == null)
                 args = new string[0];
@@ -53,6 +57,7 @@ namespace Quadarax.Foundation.QConsole
 
             RawArguments = args;
             WriteDebugInfo($"Input {args.Length} arguments appended.");
+            WriteDebugInfo($"Context set: {Context}");
 
             var commandClasses = GetTypesWithHelpAttribute(new CommandDefinitionAttribute());
             WriteDebugInfo($"Console found {commandClasses.Count()} command definitions.");

+ 9 - 4
QConsole/QConsole/Properties/AssemblyInfo.cs

@@ -6,10 +6,15 @@ using System.Runtime.InteropServices;
 // associated with an assembly.
 [assembly: AssemblyTitle("QDR.FND.QConsole")]
 [assembly: AssemblyDescription("QConsole - simple console framework (part of Quadarax.Foundation)")]
-[assembly: AssemblyConfiguration("")]
+#if DEBUG
+[assembly: AssemblyConfiguration("DEBUG")]
+#else
+[assembly: AssemblyConfiguration("RELEASE")]
+#endif
+
 [assembly: AssemblyCompany("Quadarax")]
 [assembly: AssemblyProduct("Quadarax.Foundation")]
-[assembly: AssemblyCopyright("Copyright © Quadarax 2019")]
+[assembly: AssemblyCopyright("Copyright © Quadarax 2020")]
 [assembly: AssemblyTrademark("")]
 [assembly: AssemblyCulture("")]
 
@@ -31,5 +36,5 @@ using System.Runtime.InteropServices;
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.2")]
-[assembly: AssemblyFileVersion("1.0.0.2")]
+[assembly: AssemblyVersion("1.0.1.0")]
+[assembly: AssemblyFileVersion("1.0.1.0")]

+ 5 - 0
QConsole/QConsole/QDR.FND.QConsole.csproj

@@ -76,6 +76,11 @@
     <Compile Include="Command\Defaults\CmdSelection.cs" />
     <Compile Include="Configuration\StartupConfiguration.cs" />
     <Compile Include="Constants.cs" />
+    <Compile Include="Context\DefaultCommandContext.cs" />
+    <Compile Include="Context\DefualtEngineContext.cs" />
+    <Compile Include="Context\ICommandContext.cs" />
+    <Compile Include="Context\IEngineContext.cs" />
+    <Compile Include="Context\IQConsoleContext.cs" />
     <Compile Include="DebugConsoleWriter.cs" />
     <Compile Include="Defaults.cs" />
     <Compile Include="Engine.cs" />

+ 5 - 6
QConsole/QConsole/QDR.FND.QConsole.nuspec

@@ -2,7 +2,7 @@
 <package>
   <metadata>
     <id>Quadarax.Foundation.QConsole</id>
-    <version>1.0.0.2</version>
+    <version>1.0.1.0</version>
     <title>Quadarax.Foundation.QConsole</title>
     <authors>Dalibor Votruba, Quadarax</authors>
     <owners>Dalibor Votruba</owners>
@@ -11,12 +11,11 @@
     <requireLicenseAcceptance>false</requireLicenseAcceptance>
     <description>Implementation base for console applications with commands, lists, selections and easy command handlings.</description>
     <releaseNotes>
-      23.12.2019 v.1.0.0.2
+      26.12.2019 v.1.0.0.2
       New
-      - Allows to use more asseblies in CommandDefinitionAssebmly
-      - Add DisableDefaultCommands to StartupConfiguration to hide default commands
-      - Add WaitOnKeyInNonInteractiveMode to wait on key at the end of the non-interactive process
-      - Use reference Quadarax.Foundation.Common
+      - Add contexts support to engine (infrastructure)
+      - Add contexts support to command
+      - Extends configuration ShowStatusOnEveryCommand
     </releaseNotes>
     <copyright>Copyright (c) 2019,2020 Quadarax</copyright>
     <tags>quadarax, foundation, qconsole, qdr, fnd, library, console</tags>

+ 7 - 1
QConsole/QConsole/ReleaseNote.txt

@@ -1,4 +1,10 @@
-23.12.2019 v.1.0.0.2
+26.12.2019 v.1.0.0.2
+New
+ - Add contexts support to engine (infrastructure)
+ - Add contexts support to command
+ - Extends configuration ShowStatusOnEveryCommand
+
+23.12.2019 v.1.0.0.2
 New
  - Allows to use more asseblies in CommandDefinitionAssebmly
  - Add DisableDefaultCommands to StartupConfiguration to hide default commands