From f13d7fa30950712036694972fb158231b8025bf7 Mon Sep 17 00:00:00 2001 From: Schwirg László Date: Tue, 23 Nov 2021 09:27:59 +0100 Subject: [PATCH] apró szépészeti javítások --- Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager - MSMQ.cs | 426 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs | 611 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------- Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj | 1 - 3 files changed, 546 insertions(+), 492 deletions(-) delete mode 100644 Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager - MSMQ.cs diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager - MSMQ.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager - MSMQ.cs deleted file mode 100644 index fc46d82..0000000 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager - MSMQ.cs +++ /dev/null @@ -1,426 +0,0 @@ -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 89ba7e3..f703ac6 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs @@ -74,16 +74,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS 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) + foreach (var accessright in st.Xml_AccessRights) { - MSMQManagerCore.SetPermissions(fullpath, a.un, a.ar, a.ac); - string ctrlstring = - a.ac == AccessControlEntryType.Allow ? "allowed" - : a.ac == AccessControlEntryType.Deny ? "denied" - : a.ac == AccessControlEntryType.Revoke ? "revoked" - : a.ac == AccessControlEntryType.Set ? "set" - : "???"; - ColorConsole.WriteLine($"Access right {a.ar} {ctrlstring} for user:{a.un}.", ConsoleColor.Green); + MSMQManagerCore.SetPermissions(fullpath, accessright.un, accessright.ar, accessright.ac); + string ctrlstring = accessright.AccessControlEntryTypeText(); + ColorConsole.WriteLine($"Access right {accessright.ar} {ctrlstring} for user:{accessright.un}.", ConsoleColor.Green); } } catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } @@ -140,17 +135,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS MSMQ st = p.Parameters as MSMQ; try { - foreach (var a in st.Xml_AccessRights) + foreach (var accessright in st.Xml_AccessRights) { 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" - : a.ac == AccessControlEntryType.Deny ? "denied" - : a.ac == AccessControlEntryType.Revoke ? "revoked" - : a.ac == AccessControlEntryType.Set ? "set" - : "???"; - ColorConsole.WriteLine($"Access right {a.ar} {ctrlstring} for user:{a.un}.", ConsoleColor.Green); + MSMQManagerCore.SetPermissions(fullpath, accessright.un, accessright.ar, accessright.ac); + string ctrlstring = accessright.AccessControlEntryTypeText(); + ColorConsole.WriteLine($"Access right {accessright.ar} {ctrlstring} for user:{accessright.un}.", ConsoleColor.Green); } } catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } @@ -247,13 +237,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS 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 + Message msg = MSMQManagerCore.PeekLast(fullpath, sp.messageformatter, sp.encoding, out string body, out string label); + TestSendCheckMessage(fullpath, msg, sp, body, label, "message sending/peek back"); + var ans = ColorConsole.ReadLine($"Do You want to remove this test message (lookup id='{msg.LookupId}') from quue?", ConsoleColor.Yellow,validitylist:new List { "yes","no"},defaultvalue:"yes"); + if (ans.ToLower() == "yes") { - 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); + msg = MSMQManagerCore.ReadById(fullpath, msg.LookupId, sp.messageformatter, sp.encoding, out body, out label); + TestSendCheckMessage(fullpath, msg, sp, body, label, "Read back."); } } } @@ -262,6 +252,16 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS return o; } + private static void TestSendCheckMessage(string fullpath,Message msg, SendParameters sp, string body, string label,string actiontext) + { + if (sp.messagebody == body && sp.messagelabel == label) { ColorConsole.WriteLine($"Success! Action:{actiontext}. Queue:'{fullpath}'.", ConsoleColor.Green); } + else + { + ColorConsole.WriteLine(body, prefix: $"{actiontext} body: ", f: ConsoleColor.Red); + ColorConsole.WriteLine(label, prefix: $"{actiontext} label: ", f: ConsoleColor.Red); + ColorConsole.WriteLine($"Failure! Action:{actiontext}. Queue:'{fullpath}'.", ConsoleColor.Red); + } + } private static object GetLocalInfo(object parameter, object o) { var config = (parameter as Menu.ExecutorParameter).GetConfig(); @@ -307,8 +307,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS 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 = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); - MSMQManagerCore.Peek(fullpath, out string msgbody, out string msglabel); + MSMQManagerCore.Peek(fullpath, messageformatter, encoding, out string msgbody, out string msglabel); ColorConsole.WriteLine($"Message peeked from MSMQ:{st.Xml_Name}", ConsoleColor.Green); ColorConsole.WriteLine($" Body: {msgbody}", ConsoleColor.Yellow); ColorConsole.WriteLine($" Label: {msglabel}", ConsoleColor.Yellow); @@ -341,8 +343,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS MSMQ st = p.Parameters as MSMQ; try { - var messageformatter = new ActiveXMessageFormatter(); - var encoding = Encoding.UTF8; + var messageformatter = MSMQManagerCore.SetFormatter(st.Xml_Formatter); //new ActiveXMessageFormatter(); + var encoding = MSMQManagerCore.SetEncoding(st.Xml_Encoding); // Encoding.UTF8; 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); @@ -550,7 +552,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS if (!string.IsNullOrWhiteSpace(label)) { msmq.Label = label; } } } - public static void SetPermissions(string msmqFullname,string username, MessageQueueAccessRights accessrights, AccessControlEntryType controltype) + public static void SetPermissions(string msmqFullname,string username, MessageQueueAccessRights accessrights, AccessControlEntryType controltype) { using (var msmq = new MessageQueue(msmqFullname)) { @@ -571,7 +573,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS // | MessageQueueAccessRights.ReceiveMessage // | MessageQueueAccessRights.SetQueueProperties // | MessageQueueAccessRights.DeleteQueue; - msmq.SetPermissions("EveryOne", accessrights, controltype); + msmq.SetPermissions(username, accessrights, controltype); } } @@ -586,29 +588,74 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS msmq.Purge(); } } - public static void Peek(string msmqFullname, out string body, out string label) + public static Message Peek(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) { + body = ""; + label = ""; using (var msmq = new MessageQueue(msmqFullname)) { + if (Count(msmq) == 0) { return null; } + + msmq.Formatter = messageformatter; Message m = msmq.Peek(new TimeSpan(0)); - m.BodyStream.Position = 0; - var sr = new System.IO.StreamReader(m.BodyStream); label = m.Label; - body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); + //m.BodyStream.Position = 0; + //var sr = new System.IO.StreamReader(m.BodyStream); + //body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); + body = encoding.GetString((byte[])m.Body); + return m; } } - public static void Read(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) + public static Message PeekLast(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) { + body = ""; + label = ""; using (var msmq = new MessageQueue(msmqFullname)) { + if (Count(msmq) == 0) { return null; } + //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.PeekByLookupId(MessageLookupAction.Last, 0); + label = m.Label; + body = encoding.GetString((byte[])m.Body); + return m; - Message m = msmq.Receive(new TimeSpan(0)); - m.BodyStream.Position = 0; + //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 Message Read(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) + { + body = ""; + label = ""; + using (var msmq = new MessageQueue(msmqFullname)) + { + if (Count(msmq) == 0) { return null; } + + //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)); + label = m.Label; + //m.BodyStream.Position = 0; + //var sr = new System.IO.StreamReader(m.BodyStream, encoding); + //body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); // encoding = System.Text.Encoding.UTF8; // encoding = System.Text.Encoding.UTF7; // encoding = System.Text.Encoding.UTF32; @@ -616,41 +663,55 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS // 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 = encoding.GetString((byte[])m.Body); + return m; + } + } + public static Message 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) { return null; } + + //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 = sr.ReadToEnd().Replace(((char)0).ToString(), ""); + 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(), ""); + return m; } } - public static void ReadLast(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) + public static Message ReadById(string msmqFullname, long msgid, 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(), ""); - } + if (Count(msmq) == 0) {return null; } + + msmq.Formatter = messageformatter; + var m = msmq.ReceiveByLookupId(msgid); + label = m.Label; + body = encoding.GetString((byte[])m.Body); + return m; } } public static void Send(string msmqFullname, string messagetosend, string messagelabel, IMessageFormatter messageformatter, Encoding encoding) @@ -693,9 +754,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS r.Add(nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter.Values.XmlMessageFormatter)); return r; } - public static Encoding SetEncoding(string formattername) + public static Encoding SetEncoding(string encodingname) { - switch (formattername) + switch (encodingname) { case nameof(Encoding.UTF8): return Encoding.UTF8; case nameof(Encoding.UTF7): return Encoding.UTF7; @@ -758,6 +819,17 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS } catch { return null; } } + + public string AccessControlEntryTypeText() + { + AccessRights accessright = this; + return accessright.ac == AccessControlEntryType.Allow ? "allowed" + : accessright.ac == AccessControlEntryType.Deny ? "denied" + : accessright.ac == AccessControlEntryType.Revoke ? "revoked" + : accessright.ac == AccessControlEntryType.Set ? "set" + : "???"; + } + public string un; public MessageQueueAccessRights ar; public AccessControlEntryType ac; @@ -790,4 +862,413 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS } } #endregion Defaults class + + #region MSMQ + 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 + } + #endregion MSMQ + } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj index 8e5bf8d..e0cd6ec 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj +++ b/Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj @@ -359,7 +359,6 @@ - -- libgit2 0.21.2