From bc12f89aad3370e6361a5c524b2d44bedfa5810c Mon Sep 17 00:00:00 2001 From: Schwirg László Date: Wed, 28 Aug 2024 12:44:41 +0200 Subject: [PATCH] v1.28.0.0 --- Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs | 1 + Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs index 8ee2c7a..e70d7d7 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs @@ -276,6 +276,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS public static class GetRemoteInfo { public const string KEY = "RIN"; } public static class Send { public const string KEY = "SND"; } public static class Peek { public const string KEY = "PEK"; } + public static class Enumerate { public const string KEY = "ENU"; } public static class Read{ public const string KEY = "RED"; } public static class Purge { public const string KEY = "PRG"; } } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs index 75f5bcb..d06bd17 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs @@ -41,6 +41,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.SetDefaultPermissions.KEY, "Set default MSMQ permisssions", SetDefaultPermissions, ep)) .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.GetLocalInfo.KEY, "Get local MSMQ information", GetLocalInfo, ep)) .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.GetRemoteInfo.KEY, "Get remote MSMQ information", GetRemoteInfo, ep)) + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Enumerate.KEY, "Enumerate MSMQ message", Enumerate, ep)) .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Peek.KEY, "Peek MSMQ message", Peek, ep)) .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Read.KEY, "Read MSMQ message", Read, ep)) .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Send.KEY, "Send MSMQ message", Send, ep)) @@ -291,6 +292,81 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS return o; } + private static object Enumerate(object parameter, object o) + { + var config = (parameter as Menu.ExecutorParameter).GetConfig(); + var args = (parameter as Menu.ExecutorParameter).Args; + + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); + + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Enumerate)}'!", silent: true) + .SetSelectionMode(Menu.SelectionMode.Single); + + Menu.Selection sr = menufolders.Select(selectedtaskindexes); + if (sr.Result == Menu.SelectionResult.Exit) { return o; } + else if (sr.Result == Menu.SelectionResult.None) { return o; } + else if (sr.Result == Menu.SelectionResult.Error) { return o; } + else if (sr.Result == Menu.SelectionResult.Ok) { } + else { } + foreach (var p in sr.SelectedParameterList) + { + MSMQ st = p.Parameters as MSMQ; + try + { + var messageformatter = MSMQManagerCore.SetFormatter(st.Xml_Formatter); //new ActiveXMessageFormatter(); + var encoding = MSMQManagerCore.SetEncoding(st.Xml_Encoding); // Encoding.UTF8; + var fullpath = st.Xml_FullPath; + + using (var msmq = new MessageQueue(fullpath)) + { + msmq.Formatter = messageformatter; + startenumeration: + var enumerator = msmq.GetMessageEnumerator2(); + int messageindex = 0; + while (true) + { + try + { + var isnextmeessageavailable = enumerator.MoveNext(new TimeSpan(0, 0, 5)); + if (!isnextmeessageavailable) { ColorConsole.WriteLine("No (more) message available....", ConsoleColor.White); break; } + + Message m = enumerator.Current; + ColorConsole.WriteLine("Processing message....", ConsoleColor.White); + + string msgBody = null; + if (m.Formatter is XmlMessageFormatter) + { + ((XmlMessageFormatter)m.Formatter).TargetTypes = new Type[] { typeof(string), }; + msgBody = (string)m.Body; + } + else + { + if (encoding == null) { msgBody = (string)m.Body; } + else { msgBody = (new StreamReader(m.BodyStream, encoding)).ReadToEnd(); } + } + var msglabel = m.Label; + ColorConsole.WriteLine($"Current message in MSMQ:{st.Xml_Name}", ConsoleColor.Green); + ColorConsole.WriteLine($" Body: {msgBody}", ConsoleColor.Yellow); + ColorConsole.WriteLine($" Label: {msglabel}", ConsoleColor.Yellow); + + var nextoption = ColorConsole.ReadLine("[Enter]=Move next, RC=Remove current and move next, RCR=Remove current, reset and move next, RESET=reset and move next or EX=Exit"); + if (nextoption.ToLower() == "ex") { return o; } + else if (nextoption.ToLower() == "reset") { enumerator.Reset(); } + else if (nextoption.ToLower() == "rc") { enumerator.RemoveCurrent(); } + else if (nextoption.ToLower() == "rcr") { enumerator.RemoveCurrent(); enumerator.Reset(); } + } + catch (Exception ex) { ColorConsole.WriteLine("B:"+ex.MessageNested(), ConsoleColor.Red); } + } + var repeatoption = ColorConsole.ReadLine("[Enter]=Repeat enumeration, EX=Exit"); + if (repeatoption.ToLower() == "ex") { return o; } + else { goto startenumeration; } + } + } + catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); } + } + return o; + } + private static object Peek(object parameter, object o) { var config = (parameter as Menu.ExecutorParameter).GetConfig(); diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index f22f04c..3935242 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs @@ -32,5 +32,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.27.2.0")] -[assembly: AssemblyFileVersion("1.27.2.0")] +[assembly: AssemblyVersion("1.28.0.0")] +[assembly: AssemblyFileVersion("1.28.0.0")] -- libgit2 0.21.2