diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs index 1813de7..60bbc7a 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs @@ -187,6 +187,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS public const string CMD_FUNCTION = "-FUNCTION"; public const string CMD_SILENT = "-SILENT"; public const string CMD_APPCONFIG = "-APPCONFIG"; + public const string CMD_STARTASSYSTEM = "-SYSTEM"; public static class Module { public static class Log4ProUserManager @@ -267,7 +268,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS public static class Remove { public const string KEY = "UIN"; } public static class SetPermissions { public const string KEY = "PRM"; } public static class SetDefaultPermissions { public const string KEY = "DPR"; } - public static class GetInfo { public const string KEY = "INF"; } + public static class GetLocalInfo { public const string KEY = "INF"; } + 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 Read{ public const string KEY = "RED"; } diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs index 5270d55..b8fc1d8 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs @@ -19,6 +19,7 @@ using Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS; using VRH.Common; using Microsoft.Win32; using System.Reflection; +using Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS; namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS { @@ -56,15 +57,17 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS { if (!silent) { - var ans = ColorConsole.ReadLine("NT AUTHORITY/SYSTEM", prefix: "Start as ",f:ConsoleColor.Yellow, suffix: "?", bracket: "[]",validitylist:new List { "yes","no"},exitvalue:"EX",defaultvalue:"NO"); + var ans = ColorConsole.ReadLine("NT AUTHORITY\\SYSTEM", prefix: "Start as ",f:ConsoleColor.Yellow, suffix: "?", bracket: "[]",validitylist:new List { "yes","no"},exitvalue:"EX",defaultvalue:"no"); if (ans.ToLower() != "yes") { return; } } + string runasusername = System.Security.Principal.WindowsIdentity.GetCurrent().Name; + if (runasusername=="NT AUTHORITY\\SYSTEM") { return; } + Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = @"C:\Log4ProIS\MAINTENANCECONSOLE\PsTools\psexec.exe"; - p.StartInfo.Arguments = @"-sid C:\Log4ProIS\MAINTENANCECONSOLE\Vrh.Log4Pro.MaintenanceConsole.exe"; - // The UseShellExecute flag must be turned off in order to supply a password: p.StartInfo.UseShellExecute = false; + p.StartInfo.Arguments = @"-sid C:\Log4ProIS\MAINTENANCECONSOLE\Vrh.Log4Pro.MaintenanceConsole.exe " + CLP.CMD_STARTASSYSTEM + " YES"; p.Start(); System.Environment.Exit(1); } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager - MSMQ.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager - MSMQ.cs new file mode 100644 index 0000000..fc46d82 --- /dev/null +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager - MSMQ.cs @@ -0,0 +1,426 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Messaging; +using System.Text; +using System.Threading.Tasks; + +using Vrh.Log4Pro.MaintenanceConsole.MenuNS; +using Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS; +using Vrh.Log4Pro.MaintenanceConsole.ToolsNS; +using Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS; + +using Vrh.XmlProcessing; +using VRH.Common; +using System.Xml.Linq; +using System.Text.RegularExpressions; + + +namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS +{ + public class MSMQ : XmlLinqBase + { + #region fields + public bool Valid = true; + public string Xml_Key; + public string Xml_Name; + public string Xml_AddressPrefix = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT; + public string Xml_Server = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT; + public bool Private; + public string Xml_Mode = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT; + public string Xml_Label; + public string Xml_Formatter = XmlStructure.MSMQManager.General.DefaultFormatter.Values.DEFAULT; + public string Xml_Encoding = XmlStructure.MSMQManager.General.DefaultEncoding.Values.DEFAULT; + public List Xml_AccessRights = new List(); + + public string Status; + public string StatusDescription=null; + public Guid Id; + public string QueueName; + public long NumOfMessages; + public string Label; + public string MachineName; + public IMessageFormatter Formatter; + public string FormatName; + public string Path; + public DateTime LastModifyTime; + public QueueAccessMode AccessMode; + public bool CanRead; + public bool CanWrite; + public long MaximumQueueSize; + public bool UseJournalQueue; + public long MaximumJournalSize; + + public bool Transactional; + public bool Authenticate; + public int BasePriority; + public EncryptionRequired EncryptionRequired; + #endregion fields + + #region basic constructor + public MSMQ() { } + #endregion basic constructor + + #region constructor from MessageQueue + public MSMQ(MessageQueue msmq, string key) + { + Xml_Key = key; + Xml_Name = msmq.QueueName; + Xml_Label = msmq.QueueName; + Xml_Server = msmq.MachineName; + Private = msmq.QueueName.ToLower().StartsWith("private$"); + Xml_Formatter = msmq.Formatter.GetType().Name; + Xml_AddressPrefix = "FormatName:"+msmq.FormatName.Replace(msmq.MachineName+"\\"+msmq.QueueName,""); + } + #endregion constructor from MessageQueue + + #region xml constructor + public MSMQ(XElement msmqxml,MSMQDefaults msmqdefaults) + { + Valid = true; + string ATTRIBUTEMANDATORY = nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue) + " attribute is mandatory! Name: {0}"; + Xml_Key = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key.Values.DEFAULT); + Xml_Name = msmqxml.Attribute(XName.Get(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name)))?.Value; + if (string.IsNullOrWhiteSpace(Xml_Name)) { throw new ApplicationException(string.Format(ATTRIBUTEMANDATORY, nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name))); } + Xml_AddressPrefix = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT); + Xml_Server = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT); + if (Xml_Server == "." || Xml_Server.ToLower() == "localhost") { Xml_Server = System.Environment.MachineName; } + + Private = Xml_Name.StartsWith("private$"); ; + Xml_Mode = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT); + Xml_Label = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Label), msmqxml, Xml_Name); + Xml_Formatter = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter), msmqxml, msmqdefaults.Xml_DefaultFormatter); + Xml_Encoding = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Encoding), msmqxml, msmqdefaults.Xml_DefaultEncoding); + + foreach (var ar in msmqdefaults.Xml_AccessRights) { Xml_AccessRights.Add(ar); } + try + { + var arxmllist = GetAllXElements(msmqxml, nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.AccessRight)); + foreach (var arxml in arxmllist) { var newa = AccessRights.Factory(arxml); if (newa != null) { Xml_AccessRights.Add(newa); } } + } + catch{ } + + + } + #endregion xml constructor + + #region Xml cloner constructor + public MSMQ(MSMQ msmq) + { + Valid = msmq.Valid; + Xml_Key = msmq.Xml_Key; + Xml_Name = msmq.Xml_Name; + Xml_Server = msmq.Xml_Server; + Private = msmq.Private; + Xml_Mode = msmq.Xml_Mode; + Xml_Label = msmq.Xml_Label; + Xml_Formatter= msmq.Xml_Formatter; + Xml_Encoding = msmq.Xml_Encoding; + } + #endregion Xml cloner constructor + + #region CollectMSMQInfo + public MSMQ CollectMSMQInfo() + { + MSMQ msmqdef = this; + string msmqaddressprefix = msmqdef.Xml_AddressPrefix; + string msmqservername = msmqdef.Xml_Server; + string msmqFullname = MSMQManagerCore.CreateFullQueuePath(msmqaddressprefix, msmqservername, msmqdef.Xml_Name); + msmqdef.QueueName = msmqdef.Xml_Name; + msmqdef.MachineName = msmqservername; + msmqdef.Path = msmqFullname; + try + { + msmqdef.Status = MessageQueue.Exists(msmqFullname) ? "Installed" : "Uninstalled"; + if (msmqdef.Status == "Installed") + { + using (var msmq = new MessageQueue(msmqFullname)) + { + msmqdef.QueueName = msmq.QueueName; + msmqdef.MachineName = msmq.MachineName; + + msmqdef.Id = msmq.Id; + msmqdef.NumOfMessages = MSMQManagerCore.Count(msmq); + msmqdef.Label = msmq.Label; + msmqdef.Formatter = msmq.Formatter; + msmqdef.FormatName = msmq.FormatName; + msmqdef.Path = msmq.Path; + msmqdef.LastModifyTime = msmq.LastModifyTime; + msmqdef.AccessMode = msmq.AccessMode; + msmqdef.CanRead = msmq.CanRead; + msmqdef.CanWrite = msmq.CanWrite; + msmqdef.MaximumQueueSize = msmq.MaximumQueueSize; + msmqdef.UseJournalQueue = msmq.UseJournalQueue; + msmqdef.MaximumJournalSize = msmq.MaximumJournalSize; + + msmqdef.Transactional = msmq.Transactional; + msmqdef.Authenticate = msmq.Authenticate; + msmqdef.BasePriority = msmq.BasePriority; + msmqdef.EncryptionRequired = msmq.EncryptionRequired; + + msmqdef.Status = "Ready"; + } + } + } + catch (Exception ex) { msmqdef.Status = "Error"; msmqdef.StatusDescription = ex.Message + (ex.InnerException != null ? ("\n" + ex.InnerException.Message) : ""); } + return msmqdef; + } + #endregion CollectMSMQInfo + + public string DisplayVeryShortInfo(int lineix) + { + MSMQ msmq = this; + if (lineix == 0) + { + ColorConsole.Write($"{msmq.Xml_Name}", ConsoleColor.Black, ConsoleColor.White, prefix: "Queue '", suffix: $"' queue label: '{msmq.Xml_Label}'."); + ConsoleColor statuscolor; + if (msmq.Status == "Uninstalled") { statuscolor = ConsoleColor.Red; } + else if (msmq.Status == "Error") { statuscolor = ConsoleColor.Red; } + else if (msmq.Status == "Installed") { statuscolor = ConsoleColor.Yellow; } + else if (msmq.Status == "Ready") { statuscolor = ConsoleColor.Green; } + else { statuscolor = ConsoleColor.Red; } + ColorConsole.Write(msmq.Status, statuscolor, bracket: "[]", prefix: " ", suffix: ". "); + ColorConsole.WriteLine(); + return " "; + } + else if (lineix == 1) + { + var privatepublictext = msmq.Private ? "private" : "public"; + ColorConsole.Write($"{msmq.Xml_AddressPrefix}", ConsoleColor.Black, ConsoleColor.White, prefix: "Format:", suffix: $" Queue is { privatepublictext }."); + ColorConsole.Write($"{msmq.Xml_Server}", ConsoleColor.Black, ConsoleColor.White, prefix: "Server:", suffix: $" Queue is { privatepublictext }."); + ColorConsole.WriteLine(); + return " "; + } + return null; + } + public string DisplayShortInfo(int lineix) + { + MSMQ msmq = this; + if (lineix == 0) + { + ColorConsole.Write($"{msmq.Xml_Name}", ConsoleColor.Black, ConsoleColor.White, prefix: "Queue '", suffix: $"' queue label: '{msmq.Xml_Label}'."); + ConsoleColor statuscolor; + if (msmq.Status == "Uninstalled") { statuscolor = ConsoleColor.Red; } + else if (msmq.Status == "Error") { statuscolor = ConsoleColor.Red; } + else if (msmq.Status == "Installed") { statuscolor = ConsoleColor.Yellow; } + else if (msmq.Status == "Ready") { statuscolor = ConsoleColor.Green; } + else { statuscolor = ConsoleColor.Red; } + ColorConsole.Write(msmq.Status, statuscolor, bracket: "[]", prefix: " ", suffix: ". "); + ColorConsole.WriteLine(); + return " "; + } + else if (lineix == 1) + { + var privatepublictext = msmq.Private ? "private" : "public"; + ColorConsole.Write($"{msmq.Xml_AddressPrefix}", ConsoleColor.Black, ConsoleColor.White, prefix: "Format:", suffix: $" Queue is { privatepublictext }."); + ColorConsole.Write($"{msmq.Xml_Server}", ConsoleColor.Black, ConsoleColor.White, prefix: "Server:", suffix: $" Queue is { privatepublictext }."); + ColorConsole.WriteLine(); + return " "; + } + else if (lineix == 2) + { + ColorConsole.Write($"{msmq.Path}", ConsoleColor.Yellow, prefix: "Path ", suffix: ", "); + ColorConsole.WriteLine(); + return " "; + } + else if (lineix == 3) + { + if (msmq.StatusDescription != null) + { + ConsoleColor color = ConsoleColor.Yellow; + if (msmq.Status == "Ready") { color = ConsoleColor.Green; } + else if (msmq.Status == "Error") { color = ConsoleColor.Red; } + ColorConsole.Write($"{msmq.StatusDescription}", color, prefix: "Status description "); + ColorConsole.WriteLine(); + return " "; + } + return "";//empty=van még szöveg, de most nem történt kiírás + } + else if (lineix == 4) + { + if (msmq.Status == "Ready") + { + ColorConsole.Write($"{msmq.FormatName}", ConsoleColor.Yellow, prefix: "FormatName "); + ColorConsole.WriteLine(); + return " "; + } + return ""; + } + else if (lineix == 5) + { + if (msmq.Status == "Ready") + { + ColorConsole.Write($"{msmq.Id}", ConsoleColor.Yellow, prefix: "Id "); + ColorConsole.WriteLine(); + return " "; + } + return ""; + } + else if (lineix == 6) + { + if (msmq.Status == "Ready") + { + ColorConsole.Write(msmq.NumOfMessages.ToString(), ConsoleColor.Yellow, prefix: "Num.of msgs in queue ", suffix: ". "); + ColorConsole.Write($"{msmq.LastModifyTime}", ConsoleColor.Yellow, prefix: "LastModified ", suffix: ", "); + ColorConsole.WriteLine(); + return " "; + } + return ""; + } + else if (lineix == 7) + { + if (msmq.Status == "Ready") + { + ColorConsole.Write($"{msmq.AccessMode}", ConsoleColor.Yellow, prefix: "AccessMode ", suffix: ", "); + ColorConsole.Write($"{msmq.CanRead}", ConsoleColor.Yellow, prefix: "CanRead ", suffix: ", "); + ColorConsole.Write($"{msmq.CanWrite}", ConsoleColor.Yellow, prefix: "CanWrite ", suffix: ", "); + ColorConsole.WriteLine(); + return " "; + } + return ""; + } + return null; + } + + #region DisplayInfo + public void DisplayInfo() + { + MSMQ msmq = this; + ColorConsole.Write($">>> MSMQ detailed info collected for ", ConsoleColor.Yellow); + ColorConsole.Write($"{msmq.Xml_Name}", ConsoleColor.Yellow, suffix: ", ", prefix: " QueueName : "); + ColorConsole.Write($"{msmq.Xml_Server}", ConsoleColor.Yellow, prefix: "MachineName: "); + ColorConsole.WriteLine(); + var qqn = msmq.Xml_Name; + var qexists = MSMQManagerCore.CheckIfQueueExists(msmq.Xml_Server, qqn); + if (!qexists) + { + ColorConsole.WriteLine($" Queue does not exist!", ConsoleColor.Red); + } + else + { + try + { + msmq = msmq.CollectMSMQInfo(); + ColorConsole.WriteLine($"{msmq.QueueName}", ConsoleColor.Green, prefix: $" Queue name: "); + ColorConsole.WriteLine($"{msmq.MachineName}", ConsoleColor.Green, prefix: $" Server: "); + if (msmq.Status == "Error") + { + ColorConsole.WriteLine($"{msmq.Status}", ConsoleColor.Red, prefix: $" Status: "); + ColorConsole.WriteLine($"{msmq.StatusDescription}", ConsoleColor.Red, prefix: " StatusDescription: "); + } + else if (msmq.Status != "Ready") + { + ColorConsole.WriteLine($"{msmq.Status}", ConsoleColor.Yellow, prefix: $" Status: "); + ColorConsole.WriteLine($"{msmq.StatusDescription}", ConsoleColor.Yellow, prefix: " StatusDescription: "); + } + else + { + ColorConsole.WriteLine($"{msmq.Status}", ConsoleColor.Green, prefix: $" Status: "); + ColorConsole.WriteLine($"{msmq.StatusDescription}", ConsoleColor.Green, prefix: " StatusDescription: "); + ColorConsole.WriteLine($"{msmq.Id}", ConsoleColor.Green, prefix: " Id: "); + ColorConsole.WriteLine($"{msmq.Label}", ConsoleColor.Green, prefix: " Label: "); + ColorConsole.WriteLine($"{msmq.Path}", ConsoleColor.Green, prefix: " Path: "); + ColorConsole.WriteLine($"{msmq.FormatName}", ConsoleColor.Green, prefix: " FormatName: "); + ColorConsole.Write($"{msmq.Transactional}", ConsoleColor.Green, prefix: " Transactional: ", suffix: ", "); + ColorConsole.Write($"{msmq.UseJournalQueue}", ConsoleColor.Green, suffix: ", ", prefix: "UseJournalQueue: "); + ColorConsole.Write($"{msmq.AccessMode}", ConsoleColor.Green, suffix: ", ", prefix: "AccessMode: "); + ColorConsole.Write($"{msmq.CanRead}", ConsoleColor.Green, suffix: ", ", prefix: "CanRead: "); + ColorConsole.Write($"{msmq.CanWrite}", ConsoleColor.Green, suffix: ", ", prefix: "CanWrite: "); + ColorConsole.WriteLine(); + ColorConsole.Write($"{msmq.Authenticate}", ConsoleColor.Green, suffix: ", ", prefix: " Authenticate: "); + ColorConsole.Write($"{msmq.BasePriority}", ConsoleColor.Green, suffix: ", ", prefix: "BasePriority: "); + ColorConsole.Write($"{msmq.EncryptionRequired}", ConsoleColor.Green, suffix: ", ", prefix: "EncryptionRequired: "); + ColorConsole.WriteLine(); + ColorConsole.Write($"{msmq.Formatter}", ConsoleColor.Green, suffix: ", ", prefix: " Formatter: "); + ColorConsole.Write($"{msmq.LastModifyTime}", ConsoleColor.Green, suffix: ", ", prefix: "LastModifyTime: "); + ColorConsole.WriteLine(); + ColorConsole.Write($"{msmq.NumOfMessages}", ConsoleColor.Green, suffix: ", ", prefix: " NumOfMessages: "); + ColorConsole.Write($"{msmq.MaximumJournalSize}", ConsoleColor.Green, suffix: ", ", prefix: "MaximumJournalSize: "); + ColorConsole.Write($"{msmq.MaximumQueueSize}", ConsoleColor.Green, suffix: ", ", prefix: "MaximumQueueSize: "); + ColorConsole.WriteLine(); + } + } + catch (Exception ex) { ColorConsole.WriteLine(" " + ex.Message, ConsoleColor.Red); } + } + } + #endregion DisplayInfo + + #region XmlStructure + public static class XmlStructure + { + public static class MSMQManager + { + public static class General + { + public static class AccessRights + { + public static class AccessRight + { + public static class Attributes + { + public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } + public static class Right {public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } + public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } + } + } + } + public static class MessageFiles + { + public static class Attributes + { + public static class Directory { public static class Values { public const string DEFAULT = ""; } } + public static class SendToMask { public static class Values { public const string DEFAULT = "*.*"; } } + public static class ReadToMask { public static class Values { public const string DEFAULT = "*.*"; } } + } + } + public static class DefaultFormatter { public static class Values { public const string DEFAULT = nameof(ActiveXMessageFormatter); } } + public static class DefaultEncoding { public static class Values { public const string DEFAULT = nameof(System.Text.Encoding.UTF8); } } + } + + public static class MessageQueues + { + public static class MessageQueue + { + public static class Attributes + { + public static class Key { public static class Values { public const string DEFAULT = ""; } } + public static class AddressPrefix{ public static class Values { public const string DEFAULT = ""; } } + public static class Server { public static class Values { public const string DEFAULT = "."; } } + public static class Name { } + public static class Label { } + public static class Mode + { + public static class Values + { + public const string DEFAULT = "In"; + public static class In { } + public static class Out { } + } + } + public static class Formatter + { + public static class Values + { + public static class ActiveXMessageFormatter { } + public static class BinaryMessageFormatter { } + public static class XmlMessageFormatter { } + } + } + public static class Encoding { } + } + public static class AccessRight + { + public static class Attributes + { + public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } + public static class Right { public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } + public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } + } + } + } + } + } + } + #endregion XmlStructure + } +} diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs index a542f5e..89ba7e3 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs @@ -37,7 +37,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Remove.KEY, "Remove MSMQ", Remove, ep)) .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.SetPermissions.KEY, "Set MSMQ permisssions", SetPermissions, ep)) .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.SetDefaultPermissions.KEY, "Set default MSMQ permisssions", SetDefaultPermissions, ep)) - .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.GetInfo.KEY, "Get MSMQ information", GetInfo, 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 remoteMSMQ information", GetRemoteInfo, 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)) @@ -57,7 +58,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Create)}'!", silent: true); + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Create)}'!", silent: true); Menu.Selection sr = menufolders.Select(selectedtaskindexes); if (sr.Result == Menu.SelectionResult.Exit) { return o; } @@ -70,7 +71,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS MSMQ st = p.Parameters as MSMQ; try { - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); MSMQManagerCore.CreateQueue(fullpath, st.Xml_Label); ColorConsole.WriteLine($"MSMQ:{st.Xml_Name} created.", ConsoleColor.Green); foreach (var a in st.Xml_AccessRights) @@ -96,7 +97,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Remove)}'!", silent: true); + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Remove)}'!", silent: true); Menu.Selection sr = menufolders.Select(selectedtaskindexes); if (sr.Result == Menu.SelectionResult.Exit) { return o; } @@ -109,7 +110,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS MSMQ st = p.Parameters as MSMQ; try { - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); MSMQManagerCore.DeleteQueue(fullpath); ColorConsole.WriteLine($"MSMQ:{st.Xml_Name} removed.", ConsoleColor.Green); } @@ -124,7 +125,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(SetDefaultPermissions)}'!", silent: true) + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(SetDefaultPermissions)}'!", silent: true) .SetSelectionMode(Menu.SelectionMode.Multi); Menu.Selection sr = menufolders.Select(selectedtaskindexes); @@ -141,7 +142,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS { foreach (var a in st.Xml_AccessRights) { - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); MSMQManagerCore.SetPermissions(fullpath, a.un, a.ar, a.ac); string ctrlstring = a.ac == AccessControlEntryType.Allow ? "allowed" @@ -163,7 +164,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(SetPermissions)}'!", silent: true) + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(SetPermissions)}'!", silent: true) .SetSelectionMode(Menu.SelectionMode.Multi); Menu.Selection sr = menufolders.Select(selectedtaskindexes); @@ -195,7 +196,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS MSMQ st = p.Parameters as MSMQ; try { - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); MSMQManagerCore.SetPermissions(fullpath, username, accessrights, controltype); ColorConsole.WriteLine($"Permissions set for MSMQ:{st.Xml_Name}. Username:{username}, access right: {accessrights}, control type: {controltype}", ConsoleColor.Green); } @@ -208,14 +209,67 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS } return o; } - private static object GetInfo(object parameter, object o) + private static object GetRemoteInfo(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 = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(GetInfo)}'!", silent: true) + string sndefault = null; + string sn; + while (true) + { + sn = ColorConsole.ReadLine("Enter server ip/name to get queue info from (enter . for localhost)",defaultvalue:sndefault); + if (sn.ToLower() == "ex") { return o; } + sndefault = sn; + + List queuearray = new List(); + queuearray = System.Messaging.MessageQueue.GetPrivateQueuesByMachine(sn).ToList(); + + var menumsmqs = DisplayMSMQMenu(queuearray.Select((q, ixx) => new MSMQ(q, "Q"+((ixx + 1).ToString()))).ToList(), $"Select the MSMQ(s) on server '{sn}'!", silent: false,midf: DisplayMSMQShortInfo) + .SetSelectionMode(Menu.SelectionMode.Multi); + + Menu.Selection sr = menumsmqs.Select(); + 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 { } + var ix = 1; + foreach (var p in sr.SelectedParameterList) + { + var msmq = p.Parameters as MSMQ; + msmq.DisplayInfo(); ix++; + var sp = SendParameters.Get(msmq.Xml_Encoding, msmq.Xml_Formatter); + if (sp != null) + { + var fullpath = MSMQManagerCore.CreateFullQueuePath(msmq.Xml_AddressPrefix, msmq.Xml_Server, msmq.Xml_Name); + MSMQManagerCore.Send(fullpath, sp.messagebody, sp.messagelabel, sp.messageformatter, sp.encoding); + ColorConsole.WriteLine($"Sending to '{fullpath}' ....", ConsoleColor.Yellow); + MSMQManagerCore.ReadLast(fullpath, sp.messageformatter, sp.encoding, out string body, out string label); + if (sp.messagebody == body && sp.messagelabel == label) { ColorConsole.WriteLine($"Message successfully sent to '{fullpath}' and read back!", ConsoleColor.Green); } + else + { + ColorConsole.WriteLine(body, prefix: "Read back body: ", f: ConsoleColor.Red); + ColorConsole.WriteLine(label, prefix: "Read back label: ", f: ConsoleColor.Red); + ColorConsole.WriteLine($"Message sending or read back is failed to '{fullpath}' !", ConsoleColor.Red); + } + } + } + } + + return o; + } + + private static object GetLocalInfo(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(GetLocalInfo)}'!", silent: true) .SetSelectionMode(Menu.SelectionMode.Multi); Menu.Selection sr = menufolders.Select(selectedtaskindexes); @@ -226,51 +280,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS else { } foreach (var p in sr.SelectedParameterList) { - MSMQ st = p.Parameters as MSMQ; - ColorConsole.Write($">>> MSMQ detailed info collected for ", ConsoleColor.Yellow); - ColorConsole.Write($"{st.QueueName}", ConsoleColor.Yellow,suffix:", ",prefix: " QueueName : "); - ColorConsole.Write($"{st.MachineName}", ConsoleColor.Yellow,prefix: "MachineName: "); - ColorConsole.WriteLine(); - var qqn = MSMQManagerCore.CreateQualifiedQueueName(st.Xml_AddressPrefix, st.Xml_Server,st.Xml_Private, st.Xml_Name); - var qexists = MSMQManagerCore.CheckIfQueueExists(st.Xml_Server, qqn); - if (!qexists) - { - ColorConsole.WriteLine($" Queue does not exist!", ConsoleColor.Red); - } - else - { - try - { - st = MSMQManagerCore.CollectMSMQInfo(st); - ColorConsole.WriteLine($"{st.Status}", ConsoleColor.Green,prefix: $" Status: "); - ColorConsole.WriteLine($"{st.StatusDescription}", ConsoleColor.Green,prefix:" StatusDescription: "); - ColorConsole.WriteLine($"{st.Id}", ConsoleColor.Green,prefix: " Id: "); - ColorConsole.WriteLine($"{st.Label}", ConsoleColor.Green,prefix: " Label: "); - ColorConsole.WriteLine($"{st.Path}", ConsoleColor.Green,prefix: " Path: "); - ColorConsole.WriteLine($"{st.FormatName}", ConsoleColor.Green,prefix: " FormatName: "); - ColorConsole.Write($"{st.Transactional}", ConsoleColor.Green, prefix: " Transactional: ",suffix: ", "); - ColorConsole.Write($"{st.UseJournalQueue}", ConsoleColor.Green, suffix: ", ",prefix: "UseJournalQueue: "); - ColorConsole.Write($"{st.AccessMode}", ConsoleColor.Green,suffix:", ",prefix: "AccessMode: "); - ColorConsole.Write($"{st.CanRead}", ConsoleColor.Green, suffix: ", ",prefix: "CanRead: "); - ColorConsole.Write($"{st.CanWrite}", ConsoleColor.Green, suffix: ", ",prefix: "CanWrite: "); - ColorConsole.WriteLine(); - ColorConsole.Write($"{st.Authenticate}", ConsoleColor.Green, suffix: ", ",prefix: " Authenticate: "); - ColorConsole.Write($"{st.BasePriority}", ConsoleColor.Green, suffix: ", ",prefix: "BasePriority: "); - ColorConsole.Write($"{st.EncryptionRequired}", ConsoleColor.Green, suffix: ", ",prefix: "EncryptionRequired: "); - ColorConsole.WriteLine(); - ColorConsole.Write($"{st.Formatter}", ConsoleColor.Green, suffix: ", ",prefix: " Formatter: "); - ColorConsole.Write($"{st.LastModifyTime}", ConsoleColor.Green, suffix: ", ",prefix: "LastModifyTime: "); - ColorConsole.WriteLine(); - ColorConsole.Write($"{st.NumOfMessages}", ConsoleColor.Green, suffix: ", ",prefix: " NumOfMessages: "); - ColorConsole.Write($"{st.MaximumJournalSize}", ConsoleColor.Green, suffix: ", ",prefix: "MaximumJournalSize: "); - ColorConsole.Write($"{st.MaximumQueueSize}", ConsoleColor.Green, suffix: ", ",prefix: "MaximumQueueSize: "); - ColorConsole.WriteLine(); - } - catch (Exception ex) { ColorConsole.WriteLine(" "+ex.Message, ConsoleColor.Red); } - } + MSMQ msmq = p.Parameters as MSMQ; + msmq.DisplayInfo(); } return o; } + private static object Peek(object parameter, object o) { var config = (parameter as Menu.ExecutorParameter).GetConfig(); @@ -278,7 +293,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Peek)}'!", silent: true) + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Peek)}'!", silent: true) .SetSelectionMode(Menu.SelectionMode.Single); Menu.Selection sr = menufolders.Select(selectedtaskindexes); @@ -292,7 +307,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS MSMQ st = p.Parameters as MSMQ; try { - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); MSMQManagerCore.Peek(fullpath, out string msgbody, out string msglabel); ColorConsole.WriteLine($"Message peeked from MSMQ:{st.Xml_Name}", ConsoleColor.Green); ColorConsole.WriteLine($" Body: {msgbody}", ConsoleColor.Yellow); @@ -312,7 +327,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Read)}'!", silent: true) + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Read)}'!", silent: true) .SetSelectionMode(Menu.SelectionMode.Single); Menu.Selection sr = menufolders.Select(selectedtaskindexes); @@ -328,7 +343,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS { var messageformatter = new ActiveXMessageFormatter(); var encoding = Encoding.UTF8; - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); MSMQManagerCore.Read(fullpath, messageformatter, encoding, out string msgbody, out string msglabel); ColorConsole.WriteLine($"Message read from MSMQ:{st.Xml_Name}", ConsoleColor.Green); ColorConsole.WriteLine($" Body: {msgbody}", ConsoleColor.Yellow); @@ -348,7 +363,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Send)}'!", silent: true) + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Send)}'!", silent: true) .SetSelectionMode(Menu.SelectionMode.Single); Menu.Selection sr = menufolders.Select(selectedtaskindexes); @@ -364,25 +379,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS { try { - var now = DateTime.Now.ToString(); - string messagebody = ColorConsole.ReadLine("Enter message body:", ConsoleColor.Yellow, defaultvalue: "TEST MESSAGE " + now); - if (messagebody.ToUpper() == "EX") { break; } + var sp = SendParameters.Get(st.Xml_Encoding, st.Xml_Formatter); + if (sp == null) { break; } - string messagelabel = ColorConsole.ReadLine("Enter message label:", ConsoleColor.Yellow, defaultvalue: "TESTLABEL" + now); - if (messagelabel.ToUpper() == "EX") { break; } - - string messageformatterstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetFormatterNames(), defaultvalue: st.Xml_Formatter); - if (messageformatterstring.ToUpper() == "EX") { break; } - var messageformatter = MSMQManagerCore.SetFormatter(messageformatterstring); - if (messageformatter == null) { var exmsg = $"Message formatter value is incorrect! Value:{st.Xml_Formatter}."; throw new ApplicationException(exmsg); } - - string encodingstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetEncodingNames(), defaultvalue: st.Xml_Encoding); - if (encodingstring.ToUpper() == "EX") { break; } - var encoding = MSMQManagerCore.SetEncoding(encodingstring); - if (encoding == null) { var exmsg = $"Message encoder value is incorrect! Value:{st.Xml_Encoding}."; throw new ApplicationException(exmsg); } - - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); - MSMQManagerCore.Send(fullpath, messagebody, messagelabel, messageformatter, encoding); + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); + MSMQManagerCore.Send(fullpath,sp.messagebody, sp.messagelabel, sp.messageformatter, sp.encoding); ColorConsole.WriteLine($"Message sent to MSMQ:{st.Xml_Name}.", ConsoleColor.Green); } catch (ApplicationException ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } @@ -391,6 +392,59 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS } return o; } + private class ReadParameters + { + public IMessageFormatter messageformatter; + public Encoding encoding; + public static ReadParameters Get(string defaultencoding, string defaultformatter) + { + ColorConsole.WriteLine("Enter msmq read parameters!", ConsoleColor.Yellow); + var rp = new ReadParameters() { }; + + var messageformatterstring = ColorConsole.ReadLine("Enter formatter:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetFormatterNames(), defaultvalue: defaultformatter); + if (messageformatterstring.ToUpper() == "EX") { return null; } + rp.messageformatter = MSMQManagerCore.SetFormatter(messageformatterstring); + if (rp.messageformatter == null) { var exmsg = $"Message formatter value is incorrect! Value:{messageformatterstring }."; throw new ApplicationException(exmsg); } + + string encodingstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetEncodingNames(), defaultvalue: defaultencoding); + if (encodingstring.ToUpper() == "EX") { return null; } + rp.encoding = MSMQManagerCore.SetEncoding(encodingstring); + if (rp.encoding == null) { var exmsg = $"Message encoder value is incorrect! Value:{encodingstring}."; throw new ApplicationException(exmsg); } + + return rp; + } + } + private class SendParameters + { + public string messagebody; + public string messagelabel; + public IMessageFormatter messageformatter; + public Encoding encoding; + public SendParameters() { } + public static SendParameters Get(string defaultencoding, string defaultformatter) + { + ColorConsole.WriteLine("Enter test message data!",ConsoleColor.Yellow); + var sp = new SendParameters() { }; + var now = DateTime.Now.ToString(); + sp.messagebody = ColorConsole.ReadLine("Enter message body:", ConsoleColor.Yellow, defaultvalue: "TEST MESSAGE " + now); + if (sp.messagebody.ToUpper() == "EX") { return null; } + + sp.messagelabel = ColorConsole.ReadLine("Enter message label:", ConsoleColor.Yellow, defaultvalue: "TESTLABEL" + now); + if (sp.messagelabel.ToUpper() == "EX") { return null; } + + var messageformatterstring = ColorConsole.ReadLine("Enter formatter:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetFormatterNames(), defaultvalue: defaultformatter); + if (messageformatterstring.ToUpper() == "EX") { return null; } + sp.messageformatter = MSMQManagerCore.SetFormatter(messageformatterstring); + if (sp.messageformatter == null) { var exmsg = $"Message formatter value is incorrect! Value:{messageformatterstring }."; throw new ApplicationException(exmsg); } + + string encodingstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetEncodingNames(), defaultvalue: defaultencoding); + if (encodingstring.ToUpper() == "EX") { return null; } + sp.encoding = MSMQManagerCore.SetEncoding(encodingstring); + if (sp.encoding == null) { var exmsg = $"Message encoder value is incorrect! Value:{encodingstring}."; throw new ApplicationException(exmsg); } + + return sp; + } + } private static object Purge(object parameter, object o) { var config = (parameter as Menu.ExecutorParameter).GetConfig(); @@ -398,7 +452,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Purge)}'!", silent: true); + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Purge)}'!", silent: true); Menu.Selection sr = menufolders.Select(selectedtaskindexes); if (sr.Result == Menu.SelectionResult.Exit) { return o; } @@ -411,7 +465,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS MSMQ st = p.Parameters as MSMQ; try { - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); MSMQManagerCore.Purge(fullpath); ColorConsole.WriteLine($"MSMQ messages purged. Name:{st.Xml_Name}", ConsoleColor.Green); } @@ -423,19 +477,23 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS #region private methods #region private DisplayTasks - private static void MSMQListDisplayer() { DisplayMSMQMenu(); } - private static Menu DisplayMSMQMenu(MSMQManagerXmlProcessor config = null, string prompt = null, bool silent = false) + private static void MSMQListDisplayer() { DisplayMSMQMenuFromXml(); } + private static Menu DisplayMSMQMenuFromXml(MSMQManagerXmlProcessor config = null, string prompt = null, bool silent = false) { if (config == null) { config = new MSMQManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); } List msmqdefList = config.GetDefinitionList(); - var menufct = new Menu("Scheduled tasks", prompt) - .SetMenuItemDisplayer(DisplayMSMQInfo) + return DisplayMSMQMenu(msmqdefList, prompt,silent,DisplayMSMQInfo); + } + private static Menu DisplayMSMQMenu(List msmqlist = null, string prompt = null, bool silent = false,Menu.MenuItemDisplayerFunc midf=null) + { + List msmqdefList = msmqlist; + var menufct = new Menu("MSMQ list", prompt) + .SetMenuItemDisplayer(midf) .SetSelectionMode(Menu.SelectionMode.Multi); menufct.ClearMenuItemList(); foreach (var msmqdef in msmqdefList) { - var st = MSMQManagerCore.CollectMSMQInfo(msmqdef); - menufct.AddMenuItem(new Menu.Item(msmqdef.Xml_Key, null, null, new Menu.ExecutorParameter(pars: st))); + menufct.AddMenuItem(new Menu.Item(msmqdef.Xml_Key, null, null, new Menu.ExecutorParameter(pars: msmqdef.CollectMSMQInfo()))); } if (!silent) { menufct.DisplayItems(1); } return menufct; @@ -445,79 +503,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS private static object DisplayMSMQInfo(object obj, int lineix) { MSMQ st = (obj as Menu.ExecutorParameter).Parameters as MSMQ; - if (lineix == 0) - { - ColorConsole.Write($"{st.Xml_Name}", ConsoleColor.Black, ConsoleColor.White,prefix: "Queue '",suffix: $"' queue label: '{st.Xml_Label}'."); - ConsoleColor statuscolor; - if (st.Status == "Uninstalled") { statuscolor = ConsoleColor.Red; } - else if (st.Status == "Error") { statuscolor = ConsoleColor.Red; } - else if (st.Status == "Installed") { statuscolor = ConsoleColor.Yellow; } - else if (st.Status == "Ready") { statuscolor = ConsoleColor.Green; } - else { statuscolor = ConsoleColor.Red; } - ColorConsole.Write(st.Status, statuscolor, bracket: "[]", prefix: " ", suffix: ". "); - ColorConsole.WriteLine(); - return " "; - } - else if (lineix == 1) - { - var privatepublictext = st.Xml_Private ? "private" : "public"; - ColorConsole.Write($"{st.Xml_AddressPrefix}{st.Xml_Server}", ConsoleColor.Black, ConsoleColor.White, prefix: "Server:", suffix: $"Queue is { privatepublictext }."); - ColorConsole.WriteLine(); - return " "; - } - else if (lineix == 2) - { - ColorConsole.Write($"{st.Path}", ConsoleColor.Yellow, prefix: "Path ", suffix: ", "); - ColorConsole.WriteLine(); - return " "; - } - else if (lineix == 3) - { - if (st.StatusDescription != null) - { - ConsoleColor color = ConsoleColor.Yellow; - if (st.Status == "Ready") { color = ConsoleColor.Green; } - else if (st.Status == "Error") { color = ConsoleColor.Red; } - ColorConsole.Write($"{st.StatusDescription}", color, prefix: "Status description "); - ColorConsole.WriteLine(); - return " "; - } - return "";//empty=van még szöveg, de most nem történt kiírás - } - else if (lineix == 4) - { - if (st.Status == "Ready") - { - ColorConsole.Write($"{st.FormatName}", ConsoleColor.Yellow, prefix: "FormatName "); - ColorConsole.WriteLine(); - return " "; - } - return ""; - } - else if (lineix == 5) - { - if (st.Status == "Ready") - { - ColorConsole.Write(st.NumOfMessages.ToString(), ConsoleColor.Yellow, prefix: "Num.of msgs in queue ", suffix: ". "); - ColorConsole.Write($"{st.LastModifyTime}", ConsoleColor.Yellow, prefix: "LastModified ", suffix: ", "); - ColorConsole.WriteLine(); - return " "; - } - return ""; - } - else if (lineix == 6) - { - if (st.Status == "Ready") - { - ColorConsole.Write($"{st.AccessMode}", ConsoleColor.Yellow, prefix: "AccessMode ", suffix: ", "); - ColorConsole.Write($"{st.CanRead}", ConsoleColor.Yellow, prefix: "CanRead ", suffix: ", "); - ColorConsole.Write($"{st.CanWrite}", ConsoleColor.Yellow, prefix: "CanWrite ", suffix: ", "); - ColorConsole.WriteLine(); - return " "; - } - return ""; - } - return null; + return st.DisplayShortInfo(lineix); + } + private static object DisplayMSMQShortInfo(object obj, int lineix) + { + MSMQ st = (obj as Menu.ExecutorParameter).Parameters as MSMQ; + return st.DisplayVeryShortInfo(lineix); } #endregion private method: DisplayTaskInfo #endregion private methods @@ -527,24 +518,17 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS #region MSMQManagerCore class internal static class MSMQManagerCore { - public static string CreateFullQueuePath(string addressprefix, string msmqservername, bool msmqprivate, string msmqname) + public static string CreateFullQueuePath(string addressprefix, string msmqservername, string msmqname) { - CreateQueueNames(addressprefix, msmqservername, msmqprivate, msmqname, out string qqn, out string qfn); + CreateQueueNames(addressprefix, msmqservername, msmqname, out string qfn); return qfn; } - public static string CreateQualifiedQueueName(string addressprefix, string msmqservername, bool msmqprivate, string msmqname) - { - CreateQueueNames(addressprefix, msmqservername, msmqprivate, msmqname, out string qqn, out string qfn); - return qqn; - } - private static void CreateQueueNames(string addressprefix, string msmqservername, bool msmqprivate, string msmqname,out string queuequalifiedname, out string msmqFullname) + private static void CreateQueueNames(string addressprefix, string msmqservername, string msmqname, out string msmqFullname) { - var msmqprivatenamepart = msmqprivate ? "private$\\" : ""; if (msmqservername == "." || msmqservername.ToLower() == "localhost") { msmqservername = System.Environment.MachineName; } var msmqservernamepart = string.IsNullOrWhiteSpace(msmqservername) ? "" : $"{msmqservername}\\"; addressprefix = string.IsNullOrWhiteSpace(addressprefix) ? "" : addressprefix; - msmqFullname = $"{addressprefix}{msmqservernamepart}{msmqprivatenamepart}{msmqname}"; - queuequalifiedname = $"{msmqprivatenamepart}{msmqname}"; + msmqFullname = $"{addressprefix}{msmqservernamepart}{msmqname}"; } public static bool CheckIfQueueExists(string servername,string queuefullname) { @@ -558,53 +542,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS //var queuenamelist = queuearray.Select(q => q.Path == queuefullname || q.FormatName== queuefullname || q.QueueName== queuefullname).ToList(); //return queuenamelist.Any(); } - public static MSMQ CollectMSMQInfo(MSMQ msmgqef) - { - string msmqaddressprefix = msmgqef.Xml_AddressPrefix; - string msmqservername = msmgqef.Xml_Server; - bool msmqprivate = msmgqef.Xml_Private; - string msmqname = msmgqef.Xml_Name; - var msmqprivatenamepart = msmqprivate ? "private$\\" : ""; - string msmqFullname = $"{msmqaddressprefix}{msmqservername}\\{msmqprivatenamepart}{msmqname}"; - msmgqef.QueueName = msmqname ; - msmgqef.MachineName = msmqservername; - msmgqef.Path = msmqFullname; - try - { - msmgqef.Status = MessageQueue.Exists(msmqFullname) ? "Installed" : "Uninstalled"; - if (msmgqef.Status == "Installed") - { - using (var msmq = new MessageQueue(msmqFullname)) - { - msmgqef.QueueName = msmq.QueueName; - msmgqef.MachineName = msmq.MachineName; - - msmgqef.Id = msmq.Id; - msmgqef.NumOfMessages = MSMQManagerCore.Count(msmq); - msmgqef.Label = msmq.Label; - msmgqef.Formatter = msmq.Formatter; - msmgqef.FormatName = msmq.FormatName; - msmgqef.Path = msmq.Path; - msmgqef.LastModifyTime = msmq.LastModifyTime; - msmgqef.AccessMode = msmq.AccessMode; - msmgqef.CanRead = msmq.CanRead; - msmgqef.CanWrite = msmq.CanWrite; - msmgqef.MaximumQueueSize = msmq.MaximumQueueSize; - msmgqef.UseJournalQueue = msmq.UseJournalQueue; - msmgqef.MaximumJournalSize = msmq.MaximumJournalSize; - - msmgqef.Transactional = msmq.Transactional; - msmgqef.Authenticate = msmq.Authenticate; - msmgqef.BasePriority = msmq.BasePriority; - msmgqef.EncryptionRequired = msmq.EncryptionRequired; - - msmgqef.Status = "Ready"; - } - } - } - catch (Exception ex) { msmgqef.Status = "Error"; msmgqef.StatusDescription = ex.Message + (ex.InnerException!=null? ("\n" + ex.InnerException.Message):""); } - return msmgqef; - } public static void CreateQueue(string msmqFullname, string label=null) { if (!MessageQueue.Exists(msmqFullname)) { MessageQueue.Create(msmqFullname); } @@ -684,6 +621,38 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); } } + public static void ReadLast(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) + { + body = ""; + label = ""; + using (var msmq = new MessageQueue(msmqFullname)) + { + if (Count(msmq)>0) + { + //frmA = new System.Messaging.ActiveXMessageFormatter(); + //frmA = new System.Messaging.BinaryMessageFormatter(); + //frmA = new System.Messaging.XmlMessageFormatter(); + msmq.Formatter = messageformatter; + //Message m = msmq.Receive(new TimeSpan(0)); + var m = msmq.ReceiveByLookupId(MessageLookupAction.Last, 0, null); + label = m.Label; + body = encoding.GetString((byte[])m.Body); + + + //m.BodyStream.Position = 0; + + //// encoding = System.Text.Encoding.UTF8; + //// encoding = System.Text.Encoding.UTF7; + //// encoding = System.Text.Encoding.UTF32; + //// encoding = System.Text.Encoding.Unicode; + //// encoding = System.Text.Encoding.BigEndianUnicode; + //// encoding = System.Text.Encoding.ASCII; + //// encoding = System.Text.Encoding.Default; + //var sr = new System.IO.StreamReader(m.BodyStream, encoding); + //body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); + } + } + } public static void Send(string msmqFullname, string messagetosend, string messagelabel, IMessageFormatter messageformatter, Encoding encoding) { using (var msmq = new MessageQueue(msmqFullname)) @@ -821,187 +790,4 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS } } #endregion Defaults class - - #region MSMQ class - public class MSMQ : XmlLinqBase - { - #region fields - public bool Valid = true; - public string Xml_Key; - public string Xml_Name; - public string Xml_AddressPrefix = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT; - public string Xml_Server = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT; - public bool Xml_Private = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Private.Values.DEFAULT; - public string Xml_Mode = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT; - public string Xml_Label; - public string Xml_Formatter = XmlStructure.MSMQManager.General.DefaultFormatter.Values.DEFAULT; - public string Xml_Encoding = XmlStructure.MSMQManager.General.DefaultEncoding.Values.DEFAULT; - public List Xml_AccessRights = new List(); - - public string Status; - public string StatusDescription=null; - public Guid Id; - public string QueueName; - public long NumOfMessages; - public string Label; - public string MachineName; - public IMessageFormatter Formatter; - public string FormatName; - public string Path; - public DateTime LastModifyTime; - public QueueAccessMode AccessMode; - public bool CanRead; - public bool CanWrite; - public long MaximumQueueSize; - public bool UseJournalQueue; - public long MaximumJournalSize; - - public bool Transactional; - public bool Authenticate; - public int BasePriority; - public EncryptionRequired EncryptionRequired; - #endregion fields - - #region basic constructor - public MSMQ() { } - #endregion basic constructor - #region xml constructor - public string PriorityText(int pri) - { - return - (pri == 0 ? "Realtime" - : pri == 1 ? "High" - : pri == 2 ? "High" - : pri == 3 ? "Normal" - : pri == 4 ? "Normal" - : pri == 5 ? "Normal" - : pri == 6 ? "Normal" - : pri == 7 ? "Low" - : pri == 8 ? "Low" - : pri == 9 ? "Idle" - : pri == 10 ? "Idle" - : "Idle") + $"({pri})"; - } - public MSMQ(XElement msmqxml,MSMQDefaults msmqdefaults) - { - Valid = true; - string ATTRIBUTEMANDATORY = nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue) + " attribute is mandatory! Name: {0}"; - Xml_Key = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key.Values.DEFAULT); - Xml_Name = msmqxml.Attribute(XName.Get(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name)))?.Value; - if (string.IsNullOrWhiteSpace(Xml_Name)) { throw new ApplicationException(string.Format(ATTRIBUTEMANDATORY, nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name))); } - Xml_AddressPrefix = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT); - Xml_Server = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT); - if (Xml_Server == "." || Xml_Server.ToLower() == "localhost") { Xml_Server = System.Environment.MachineName; } - - Xml_Private = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Private), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Private.Values.DEFAULT); - Xml_Mode = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT); - Xml_Label = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Label), msmqxml, Xml_Name); - Xml_Formatter = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter), msmqxml, msmqdefaults.Xml_DefaultFormatter); - Xml_Encoding = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Encoding), msmqxml, msmqdefaults.Xml_DefaultEncoding); - - foreach (var ar in msmqdefaults.Xml_AccessRights) { Xml_AccessRights.Add(ar); } - try - { - var arxmllist = GetAllXElements(msmqxml, nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.AccessRight)); - foreach (var arxml in arxmllist) { var newa = AccessRights.Factory(arxml); if (newa != null) { Xml_AccessRights.Add(newa); } } - } - catch{ } - - - } - #endregion xml constructor - #region cloner constructor - public MSMQ(MSMQ msmq) - { - Valid = msmq.Valid; - Xml_Key = msmq.Xml_Key; - Xml_Name = msmq.Xml_Name; - Xml_Server = msmq.Xml_Server; - Xml_Private = msmq.Xml_Private; - Xml_Mode = msmq.Xml_Mode; - Xml_Label = msmq.Xml_Label; - Xml_Formatter= msmq.Xml_Formatter; - Xml_Encoding = msmq.Xml_Encoding; - } - #endregion cloner constructor - #region XmlStructure - public static class XmlStructure - { - public static class MSMQManager - { - public static class General - { - public static class AccessRights - { - public static class AccessRight - { - public static class Attributes - { - public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } - public static class Right {public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } - public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } - } - } - } - public static class MessageFiles - { - public static class Attributes - { - public static class Directory { public static class Values { public const string DEFAULT = ""; } } - public static class SendToMask { public static class Values { public const string DEFAULT = "*.*"; } } - public static class ReadToMask { public static class Values { public const string DEFAULT = "*.*"; } } - } - } - public static class DefaultFormatter { public static class Values { public const string DEFAULT = nameof(ActiveXMessageFormatter); } } - public static class DefaultEncoding { public static class Values { public const string DEFAULT = nameof(System.Text.Encoding.UTF8); } } - } - - public static class MessageQueues - { - public static class MessageQueue - { - public static class Attributes - { - public static class Key { public static class Values { public const string DEFAULT = ""; } } - public static class AddressPrefix{ public static class Values { public const string DEFAULT = ""; } } - public static class Server { public static class Values { public const string DEFAULT = "."; } } - public static class Name { } - public static class Label { } - public static class Private { public static class Values { public const bool DEFAULT = true; } } - public static class Mode - { - public static class Values - { - public const string DEFAULT = "In"; - public static class In { } - public static class Out { } - } - } - public static class Formatter - { - public static class Values - { - public static class ActiveXMessageFormatter { } - public static class BinaryMessageFormatter { } - public static class XmlMessageFormatter { } - } - } - public static class Encoding { } - } - public static class AccessRight - { - public static class Attributes - { - public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } - public static class Right { public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } - public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } - } - } - } - } - } - } - #endregion XmlStructure - } - #endregion MSMQ class } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs index 63ae0ce..4dfce6f 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs @@ -71,7 +71,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS #region RegexTester public static object StartAsSystem(object parameter, object o) { - OtherTools.StartAsSystem(false); + OtherTools.StartAsSystem(true); return o; } private static object RegexTester(object parameter, object o) diff --git a/Vrh.Log4Pro.MaintenanceConsole/Program.cs b/Vrh.Log4Pro.MaintenanceConsole/Program.cs index bdd92e4..8ec9bd4 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Program.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Program.cs @@ -37,8 +37,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole { static void Main(string[] args) { + var startassystemstr = CommandLine.GetCommandLineArgument(args, CLP.CMD_STARTASSYSTEM); + var startassystem = startassystemstr!=null && startassystemstr.ToLower() == "yes"; + OtherTools.StartAsAdmin(); - OtherTools.StartAsSystem(silent:false); + OtherTools.StartAsSystem(silent:startassystem); //while (true) //{ // Console.Clear(); diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index 110d7c2..67125cc 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.9.0.0")] -[assembly: AssemblyFileVersion("1.9.0.0")] +[assembly: AssemblyVersion("1.9.2.0")] +[assembly: AssemblyFileVersion("1.9.2.0")] diff --git a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj index e0cd6ec..8e5bf8d 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj +++ b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj @@ -359,6 +359,7 @@ + -- libgit2 0.21.2