Commit bc12f89aad3370e6361a5c524b2d44bedfa5810c
1 parent
eeb190f8
v1.28.0.0
Showing
3 changed files
with
79 additions
and
2 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
| ... | ... | @@ -276,6 +276,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS |
| 276 | 276 | public static class GetRemoteInfo { public const string KEY = "RIN"; } |
| 277 | 277 | public static class Send { public const string KEY = "SND"; } |
| 278 | 278 | public static class Peek { public const string KEY = "PEK"; } |
| 279 | + public static class Enumerate { public const string KEY = "ENU"; } | |
| 279 | 280 | public static class Read{ public const string KEY = "RED"; } |
| 280 | 281 | public static class Purge { public const string KEY = "PRG"; } |
| 281 | 282 | } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs
| ... | ... | @@ -41,6 +41,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 41 | 41 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.SetDefaultPermissions.KEY, "Set default MSMQ permisssions", SetDefaultPermissions, ep)) |
| 42 | 42 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.GetLocalInfo.KEY, "Get local MSMQ information", GetLocalInfo, ep)) |
| 43 | 43 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.GetRemoteInfo.KEY, "Get remote MSMQ information", GetRemoteInfo, ep)) |
| 44 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Enumerate.KEY, "Enumerate MSMQ message", Enumerate, ep)) | |
| 44 | 45 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Peek.KEY, "Peek MSMQ message", Peek, ep)) |
| 45 | 46 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Read.KEY, "Read MSMQ message", Read, ep)) |
| 46 | 47 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Send.KEY, "Send MSMQ message", Send, ep)) |
| ... | ... | @@ -291,6 +292,81 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 291 | 292 | return o; |
| 292 | 293 | } |
| 293 | 294 | |
| 295 | + private static object Enumerate(object parameter, object o) | |
| 296 | + { | |
| 297 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
| 298 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
| 299 | + | |
| 300 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
| 301 | + | |
| 302 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Enumerate)}'!", silent: true) | |
| 303 | + .SetSelectionMode(Menu.SelectionMode.Single); | |
| 304 | + | |
| 305 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
| 306 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
| 307 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
| 308 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
| 309 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
| 310 | + else { } | |
| 311 | + foreach (var p in sr.SelectedParameterList) | |
| 312 | + { | |
| 313 | + MSMQ st = p.Parameters as MSMQ; | |
| 314 | + try | |
| 315 | + { | |
| 316 | + var messageformatter = MSMQManagerCore.SetFormatter(st.Xml_Formatter); //new ActiveXMessageFormatter(); | |
| 317 | + var encoding = MSMQManagerCore.SetEncoding(st.Xml_Encoding); // Encoding.UTF8; | |
| 318 | + var fullpath = st.Xml_FullPath; | |
| 319 | + | |
| 320 | + using (var msmq = new MessageQueue(fullpath)) | |
| 321 | + { | |
| 322 | + msmq.Formatter = messageformatter; | |
| 323 | + startenumeration: | |
| 324 | + var enumerator = msmq.GetMessageEnumerator2(); | |
| 325 | + int messageindex = 0; | |
| 326 | + while (true) | |
| 327 | + { | |
| 328 | + try | |
| 329 | + { | |
| 330 | + var isnextmeessageavailable = enumerator.MoveNext(new TimeSpan(0, 0, 5)); | |
| 331 | + if (!isnextmeessageavailable) { ColorConsole.WriteLine("No (more) message available....", ConsoleColor.White); break; } | |
| 332 | + | |
| 333 | + Message m = enumerator.Current; | |
| 334 | + ColorConsole.WriteLine("Processing message....", ConsoleColor.White); | |
| 335 | + | |
| 336 | + string msgBody = null; | |
| 337 | + if (m.Formatter is XmlMessageFormatter) | |
| 338 | + { | |
| 339 | + ((XmlMessageFormatter)m.Formatter).TargetTypes = new Type[] { typeof(string), }; | |
| 340 | + msgBody = (string)m.Body; | |
| 341 | + } | |
| 342 | + else | |
| 343 | + { | |
| 344 | + if (encoding == null) { msgBody = (string)m.Body; } | |
| 345 | + else { msgBody = (new StreamReader(m.BodyStream, encoding)).ReadToEnd(); } | |
| 346 | + } | |
| 347 | + var msglabel = m.Label; | |
| 348 | + ColorConsole.WriteLine($"Current message in MSMQ:{st.Xml_Name}", ConsoleColor.Green); | |
| 349 | + ColorConsole.WriteLine($" Body: {msgBody}", ConsoleColor.Yellow); | |
| 350 | + ColorConsole.WriteLine($" Label: {msglabel}", ConsoleColor.Yellow); | |
| 351 | + | |
| 352 | + 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"); | |
| 353 | + if (nextoption.ToLower() == "ex") { return o; } | |
| 354 | + else if (nextoption.ToLower() == "reset") { enumerator.Reset(); } | |
| 355 | + else if (nextoption.ToLower() == "rc") { enumerator.RemoveCurrent(); } | |
| 356 | + else if (nextoption.ToLower() == "rcr") { enumerator.RemoveCurrent(); enumerator.Reset(); } | |
| 357 | + } | |
| 358 | + catch (Exception ex) { ColorConsole.WriteLine("B:"+ex.MessageNested(), ConsoleColor.Red); } | |
| 359 | + } | |
| 360 | + var repeatoption = ColorConsole.ReadLine("[Enter]=Repeat enumeration, EX=Exit"); | |
| 361 | + if (repeatoption.ToLower() == "ex") { return o; } | |
| 362 | + else { goto startenumeration; } | |
| 363 | + } | |
| 364 | + } | |
| 365 | + catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); } | |
| 366 | + } | |
| 367 | + return o; | |
| 368 | + } | |
| 369 | + | |
| 294 | 370 | private static object Peek(object parameter, object o) |
| 295 | 371 | { |
| 296 | 372 | var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
| ... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
| 32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
| 33 | 33 | // by using the '*' as shown below: |
| 34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
| 35 | -[assembly: AssemblyVersion("1.27.2.0")] | |
| 36 | -[assembly: AssemblyFileVersion("1.27.2.0")] | |
| 35 | +[assembly: AssemblyVersion("1.28.0.0")] | |
| 36 | +[assembly: AssemblyFileVersion("1.28.0.0")] | ... | ... |