From d97ce6a4d1e08a3039a93b8e64acea9a63d12093 Mon Sep 17 00:00:00 2001 From: Adam Ralph Date: Mon, 3 Sep 2018 17:50:53 +0200 Subject: [PATCH] minimize 04-integration/after/Divergent.Customers.API --- .../after/Divergent.Customers.API/ConsoleEx.cs | 15 +++++++++++++++ .../Divergent.Customers.API.csproj | 2 +- .../after/Divergent.Customers.API/Program.cs | 1 + .../WindowsNativeMethods.cs | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 exercises/04-integration/after/Divergent.Customers.API/ConsoleEx.cs create mode 100644 exercises/04-integration/after/Divergent.Customers.API/WindowsNativeMethods.cs diff --git a/exercises/04-integration/after/Divergent.Customers.API/ConsoleEx.cs b/exercises/04-integration/after/Divergent.Customers.API/ConsoleEx.cs new file mode 100644 index 000000000..ea9bedcf1 --- /dev/null +++ b/exercises/04-integration/after/Divergent.Customers.API/ConsoleEx.cs @@ -0,0 +1,15 @@ +using System.Runtime.InteropServices; + +namespace Divergent.Customers.API +{ + static class ConsoleEx + { + public static void TryMinimize() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + WindowsNativeMethods.ShowWindow(WindowsNativeMethods.GetConsoleWindow(), WindowsNativeMethods.SW_SHOWMINIMIZED); + } + } + } +} diff --git a/exercises/04-integration/after/Divergent.Customers.API/Divergent.Customers.API.csproj b/exercises/04-integration/after/Divergent.Customers.API/Divergent.Customers.API.csproj index a9d402252..f14ded808 100644 --- a/exercises/04-integration/after/Divergent.Customers.API/Divergent.Customers.API.csproj +++ b/exercises/04-integration/after/Divergent.Customers.API/Divergent.Customers.API.csproj @@ -3,7 +3,7 @@ latest Exe - net461 + net471 diff --git a/exercises/04-integration/after/Divergent.Customers.API/Program.cs b/exercises/04-integration/after/Divergent.Customers.API/Program.cs index 1c140f202..d0b94bb7a 100644 --- a/exercises/04-integration/after/Divergent.Customers.API/Program.cs +++ b/exercises/04-integration/after/Divergent.Customers.API/Program.cs @@ -10,6 +10,7 @@ class Program public static async Task Main(string[] args) { Console.Title = MethodBase.GetCurrentMethod().DeclaringType.Namespace; + ConsoleEx.TryMinimize(); var tcs = new TaskCompletionSource(); Console.CancelKeyPress += (sender, e) => { tcs.SetResult(null); }; diff --git a/exercises/04-integration/after/Divergent.Customers.API/WindowsNativeMethods.cs b/exercises/04-integration/after/Divergent.Customers.API/WindowsNativeMethods.cs new file mode 100644 index 000000000..0778acf53 --- /dev/null +++ b/exercises/04-integration/after/Divergent.Customers.API/WindowsNativeMethods.cs @@ -0,0 +1,16 @@ +using System; +using System.Runtime.InteropServices; + +namespace Divergent.Customers.API +{ + static class WindowsNativeMethods + { + public const int SW_SHOWMINIMIZED = 2; + + [DllImport("kernel32.dll")] + public static extern IntPtr GetConsoleWindow(); + + [DllImport("user32.dll")] + public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); + } +}