Commit a6a553c95fcf878f09cb31546bac82fd1431c805
1 parent
823fdecc
1.9.2
Showing
8 changed files
with
627 additions
and
406 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
| ... | ... | @@ -187,6 +187,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS |
| 187 | 187 | public const string CMD_FUNCTION = "-FUNCTION"; |
| 188 | 188 | public const string CMD_SILENT = "-SILENT"; |
| 189 | 189 | public const string CMD_APPCONFIG = "-APPCONFIG"; |
| 190 | + public const string CMD_STARTASSYSTEM = "-SYSTEM"; | |
| 190 | 191 | public static class Module |
| 191 | 192 | { |
| 192 | 193 | public static class Log4ProUserManager |
| ... | ... | @@ -267,7 +268,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS |
| 267 | 268 | public static class Remove { public const string KEY = "UIN"; } |
| 268 | 269 | public static class SetPermissions { public const string KEY = "PRM"; } |
| 269 | 270 | public static class SetDefaultPermissions { public const string KEY = "DPR"; } |
| 270 | - public static class GetInfo { public const string KEY = "INF"; } | |
| 271 | + public static class GetLocalInfo { public const string KEY = "INF"; } | |
| 272 | + public static class GetRemoteInfo { public const string KEY = "RIN"; } | |
| 271 | 273 | public static class Send { public const string KEY = "SND"; } |
| 272 | 274 | public static class Peek { public const string KEY = "PEK"; } |
| 273 | 275 | public static class Read{ public const string KEY = "RED"; } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs
| ... | ... | @@ -19,6 +19,7 @@ using Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS; |
| 19 | 19 | using VRH.Common; |
| 20 | 20 | using Microsoft.Win32; |
| 21 | 21 | using System.Reflection; |
| 22 | +using Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS; | |
| 22 | 23 | |
| 23 | 24 | namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
| 24 | 25 | { |
| ... | ... | @@ -56,15 +57,17 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
| 56 | 57 | { |
| 57 | 58 | if (!silent) |
| 58 | 59 | { |
| 59 | - var ans = ColorConsole.ReadLine("NT AUTHORITY/SYSTEM", prefix: "Start as ",f:ConsoleColor.Yellow, suffix: "?", bracket: "[]",validitylist:new List<string> { "yes","no"},exitvalue:"EX",defaultvalue:"NO"); | |
| 60 | + var ans = ColorConsole.ReadLine("NT AUTHORITY\\SYSTEM", prefix: "Start as ",f:ConsoleColor.Yellow, suffix: "?", bracket: "[]",validitylist:new List<string> { "yes","no"},exitvalue:"EX",defaultvalue:"no"); | |
| 60 | 61 | if (ans.ToLower() != "yes") { return; } |
| 61 | 62 | } |
| 63 | + string runasusername = System.Security.Principal.WindowsIdentity.GetCurrent().Name; | |
| 64 | + if (runasusername=="NT AUTHORITY\\SYSTEM") { return; } | |
| 65 | + | |
| 62 | 66 | Process p = new System.Diagnostics.Process(); |
| 63 | 67 | p.StartInfo.FileName = @"C:\Log4ProIS\MAINTENANCECONSOLE\PsTools\psexec.exe"; |
| 64 | - p.StartInfo.Arguments = @"-sid C:\Log4ProIS\MAINTENANCECONSOLE\Vrh.Log4Pro.MaintenanceConsole.exe"; | |
| 65 | - // The UseShellExecute flag must be turned off in order to supply a password: | |
| 66 | 68 | p.StartInfo.UseShellExecute = false; |
| 67 | 69 | |
| 70 | + p.StartInfo.Arguments = @"-sid C:\Log4ProIS\MAINTENANCECONSOLE\Vrh.Log4Pro.MaintenanceConsole.exe " + CLP.CMD_STARTASSYSTEM + " YES"; | |
| 68 | 71 | p.Start(); |
| 69 | 72 | System.Environment.Exit(1); |
| 70 | 73 | } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager - MSMQ.cs
0 → 100644
| ... | ... | @@ -0,0 +1,426 @@ |
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Linq; | |
| 4 | +using System.Messaging; | |
| 5 | +using System.Text; | |
| 6 | +using System.Threading.Tasks; | |
| 7 | + | |
| 8 | +using Vrh.Log4Pro.MaintenanceConsole.MenuNS; | |
| 9 | +using Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS; | |
| 10 | +using Vrh.Log4Pro.MaintenanceConsole.ToolsNS; | |
| 11 | +using Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS; | |
| 12 | + | |
| 13 | +using Vrh.XmlProcessing; | |
| 14 | +using VRH.Common; | |
| 15 | +using System.Xml.Linq; | |
| 16 | +using System.Text.RegularExpressions; | |
| 17 | + | |
| 18 | + | |
| 19 | +namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS | |
| 20 | +{ | |
| 21 | + public class MSMQ : XmlLinqBase | |
| 22 | + { | |
| 23 | + #region fields | |
| 24 | + public bool Valid = true; | |
| 25 | + public string Xml_Key; | |
| 26 | + public string Xml_Name; | |
| 27 | + public string Xml_AddressPrefix = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT; | |
| 28 | + public string Xml_Server = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT; | |
| 29 | + public bool Private; | |
| 30 | + public string Xml_Mode = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT; | |
| 31 | + public string Xml_Label; | |
| 32 | + public string Xml_Formatter = XmlStructure.MSMQManager.General.DefaultFormatter.Values.DEFAULT; | |
| 33 | + public string Xml_Encoding = XmlStructure.MSMQManager.General.DefaultEncoding.Values.DEFAULT; | |
| 34 | + public List<AccessRights> Xml_AccessRights = new List<AccessRights>(); | |
| 35 | + | |
| 36 | + public string Status; | |
| 37 | + public string StatusDescription=null; | |
| 38 | + public Guid Id; | |
| 39 | + public string QueueName; | |
| 40 | + public long NumOfMessages; | |
| 41 | + public string Label; | |
| 42 | + public string MachineName; | |
| 43 | + public IMessageFormatter Formatter; | |
| 44 | + public string FormatName; | |
| 45 | + public string Path; | |
| 46 | + public DateTime LastModifyTime; | |
| 47 | + public QueueAccessMode AccessMode; | |
| 48 | + public bool CanRead; | |
| 49 | + public bool CanWrite; | |
| 50 | + public long MaximumQueueSize; | |
| 51 | + public bool UseJournalQueue; | |
| 52 | + public long MaximumJournalSize; | |
| 53 | + | |
| 54 | + public bool Transactional; | |
| 55 | + public bool Authenticate; | |
| 56 | + public int BasePriority; | |
| 57 | + public EncryptionRequired EncryptionRequired; | |
| 58 | + #endregion fields | |
| 59 | + | |
| 60 | + #region basic constructor | |
| 61 | + public MSMQ() { } | |
| 62 | + #endregion basic constructor | |
| 63 | + | |
| 64 | + #region constructor from MessageQueue | |
| 65 | + public MSMQ(MessageQueue msmq, string key) | |
| 66 | + { | |
| 67 | + Xml_Key = key; | |
| 68 | + Xml_Name = msmq.QueueName; | |
| 69 | + Xml_Label = msmq.QueueName; | |
| 70 | + Xml_Server = msmq.MachineName; | |
| 71 | + Private = msmq.QueueName.ToLower().StartsWith("private$"); | |
| 72 | + Xml_Formatter = msmq.Formatter.GetType().Name; | |
| 73 | + Xml_AddressPrefix = "FormatName:"+msmq.FormatName.Replace(msmq.MachineName+"\\"+msmq.QueueName,""); | |
| 74 | + } | |
| 75 | + #endregion constructor from MessageQueue | |
| 76 | + | |
| 77 | + #region xml constructor | |
| 78 | + public MSMQ(XElement msmqxml,MSMQDefaults msmqdefaults) | |
| 79 | + { | |
| 80 | + Valid = true; | |
| 81 | + string ATTRIBUTEMANDATORY = nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue) + " attribute is mandatory! Name: {0}"; | |
| 82 | + Xml_Key = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key.Values.DEFAULT); | |
| 83 | + Xml_Name = msmqxml.Attribute(XName.Get(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name)))?.Value; | |
| 84 | + if (string.IsNullOrWhiteSpace(Xml_Name)) { throw new ApplicationException(string.Format(ATTRIBUTEMANDATORY, nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name))); } | |
| 85 | + Xml_AddressPrefix = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT); | |
| 86 | + Xml_Server = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT); | |
| 87 | + if (Xml_Server == "." || Xml_Server.ToLower() == "localhost") { Xml_Server = System.Environment.MachineName; } | |
| 88 | + | |
| 89 | + Private = Xml_Name.StartsWith("private$"); ; | |
| 90 | + Xml_Mode = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT); | |
| 91 | + Xml_Label = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Label), msmqxml, Xml_Name); | |
| 92 | + Xml_Formatter = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter), msmqxml, msmqdefaults.Xml_DefaultFormatter); | |
| 93 | + Xml_Encoding = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Encoding), msmqxml, msmqdefaults.Xml_DefaultEncoding); | |
| 94 | + | |
| 95 | + foreach (var ar in msmqdefaults.Xml_AccessRights) { Xml_AccessRights.Add(ar); } | |
| 96 | + try | |
| 97 | + { | |
| 98 | + var arxmllist = GetAllXElements(msmqxml, nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.AccessRight)); | |
| 99 | + foreach (var arxml in arxmllist) { var newa = AccessRights.Factory(arxml); if (newa != null) { Xml_AccessRights.Add(newa); } } | |
| 100 | + } | |
| 101 | + catch{ } | |
| 102 | + | |
| 103 | + | |
| 104 | + } | |
| 105 | + #endregion xml constructor | |
| 106 | + | |
| 107 | + #region Xml cloner constructor | |
| 108 | + public MSMQ(MSMQ msmq) | |
| 109 | + { | |
| 110 | + Valid = msmq.Valid; | |
| 111 | + Xml_Key = msmq.Xml_Key; | |
| 112 | + Xml_Name = msmq.Xml_Name; | |
| 113 | + Xml_Server = msmq.Xml_Server; | |
| 114 | + Private = msmq.Private; | |
| 115 | + Xml_Mode = msmq.Xml_Mode; | |
| 116 | + Xml_Label = msmq.Xml_Label; | |
| 117 | + Xml_Formatter= msmq.Xml_Formatter; | |
| 118 | + Xml_Encoding = msmq.Xml_Encoding; | |
| 119 | + } | |
| 120 | + #endregion Xml cloner constructor | |
| 121 | + | |
| 122 | + #region CollectMSMQInfo | |
| 123 | + public MSMQ CollectMSMQInfo() | |
| 124 | + { | |
| 125 | + MSMQ msmqdef = this; | |
| 126 | + string msmqaddressprefix = msmqdef.Xml_AddressPrefix; | |
| 127 | + string msmqservername = msmqdef.Xml_Server; | |
| 128 | + string msmqFullname = MSMQManagerCore.CreateFullQueuePath(msmqaddressprefix, msmqservername, msmqdef.Xml_Name); | |
| 129 | + msmqdef.QueueName = msmqdef.Xml_Name; | |
| 130 | + msmqdef.MachineName = msmqservername; | |
| 131 | + msmqdef.Path = msmqFullname; | |
| 132 | + try | |
| 133 | + { | |
| 134 | + msmqdef.Status = MessageQueue.Exists(msmqFullname) ? "Installed" : "Uninstalled"; | |
| 135 | + if (msmqdef.Status == "Installed") | |
| 136 | + { | |
| 137 | + using (var msmq = new MessageQueue(msmqFullname)) | |
| 138 | + { | |
| 139 | + msmqdef.QueueName = msmq.QueueName; | |
| 140 | + msmqdef.MachineName = msmq.MachineName; | |
| 141 | + | |
| 142 | + msmqdef.Id = msmq.Id; | |
| 143 | + msmqdef.NumOfMessages = MSMQManagerCore.Count(msmq); | |
| 144 | + msmqdef.Label = msmq.Label; | |
| 145 | + msmqdef.Formatter = msmq.Formatter; | |
| 146 | + msmqdef.FormatName = msmq.FormatName; | |
| 147 | + msmqdef.Path = msmq.Path; | |
| 148 | + msmqdef.LastModifyTime = msmq.LastModifyTime; | |
| 149 | + msmqdef.AccessMode = msmq.AccessMode; | |
| 150 | + msmqdef.CanRead = msmq.CanRead; | |
| 151 | + msmqdef.CanWrite = msmq.CanWrite; | |
| 152 | + msmqdef.MaximumQueueSize = msmq.MaximumQueueSize; | |
| 153 | + msmqdef.UseJournalQueue = msmq.UseJournalQueue; | |
| 154 | + msmqdef.MaximumJournalSize = msmq.MaximumJournalSize; | |
| 155 | + | |
| 156 | + msmqdef.Transactional = msmq.Transactional; | |
| 157 | + msmqdef.Authenticate = msmq.Authenticate; | |
| 158 | + msmqdef.BasePriority = msmq.BasePriority; | |
| 159 | + msmqdef.EncryptionRequired = msmq.EncryptionRequired; | |
| 160 | + | |
| 161 | + msmqdef.Status = "Ready"; | |
| 162 | + } | |
| 163 | + } | |
| 164 | + } | |
| 165 | + catch (Exception ex) { msmqdef.Status = "Error"; msmqdef.StatusDescription = ex.Message + (ex.InnerException != null ? ("\n" + ex.InnerException.Message) : ""); } | |
| 166 | + return msmqdef; | |
| 167 | + } | |
| 168 | + #endregion CollectMSMQInfo | |
| 169 | + | |
| 170 | + public string DisplayVeryShortInfo(int lineix) | |
| 171 | + { | |
| 172 | + MSMQ msmq = this; | |
| 173 | + if (lineix == 0) | |
| 174 | + { | |
| 175 | + ColorConsole.Write($"{msmq.Xml_Name}", ConsoleColor.Black, ConsoleColor.White, prefix: "Queue '", suffix: $"' queue label: '{msmq.Xml_Label}'."); | |
| 176 | + ConsoleColor statuscolor; | |
| 177 | + if (msmq.Status == "Uninstalled") { statuscolor = ConsoleColor.Red; } | |
| 178 | + else if (msmq.Status == "Error") { statuscolor = ConsoleColor.Red; } | |
| 179 | + else if (msmq.Status == "Installed") { statuscolor = ConsoleColor.Yellow; } | |
| 180 | + else if (msmq.Status == "Ready") { statuscolor = ConsoleColor.Green; } | |
| 181 | + else { statuscolor = ConsoleColor.Red; } | |
| 182 | + ColorConsole.Write(msmq.Status, statuscolor, bracket: "[]", prefix: " ", suffix: ". "); | |
| 183 | + ColorConsole.WriteLine(); | |
| 184 | + return " "; | |
| 185 | + } | |
| 186 | + else if (lineix == 1) | |
| 187 | + { | |
| 188 | + var privatepublictext = msmq.Private ? "private" : "public"; | |
| 189 | + ColorConsole.Write($"{msmq.Xml_AddressPrefix}", ConsoleColor.Black, ConsoleColor.White, prefix: "Format:", suffix: $" Queue is { privatepublictext }."); | |
| 190 | + ColorConsole.Write($"{msmq.Xml_Server}", ConsoleColor.Black, ConsoleColor.White, prefix: "Server:", suffix: $" Queue is { privatepublictext }."); | |
| 191 | + ColorConsole.WriteLine(); | |
| 192 | + return " "; | |
| 193 | + } | |
| 194 | + return null; | |
| 195 | + } | |
| 196 | + public string DisplayShortInfo(int lineix) | |
| 197 | + { | |
| 198 | + MSMQ msmq = this; | |
| 199 | + if (lineix == 0) | |
| 200 | + { | |
| 201 | + ColorConsole.Write($"{msmq.Xml_Name}", ConsoleColor.Black, ConsoleColor.White, prefix: "Queue '", suffix: $"' queue label: '{msmq.Xml_Label}'."); | |
| 202 | + ConsoleColor statuscolor; | |
| 203 | + if (msmq.Status == "Uninstalled") { statuscolor = ConsoleColor.Red; } | |
| 204 | + else if (msmq.Status == "Error") { statuscolor = ConsoleColor.Red; } | |
| 205 | + else if (msmq.Status == "Installed") { statuscolor = ConsoleColor.Yellow; } | |
| 206 | + else if (msmq.Status == "Ready") { statuscolor = ConsoleColor.Green; } | |
| 207 | + else { statuscolor = ConsoleColor.Red; } | |
| 208 | + ColorConsole.Write(msmq.Status, statuscolor, bracket: "[]", prefix: " ", suffix: ". "); | |
| 209 | + ColorConsole.WriteLine(); | |
| 210 | + return " "; | |
| 211 | + } | |
| 212 | + else if (lineix == 1) | |
| 213 | + { | |
| 214 | + var privatepublictext = msmq.Private ? "private" : "public"; | |
| 215 | + ColorConsole.Write($"{msmq.Xml_AddressPrefix}", ConsoleColor.Black, ConsoleColor.White, prefix: "Format:", suffix: $" Queue is { privatepublictext }."); | |
| 216 | + ColorConsole.Write($"{msmq.Xml_Server}", ConsoleColor.Black, ConsoleColor.White, prefix: "Server:", suffix: $" Queue is { privatepublictext }."); | |
| 217 | + ColorConsole.WriteLine(); | |
| 218 | + return " "; | |
| 219 | + } | |
| 220 | + else if (lineix == 2) | |
| 221 | + { | |
| 222 | + ColorConsole.Write($"{msmq.Path}", ConsoleColor.Yellow, prefix: "Path ", suffix: ", "); | |
| 223 | + ColorConsole.WriteLine(); | |
| 224 | + return " "; | |
| 225 | + } | |
| 226 | + else if (lineix == 3) | |
| 227 | + { | |
| 228 | + if (msmq.StatusDescription != null) | |
| 229 | + { | |
| 230 | + ConsoleColor color = ConsoleColor.Yellow; | |
| 231 | + if (msmq.Status == "Ready") { color = ConsoleColor.Green; } | |
| 232 | + else if (msmq.Status == "Error") { color = ConsoleColor.Red; } | |
| 233 | + ColorConsole.Write($"{msmq.StatusDescription}", color, prefix: "Status description "); | |
| 234 | + ColorConsole.WriteLine(); | |
| 235 | + return " "; | |
| 236 | + } | |
| 237 | + return "";//empty=van még szöveg, de most nem történt kiírás | |
| 238 | + } | |
| 239 | + else if (lineix == 4) | |
| 240 | + { | |
| 241 | + if (msmq.Status == "Ready") | |
| 242 | + { | |
| 243 | + ColorConsole.Write($"{msmq.FormatName}", ConsoleColor.Yellow, prefix: "FormatName "); | |
| 244 | + ColorConsole.WriteLine(); | |
| 245 | + return " "; | |
| 246 | + } | |
| 247 | + return ""; | |
| 248 | + } | |
| 249 | + else if (lineix == 5) | |
| 250 | + { | |
| 251 | + if (msmq.Status == "Ready") | |
| 252 | + { | |
| 253 | + ColorConsole.Write($"{msmq.Id}", ConsoleColor.Yellow, prefix: "Id "); | |
| 254 | + ColorConsole.WriteLine(); | |
| 255 | + return " "; | |
| 256 | + } | |
| 257 | + return ""; | |
| 258 | + } | |
| 259 | + else if (lineix == 6) | |
| 260 | + { | |
| 261 | + if (msmq.Status == "Ready") | |
| 262 | + { | |
| 263 | + ColorConsole.Write(msmq.NumOfMessages.ToString(), ConsoleColor.Yellow, prefix: "Num.of msgs in queue ", suffix: ". "); | |
| 264 | + ColorConsole.Write($"{msmq.LastModifyTime}", ConsoleColor.Yellow, prefix: "LastModified ", suffix: ", "); | |
| 265 | + ColorConsole.WriteLine(); | |
| 266 | + return " "; | |
| 267 | + } | |
| 268 | + return ""; | |
| 269 | + } | |
| 270 | + else if (lineix == 7) | |
| 271 | + { | |
| 272 | + if (msmq.Status == "Ready") | |
| 273 | + { | |
| 274 | + ColorConsole.Write($"{msmq.AccessMode}", ConsoleColor.Yellow, prefix: "AccessMode ", suffix: ", "); | |
| 275 | + ColorConsole.Write($"{msmq.CanRead}", ConsoleColor.Yellow, prefix: "CanRead ", suffix: ", "); | |
| 276 | + ColorConsole.Write($"{msmq.CanWrite}", ConsoleColor.Yellow, prefix: "CanWrite ", suffix: ", "); | |
| 277 | + ColorConsole.WriteLine(); | |
| 278 | + return " "; | |
| 279 | + } | |
| 280 | + return ""; | |
| 281 | + } | |
| 282 | + return null; | |
| 283 | + } | |
| 284 | + | |
| 285 | + #region DisplayInfo | |
| 286 | + public void DisplayInfo() | |
| 287 | + { | |
| 288 | + MSMQ msmq = this; | |
| 289 | + ColorConsole.Write($">>> MSMQ detailed info collected for ", ConsoleColor.Yellow); | |
| 290 | + ColorConsole.Write($"{msmq.Xml_Name}", ConsoleColor.Yellow, suffix: ", ", prefix: " QueueName : "); | |
| 291 | + ColorConsole.Write($"{msmq.Xml_Server}", ConsoleColor.Yellow, prefix: "MachineName: "); | |
| 292 | + ColorConsole.WriteLine(); | |
| 293 | + var qqn = msmq.Xml_Name; | |
| 294 | + var qexists = MSMQManagerCore.CheckIfQueueExists(msmq.Xml_Server, qqn); | |
| 295 | + if (!qexists) | |
| 296 | + { | |
| 297 | + ColorConsole.WriteLine($" Queue does not exist!", ConsoleColor.Red); | |
| 298 | + } | |
| 299 | + else | |
| 300 | + { | |
| 301 | + try | |
| 302 | + { | |
| 303 | + msmq = msmq.CollectMSMQInfo(); | |
| 304 | + ColorConsole.WriteLine($"{msmq.QueueName}", ConsoleColor.Green, prefix: $" Queue name: "); | |
| 305 | + ColorConsole.WriteLine($"{msmq.MachineName}", ConsoleColor.Green, prefix: $" Server: "); | |
| 306 | + if (msmq.Status == "Error") | |
| 307 | + { | |
| 308 | + ColorConsole.WriteLine($"{msmq.Status}", ConsoleColor.Red, prefix: $" Status: "); | |
| 309 | + ColorConsole.WriteLine($"{msmq.StatusDescription}", ConsoleColor.Red, prefix: " StatusDescription: "); | |
| 310 | + } | |
| 311 | + else if (msmq.Status != "Ready") | |
| 312 | + { | |
| 313 | + ColorConsole.WriteLine($"{msmq.Status}", ConsoleColor.Yellow, prefix: $" Status: "); | |
| 314 | + ColorConsole.WriteLine($"{msmq.StatusDescription}", ConsoleColor.Yellow, prefix: " StatusDescription: "); | |
| 315 | + } | |
| 316 | + else | |
| 317 | + { | |
| 318 | + ColorConsole.WriteLine($"{msmq.Status}", ConsoleColor.Green, prefix: $" Status: "); | |
| 319 | + ColorConsole.WriteLine($"{msmq.StatusDescription}", ConsoleColor.Green, prefix: " StatusDescription: "); | |
| 320 | + ColorConsole.WriteLine($"{msmq.Id}", ConsoleColor.Green, prefix: " Id: "); | |
| 321 | + ColorConsole.WriteLine($"{msmq.Label}", ConsoleColor.Green, prefix: " Label: "); | |
| 322 | + ColorConsole.WriteLine($"{msmq.Path}", ConsoleColor.Green, prefix: " Path: "); | |
| 323 | + ColorConsole.WriteLine($"{msmq.FormatName}", ConsoleColor.Green, prefix: " FormatName: "); | |
| 324 | + ColorConsole.Write($"{msmq.Transactional}", ConsoleColor.Green, prefix: " Transactional: ", suffix: ", "); | |
| 325 | + ColorConsole.Write($"{msmq.UseJournalQueue}", ConsoleColor.Green, suffix: ", ", prefix: "UseJournalQueue: "); | |
| 326 | + ColorConsole.Write($"{msmq.AccessMode}", ConsoleColor.Green, suffix: ", ", prefix: "AccessMode: "); | |
| 327 | + ColorConsole.Write($"{msmq.CanRead}", ConsoleColor.Green, suffix: ", ", prefix: "CanRead: "); | |
| 328 | + ColorConsole.Write($"{msmq.CanWrite}", ConsoleColor.Green, suffix: ", ", prefix: "CanWrite: "); | |
| 329 | + ColorConsole.WriteLine(); | |
| 330 | + ColorConsole.Write($"{msmq.Authenticate}", ConsoleColor.Green, suffix: ", ", prefix: " Authenticate: "); | |
| 331 | + ColorConsole.Write($"{msmq.BasePriority}", ConsoleColor.Green, suffix: ", ", prefix: "BasePriority: "); | |
| 332 | + ColorConsole.Write($"{msmq.EncryptionRequired}", ConsoleColor.Green, suffix: ", ", prefix: "EncryptionRequired: "); | |
| 333 | + ColorConsole.WriteLine(); | |
| 334 | + ColorConsole.Write($"{msmq.Formatter}", ConsoleColor.Green, suffix: ", ", prefix: " Formatter: "); | |
| 335 | + ColorConsole.Write($"{msmq.LastModifyTime}", ConsoleColor.Green, suffix: ", ", prefix: "LastModifyTime: "); | |
| 336 | + ColorConsole.WriteLine(); | |
| 337 | + ColorConsole.Write($"{msmq.NumOfMessages}", ConsoleColor.Green, suffix: ", ", prefix: " NumOfMessages: "); | |
| 338 | + ColorConsole.Write($"{msmq.MaximumJournalSize}", ConsoleColor.Green, suffix: ", ", prefix: "MaximumJournalSize: "); | |
| 339 | + ColorConsole.Write($"{msmq.MaximumQueueSize}", ConsoleColor.Green, suffix: ", ", prefix: "MaximumQueueSize: "); | |
| 340 | + ColorConsole.WriteLine(); | |
| 341 | + } | |
| 342 | + } | |
| 343 | + catch (Exception ex) { ColorConsole.WriteLine(" " + ex.Message, ConsoleColor.Red); } | |
| 344 | + } | |
| 345 | + } | |
| 346 | + #endregion DisplayInfo | |
| 347 | + | |
| 348 | + #region XmlStructure | |
| 349 | + public static class XmlStructure | |
| 350 | + { | |
| 351 | + public static class MSMQManager | |
| 352 | + { | |
| 353 | + public static class General | |
| 354 | + { | |
| 355 | + public static class AccessRights | |
| 356 | + { | |
| 357 | + public static class AccessRight | |
| 358 | + { | |
| 359 | + public static class Attributes | |
| 360 | + { | |
| 361 | + public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } | |
| 362 | + public static class Right {public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } | |
| 363 | + public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } | |
| 364 | + } | |
| 365 | + } | |
| 366 | + } | |
| 367 | + public static class MessageFiles | |
| 368 | + { | |
| 369 | + public static class Attributes | |
| 370 | + { | |
| 371 | + public static class Directory { public static class Values { public const string DEFAULT = ""; } } | |
| 372 | + public static class SendToMask { public static class Values { public const string DEFAULT = "*.*"; } } | |
| 373 | + public static class ReadToMask { public static class Values { public const string DEFAULT = "*.*"; } } | |
| 374 | + } | |
| 375 | + } | |
| 376 | + public static class DefaultFormatter { public static class Values { public const string DEFAULT = nameof(ActiveXMessageFormatter); } } | |
| 377 | + public static class DefaultEncoding { public static class Values { public const string DEFAULT = nameof(System.Text.Encoding.UTF8); } } | |
| 378 | + } | |
| 379 | + | |
| 380 | + public static class MessageQueues | |
| 381 | + { | |
| 382 | + public static class MessageQueue | |
| 383 | + { | |
| 384 | + public static class Attributes | |
| 385 | + { | |
| 386 | + public static class Key { public static class Values { public const string DEFAULT = ""; } } | |
| 387 | + public static class AddressPrefix{ public static class Values { public const string DEFAULT = ""; } } | |
| 388 | + public static class Server { public static class Values { public const string DEFAULT = "."; } } | |
| 389 | + public static class Name { } | |
| 390 | + public static class Label { } | |
| 391 | + public static class Mode | |
| 392 | + { | |
| 393 | + public static class Values | |
| 394 | + { | |
| 395 | + public const string DEFAULT = "In"; | |
| 396 | + public static class In { } | |
| 397 | + public static class Out { } | |
| 398 | + } | |
| 399 | + } | |
| 400 | + public static class Formatter | |
| 401 | + { | |
| 402 | + public static class Values | |
| 403 | + { | |
| 404 | + public static class ActiveXMessageFormatter { } | |
| 405 | + public static class BinaryMessageFormatter { } | |
| 406 | + public static class XmlMessageFormatter { } | |
| 407 | + } | |
| 408 | + } | |
| 409 | + public static class Encoding { } | |
| 410 | + } | |
| 411 | + public static class AccessRight | |
| 412 | + { | |
| 413 | + public static class Attributes | |
| 414 | + { | |
| 415 | + public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } | |
| 416 | + public static class Right { public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } | |
| 417 | + public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } | |
| 418 | + } | |
| 419 | + } | |
| 420 | + } | |
| 421 | + } | |
| 422 | + } | |
| 423 | + } | |
| 424 | + #endregion XmlStructure | |
| 425 | + } | |
| 426 | +} | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs
| ... | ... | @@ -37,7 +37,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 37 | 37 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Remove.KEY, "Remove MSMQ", Remove, ep)) |
| 38 | 38 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.SetPermissions.KEY, "Set MSMQ permisssions", SetPermissions, ep)) |
| 39 | 39 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.SetDefaultPermissions.KEY, "Set default MSMQ permisssions", SetDefaultPermissions, ep)) |
| 40 | - .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.GetInfo.KEY, "Get MSMQ information", GetInfo, ep)) | |
| 40 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.GetLocalInfo.KEY, "Get local MSMQ information", GetLocalInfo, ep)) | |
| 41 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.GetRemoteInfo.KEY, "Get remoteMSMQ information", GetRemoteInfo, ep)) | |
| 41 | 42 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Peek.KEY, "Peek MSMQ message", Peek, ep)) |
| 42 | 43 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Read.KEY, "Read MSMQ message", Read, ep)) |
| 43 | 44 | .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Send.KEY, "Send MSMQ message", Send, ep)) |
| ... | ... | @@ -57,7 +58,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 57 | 58 | |
| 58 | 59 | var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); |
| 59 | 60 | |
| 60 | - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Create)}'!", silent: true); | |
| 61 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Create)}'!", silent: true); | |
| 61 | 62 | |
| 62 | 63 | Menu.Selection sr = menufolders.Select(selectedtaskindexes); |
| 63 | 64 | if (sr.Result == Menu.SelectionResult.Exit) { return o; } |
| ... | ... | @@ -70,7 +71,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 70 | 71 | MSMQ st = p.Parameters as MSMQ; |
| 71 | 72 | try |
| 72 | 73 | { |
| 73 | - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
| 74 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); | |
| 74 | 75 | MSMQManagerCore.CreateQueue(fullpath, st.Xml_Label); |
| 75 | 76 | ColorConsole.WriteLine($"MSMQ:{st.Xml_Name} created.", ConsoleColor.Green); |
| 76 | 77 | foreach (var a in st.Xml_AccessRights) |
| ... | ... | @@ -96,7 +97,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 96 | 97 | |
| 97 | 98 | var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); |
| 98 | 99 | |
| 99 | - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Remove)}'!", silent: true); | |
| 100 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Remove)}'!", silent: true); | |
| 100 | 101 | |
| 101 | 102 | Menu.Selection sr = menufolders.Select(selectedtaskindexes); |
| 102 | 103 | if (sr.Result == Menu.SelectionResult.Exit) { return o; } |
| ... | ... | @@ -109,7 +110,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 109 | 110 | MSMQ st = p.Parameters as MSMQ; |
| 110 | 111 | try |
| 111 | 112 | { |
| 112 | - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
| 113 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); | |
| 113 | 114 | MSMQManagerCore.DeleteQueue(fullpath); |
| 114 | 115 | ColorConsole.WriteLine($"MSMQ:{st.Xml_Name} removed.", ConsoleColor.Green); |
| 115 | 116 | } |
| ... | ... | @@ -124,7 +125,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 124 | 125 | |
| 125 | 126 | var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); |
| 126 | 127 | |
| 127 | - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(SetDefaultPermissions)}'!", silent: true) | |
| 128 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(SetDefaultPermissions)}'!", silent: true) | |
| 128 | 129 | .SetSelectionMode(Menu.SelectionMode.Multi); |
| 129 | 130 | |
| 130 | 131 | Menu.Selection sr = menufolders.Select(selectedtaskindexes); |
| ... | ... | @@ -141,7 +142,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 141 | 142 | { |
| 142 | 143 | foreach (var a in st.Xml_AccessRights) |
| 143 | 144 | { |
| 144 | - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
| 145 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); | |
| 145 | 146 | MSMQManagerCore.SetPermissions(fullpath, a.un, a.ar, a.ac); |
| 146 | 147 | string ctrlstring = |
| 147 | 148 | a.ac == AccessControlEntryType.Allow ? "allowed" |
| ... | ... | @@ -163,7 +164,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 163 | 164 | |
| 164 | 165 | var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); |
| 165 | 166 | |
| 166 | - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(SetPermissions)}'!", silent: true) | |
| 167 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(SetPermissions)}'!", silent: true) | |
| 167 | 168 | .SetSelectionMode(Menu.SelectionMode.Multi); |
| 168 | 169 | |
| 169 | 170 | Menu.Selection sr = menufolders.Select(selectedtaskindexes); |
| ... | ... | @@ -195,7 +196,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 195 | 196 | MSMQ st = p.Parameters as MSMQ; |
| 196 | 197 | try |
| 197 | 198 | { |
| 198 | - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
| 199 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); | |
| 199 | 200 | MSMQManagerCore.SetPermissions(fullpath, username, accessrights, controltype); |
| 200 | 201 | ColorConsole.WriteLine($"Permissions set for MSMQ:{st.Xml_Name}. Username:{username}, access right: {accessrights}, control type: {controltype}", ConsoleColor.Green); |
| 201 | 202 | } |
| ... | ... | @@ -208,14 +209,67 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 208 | 209 | } |
| 209 | 210 | return o; |
| 210 | 211 | } |
| 211 | - private static object GetInfo(object parameter, object o) | |
| 212 | + private static object GetRemoteInfo(object parameter, object o) | |
| 212 | 213 | { |
| 213 | 214 | var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); |
| 214 | 215 | var args = (parameter as Menu.ExecutorParameter).Args; |
| 215 | 216 | |
| 216 | 217 | var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); |
| 217 | 218 | |
| 218 | - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(GetInfo)}'!", silent: true) | |
| 219 | + string sndefault = null; | |
| 220 | + string sn; | |
| 221 | + while (true) | |
| 222 | + { | |
| 223 | + sn = ColorConsole.ReadLine("Enter server ip/name to get queue info from (enter . for localhost)",defaultvalue:sndefault); | |
| 224 | + if (sn.ToLower() == "ex") { return o; } | |
| 225 | + sndefault = sn; | |
| 226 | + | |
| 227 | + List<System.Messaging.MessageQueue> queuearray = new List<System.Messaging.MessageQueue>(); | |
| 228 | + queuearray = System.Messaging.MessageQueue.GetPrivateQueuesByMachine(sn).ToList(); | |
| 229 | + | |
| 230 | + 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) | |
| 231 | + .SetSelectionMode(Menu.SelectionMode.Multi); | |
| 232 | + | |
| 233 | + Menu.Selection sr = menumsmqs.Select(); | |
| 234 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
| 235 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
| 236 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
| 237 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
| 238 | + else { } | |
| 239 | + var ix = 1; | |
| 240 | + foreach (var p in sr.SelectedParameterList) | |
| 241 | + { | |
| 242 | + var msmq = p.Parameters as MSMQ; | |
| 243 | + msmq.DisplayInfo(); ix++; | |
| 244 | + var sp = SendParameters.Get(msmq.Xml_Encoding, msmq.Xml_Formatter); | |
| 245 | + if (sp != null) | |
| 246 | + { | |
| 247 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(msmq.Xml_AddressPrefix, msmq.Xml_Server, msmq.Xml_Name); | |
| 248 | + MSMQManagerCore.Send(fullpath, sp.messagebody, sp.messagelabel, sp.messageformatter, sp.encoding); | |
| 249 | + ColorConsole.WriteLine($"Sending to '{fullpath}' ....", ConsoleColor.Yellow); | |
| 250 | + MSMQManagerCore.ReadLast(fullpath, sp.messageformatter, sp.encoding, out string body, out string label); | |
| 251 | + if (sp.messagebody == body && sp.messagelabel == label) { ColorConsole.WriteLine($"Message successfully sent to '{fullpath}' and read back!", ConsoleColor.Green); } | |
| 252 | + else | |
| 253 | + { | |
| 254 | + ColorConsole.WriteLine(body, prefix: "Read back body: ", f: ConsoleColor.Red); | |
| 255 | + ColorConsole.WriteLine(label, prefix: "Read back label: ", f: ConsoleColor.Red); | |
| 256 | + ColorConsole.WriteLine($"Message sending or read back is failed to '{fullpath}' !", ConsoleColor.Red); | |
| 257 | + } | |
| 258 | + } | |
| 259 | + } | |
| 260 | + } | |
| 261 | + | |
| 262 | + return o; | |
| 263 | + } | |
| 264 | + | |
| 265 | + private static object GetLocalInfo(object parameter, object o) | |
| 266 | + { | |
| 267 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
| 268 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
| 269 | + | |
| 270 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
| 271 | + | |
| 272 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(GetLocalInfo)}'!", silent: true) | |
| 219 | 273 | .SetSelectionMode(Menu.SelectionMode.Multi); |
| 220 | 274 | |
| 221 | 275 | Menu.Selection sr = menufolders.Select(selectedtaskindexes); |
| ... | ... | @@ -226,51 +280,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 226 | 280 | else { } |
| 227 | 281 | foreach (var p in sr.SelectedParameterList) |
| 228 | 282 | { |
| 229 | - MSMQ st = p.Parameters as MSMQ; | |
| 230 | - ColorConsole.Write($">>> MSMQ detailed info collected for ", ConsoleColor.Yellow); | |
| 231 | - ColorConsole.Write($"{st.QueueName}", ConsoleColor.Yellow,suffix:", ",prefix: " QueueName : "); | |
| 232 | - ColorConsole.Write($"{st.MachineName}", ConsoleColor.Yellow,prefix: "MachineName: "); | |
| 233 | - ColorConsole.WriteLine(); | |
| 234 | - var qqn = MSMQManagerCore.CreateQualifiedQueueName(st.Xml_AddressPrefix, st.Xml_Server,st.Xml_Private, st.Xml_Name); | |
| 235 | - var qexists = MSMQManagerCore.CheckIfQueueExists(st.Xml_Server, qqn); | |
| 236 | - if (!qexists) | |
| 237 | - { | |
| 238 | - ColorConsole.WriteLine($" Queue does not exist!", ConsoleColor.Red); | |
| 239 | - } | |
| 240 | - else | |
| 241 | - { | |
| 242 | - try | |
| 243 | - { | |
| 244 | - st = MSMQManagerCore.CollectMSMQInfo(st); | |
| 245 | - ColorConsole.WriteLine($"{st.Status}", ConsoleColor.Green,prefix: $" Status: "); | |
| 246 | - ColorConsole.WriteLine($"{st.StatusDescription}", ConsoleColor.Green,prefix:" StatusDescription: "); | |
| 247 | - ColorConsole.WriteLine($"{st.Id}", ConsoleColor.Green,prefix: " Id: "); | |
| 248 | - ColorConsole.WriteLine($"{st.Label}", ConsoleColor.Green,prefix: " Label: "); | |
| 249 | - ColorConsole.WriteLine($"{st.Path}", ConsoleColor.Green,prefix: " Path: "); | |
| 250 | - ColorConsole.WriteLine($"{st.FormatName}", ConsoleColor.Green,prefix: " FormatName: "); | |
| 251 | - ColorConsole.Write($"{st.Transactional}", ConsoleColor.Green, prefix: " Transactional: ",suffix: ", "); | |
| 252 | - ColorConsole.Write($"{st.UseJournalQueue}", ConsoleColor.Green, suffix: ", ",prefix: "UseJournalQueue: "); | |
| 253 | - ColorConsole.Write($"{st.AccessMode}", ConsoleColor.Green,suffix:", ",prefix: "AccessMode: "); | |
| 254 | - ColorConsole.Write($"{st.CanRead}", ConsoleColor.Green, suffix: ", ",prefix: "CanRead: "); | |
| 255 | - ColorConsole.Write($"{st.CanWrite}", ConsoleColor.Green, suffix: ", ",prefix: "CanWrite: "); | |
| 256 | - ColorConsole.WriteLine(); | |
| 257 | - ColorConsole.Write($"{st.Authenticate}", ConsoleColor.Green, suffix: ", ",prefix: " Authenticate: "); | |
| 258 | - ColorConsole.Write($"{st.BasePriority}", ConsoleColor.Green, suffix: ", ",prefix: "BasePriority: "); | |
| 259 | - ColorConsole.Write($"{st.EncryptionRequired}", ConsoleColor.Green, suffix: ", ",prefix: "EncryptionRequired: "); | |
| 260 | - ColorConsole.WriteLine(); | |
| 261 | - ColorConsole.Write($"{st.Formatter}", ConsoleColor.Green, suffix: ", ",prefix: " Formatter: "); | |
| 262 | - ColorConsole.Write($"{st.LastModifyTime}", ConsoleColor.Green, suffix: ", ",prefix: "LastModifyTime: "); | |
| 263 | - ColorConsole.WriteLine(); | |
| 264 | - ColorConsole.Write($"{st.NumOfMessages}", ConsoleColor.Green, suffix: ", ",prefix: " NumOfMessages: "); | |
| 265 | - ColorConsole.Write($"{st.MaximumJournalSize}", ConsoleColor.Green, suffix: ", ",prefix: "MaximumJournalSize: "); | |
| 266 | - ColorConsole.Write($"{st.MaximumQueueSize}", ConsoleColor.Green, suffix: ", ",prefix: "MaximumQueueSize: "); | |
| 267 | - ColorConsole.WriteLine(); | |
| 268 | - } | |
| 269 | - catch (Exception ex) { ColorConsole.WriteLine(" "+ex.Message, ConsoleColor.Red); } | |
| 270 | - } | |
| 283 | + MSMQ msmq = p.Parameters as MSMQ; | |
| 284 | + msmq.DisplayInfo(); | |
| 271 | 285 | } |
| 272 | 286 | return o; |
| 273 | 287 | } |
| 288 | + | |
| 274 | 289 | private static object Peek(object parameter, object o) |
| 275 | 290 | { |
| 276 | 291 | var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); |
| ... | ... | @@ -278,7 +293,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 278 | 293 | |
| 279 | 294 | var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); |
| 280 | 295 | |
| 281 | - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Peek)}'!", silent: true) | |
| 296 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Peek)}'!", silent: true) | |
| 282 | 297 | .SetSelectionMode(Menu.SelectionMode.Single); |
| 283 | 298 | |
| 284 | 299 | Menu.Selection sr = menufolders.Select(selectedtaskindexes); |
| ... | ... | @@ -292,7 +307,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 292 | 307 | MSMQ st = p.Parameters as MSMQ; |
| 293 | 308 | try |
| 294 | 309 | { |
| 295 | - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
| 310 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); | |
| 296 | 311 | MSMQManagerCore.Peek(fullpath, out string msgbody, out string msglabel); |
| 297 | 312 | ColorConsole.WriteLine($"Message peeked from MSMQ:{st.Xml_Name}", ConsoleColor.Green); |
| 298 | 313 | ColorConsole.WriteLine($" Body: {msgbody}", ConsoleColor.Yellow); |
| ... | ... | @@ -312,7 +327,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 312 | 327 | |
| 313 | 328 | var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); |
| 314 | 329 | |
| 315 | - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Read)}'!", silent: true) | |
| 330 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Read)}'!", silent: true) | |
| 316 | 331 | .SetSelectionMode(Menu.SelectionMode.Single); |
| 317 | 332 | |
| 318 | 333 | Menu.Selection sr = menufolders.Select(selectedtaskindexes); |
| ... | ... | @@ -328,7 +343,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 328 | 343 | { |
| 329 | 344 | var messageformatter = new ActiveXMessageFormatter(); |
| 330 | 345 | var encoding = Encoding.UTF8; |
| 331 | - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
| 346 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); | |
| 332 | 347 | MSMQManagerCore.Read(fullpath, messageformatter, encoding, out string msgbody, out string msglabel); |
| 333 | 348 | ColorConsole.WriteLine($"Message read from MSMQ:{st.Xml_Name}", ConsoleColor.Green); |
| 334 | 349 | ColorConsole.WriteLine($" Body: {msgbody}", ConsoleColor.Yellow); |
| ... | ... | @@ -348,7 +363,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 348 | 363 | |
| 349 | 364 | var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); |
| 350 | 365 | |
| 351 | - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Send)}'!", silent: true) | |
| 366 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Send)}'!", silent: true) | |
| 352 | 367 | .SetSelectionMode(Menu.SelectionMode.Single); |
| 353 | 368 | |
| 354 | 369 | Menu.Selection sr = menufolders.Select(selectedtaskindexes); |
| ... | ... | @@ -364,25 +379,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 364 | 379 | { |
| 365 | 380 | try |
| 366 | 381 | { |
| 367 | - var now = DateTime.Now.ToString(); | |
| 368 | - string messagebody = ColorConsole.ReadLine("Enter message body:", ConsoleColor.Yellow, defaultvalue: "TEST MESSAGE " + now); | |
| 369 | - if (messagebody.ToUpper() == "EX") { break; } | |
| 382 | + var sp = SendParameters.Get(st.Xml_Encoding, st.Xml_Formatter); | |
| 383 | + if (sp == null) { break; } | |
| 370 | 384 | |
| 371 | - string messagelabel = ColorConsole.ReadLine("Enter message label:", ConsoleColor.Yellow, defaultvalue: "TESTLABEL" + now); | |
| 372 | - if (messagelabel.ToUpper() == "EX") { break; } | |
| 373 | - | |
| 374 | - string messageformatterstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetFormatterNames(), defaultvalue: st.Xml_Formatter); | |
| 375 | - if (messageformatterstring.ToUpper() == "EX") { break; } | |
| 376 | - var messageformatter = MSMQManagerCore.SetFormatter(messageformatterstring); | |
| 377 | - if (messageformatter == null) { var exmsg = $"Message formatter value is incorrect! Value:{st.Xml_Formatter}."; throw new ApplicationException(exmsg); } | |
| 378 | - | |
| 379 | - string encodingstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetEncodingNames(), defaultvalue: st.Xml_Encoding); | |
| 380 | - if (encodingstring.ToUpper() == "EX") { break; } | |
| 381 | - var encoding = MSMQManagerCore.SetEncoding(encodingstring); | |
| 382 | - if (encoding == null) { var exmsg = $"Message encoder value is incorrect! Value:{st.Xml_Encoding}."; throw new ApplicationException(exmsg); } | |
| 383 | - | |
| 384 | - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
| 385 | - MSMQManagerCore.Send(fullpath, messagebody, messagelabel, messageformatter, encoding); | |
| 385 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); | |
| 386 | + MSMQManagerCore.Send(fullpath,sp.messagebody, sp.messagelabel, sp.messageformatter, sp.encoding); | |
| 386 | 387 | ColorConsole.WriteLine($"Message sent to MSMQ:{st.Xml_Name}.", ConsoleColor.Green); |
| 387 | 388 | } |
| 388 | 389 | catch (ApplicationException ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } |
| ... | ... | @@ -391,6 +392,59 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 391 | 392 | } |
| 392 | 393 | return o; |
| 393 | 394 | } |
| 395 | + private class ReadParameters | |
| 396 | + { | |
| 397 | + public IMessageFormatter messageformatter; | |
| 398 | + public Encoding encoding; | |
| 399 | + public static ReadParameters Get(string defaultencoding, string defaultformatter) | |
| 400 | + { | |
| 401 | + ColorConsole.WriteLine("Enter msmq read parameters!", ConsoleColor.Yellow); | |
| 402 | + var rp = new ReadParameters() { }; | |
| 403 | + | |
| 404 | + var messageformatterstring = ColorConsole.ReadLine("Enter formatter:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetFormatterNames(), defaultvalue: defaultformatter); | |
| 405 | + if (messageformatterstring.ToUpper() == "EX") { return null; } | |
| 406 | + rp.messageformatter = MSMQManagerCore.SetFormatter(messageformatterstring); | |
| 407 | + if (rp.messageformatter == null) { var exmsg = $"Message formatter value is incorrect! Value:{messageformatterstring }."; throw new ApplicationException(exmsg); } | |
| 408 | + | |
| 409 | + string encodingstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetEncodingNames(), defaultvalue: defaultencoding); | |
| 410 | + if (encodingstring.ToUpper() == "EX") { return null; } | |
| 411 | + rp.encoding = MSMQManagerCore.SetEncoding(encodingstring); | |
| 412 | + if (rp.encoding == null) { var exmsg = $"Message encoder value is incorrect! Value:{encodingstring}."; throw new ApplicationException(exmsg); } | |
| 413 | + | |
| 414 | + return rp; | |
| 415 | + } | |
| 416 | + } | |
| 417 | + private class SendParameters | |
| 418 | + { | |
| 419 | + public string messagebody; | |
| 420 | + public string messagelabel; | |
| 421 | + public IMessageFormatter messageformatter; | |
| 422 | + public Encoding encoding; | |
| 423 | + public SendParameters() { } | |
| 424 | + public static SendParameters Get(string defaultencoding, string defaultformatter) | |
| 425 | + { | |
| 426 | + ColorConsole.WriteLine("Enter test message data!",ConsoleColor.Yellow); | |
| 427 | + var sp = new SendParameters() { }; | |
| 428 | + var now = DateTime.Now.ToString(); | |
| 429 | + sp.messagebody = ColorConsole.ReadLine("Enter message body:", ConsoleColor.Yellow, defaultvalue: "TEST MESSAGE " + now); | |
| 430 | + if (sp.messagebody.ToUpper() == "EX") { return null; } | |
| 431 | + | |
| 432 | + sp.messagelabel = ColorConsole.ReadLine("Enter message label:", ConsoleColor.Yellow, defaultvalue: "TESTLABEL" + now); | |
| 433 | + if (sp.messagelabel.ToUpper() == "EX") { return null; } | |
| 434 | + | |
| 435 | + var messageformatterstring = ColorConsole.ReadLine("Enter formatter:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetFormatterNames(), defaultvalue: defaultformatter); | |
| 436 | + if (messageformatterstring.ToUpper() == "EX") { return null; } | |
| 437 | + sp.messageformatter = MSMQManagerCore.SetFormatter(messageformatterstring); | |
| 438 | + if (sp.messageformatter == null) { var exmsg = $"Message formatter value is incorrect! Value:{messageformatterstring }."; throw new ApplicationException(exmsg); } | |
| 439 | + | |
| 440 | + string encodingstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetEncodingNames(), defaultvalue: defaultencoding); | |
| 441 | + if (encodingstring.ToUpper() == "EX") { return null; } | |
| 442 | + sp.encoding = MSMQManagerCore.SetEncoding(encodingstring); | |
| 443 | + if (sp.encoding == null) { var exmsg = $"Message encoder value is incorrect! Value:{encodingstring}."; throw new ApplicationException(exmsg); } | |
| 444 | + | |
| 445 | + return sp; | |
| 446 | + } | |
| 447 | + } | |
| 394 | 448 | private static object Purge(object parameter, object o) |
| 395 | 449 | { |
| 396 | 450 | var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); |
| ... | ... | @@ -398,7 +452,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 398 | 452 | |
| 399 | 453 | var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); |
| 400 | 454 | |
| 401 | - var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Purge)}'!", silent: true); | |
| 455 | + var menufolders = DisplayMSMQMenuFromXml(config, $"Select the MSMQ(s) to manage with function '{nameof(Purge)}'!", silent: true); | |
| 402 | 456 | |
| 403 | 457 | Menu.Selection sr = menufolders.Select(selectedtaskindexes); |
| 404 | 458 | if (sr.Result == Menu.SelectionResult.Exit) { return o; } |
| ... | ... | @@ -411,7 +465,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 411 | 465 | MSMQ st = p.Parameters as MSMQ; |
| 412 | 466 | try |
| 413 | 467 | { |
| 414 | - var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
| 468 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Name); | |
| 415 | 469 | MSMQManagerCore.Purge(fullpath); |
| 416 | 470 | ColorConsole.WriteLine($"MSMQ messages purged. Name:{st.Xml_Name}", ConsoleColor.Green); |
| 417 | 471 | } |
| ... | ... | @@ -423,19 +477,23 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 423 | 477 | |
| 424 | 478 | #region private methods |
| 425 | 479 | #region private DisplayTasks |
| 426 | - private static void MSMQListDisplayer() { DisplayMSMQMenu(); } | |
| 427 | - private static Menu DisplayMSMQMenu(MSMQManagerXmlProcessor config = null, string prompt = null, bool silent = false) | |
| 480 | + private static void MSMQListDisplayer() { DisplayMSMQMenuFromXml(); } | |
| 481 | + private static Menu DisplayMSMQMenuFromXml(MSMQManagerXmlProcessor config = null, string prompt = null, bool silent = false) | |
| 428 | 482 | { |
| 429 | 483 | if (config == null) { config = new MSMQManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); } |
| 430 | 484 | List<MSMQ> msmqdefList = config.GetDefinitionList(); |
| 431 | - var menufct = new Menu("Scheduled tasks", prompt) | |
| 432 | - .SetMenuItemDisplayer(DisplayMSMQInfo) | |
| 485 | + return DisplayMSMQMenu(msmqdefList, prompt,silent,DisplayMSMQInfo); | |
| 486 | + } | |
| 487 | + private static Menu DisplayMSMQMenu(List<MSMQ> msmqlist = null, string prompt = null, bool silent = false,Menu.MenuItemDisplayerFunc midf=null) | |
| 488 | + { | |
| 489 | + List<MSMQ> msmqdefList = msmqlist; | |
| 490 | + var menufct = new Menu("MSMQ list", prompt) | |
| 491 | + .SetMenuItemDisplayer(midf) | |
| 433 | 492 | .SetSelectionMode(Menu.SelectionMode.Multi); |
| 434 | 493 | menufct.ClearMenuItemList(); |
| 435 | 494 | foreach (var msmqdef in msmqdefList) |
| 436 | 495 | { |
| 437 | - var st = MSMQManagerCore.CollectMSMQInfo(msmqdef); | |
| 438 | - menufct.AddMenuItem(new Menu.Item(msmqdef.Xml_Key, null, null, new Menu.ExecutorParameter(pars: st))); | |
| 496 | + menufct.AddMenuItem(new Menu.Item(msmqdef.Xml_Key, null, null, new Menu.ExecutorParameter(pars: msmqdef.CollectMSMQInfo()))); | |
| 439 | 497 | } |
| 440 | 498 | if (!silent) { menufct.DisplayItems(1); } |
| 441 | 499 | return menufct; |
| ... | ... | @@ -445,79 +503,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 445 | 503 | private static object DisplayMSMQInfo(object obj, int lineix) |
| 446 | 504 | { |
| 447 | 505 | MSMQ st = (obj as Menu.ExecutorParameter).Parameters as MSMQ; |
| 448 | - if (lineix == 0) | |
| 449 | - { | |
| 450 | - ColorConsole.Write($"{st.Xml_Name}", ConsoleColor.Black, ConsoleColor.White,prefix: "Queue '",suffix: $"' queue label: '{st.Xml_Label}'."); | |
| 451 | - ConsoleColor statuscolor; | |
| 452 | - if (st.Status == "Uninstalled") { statuscolor = ConsoleColor.Red; } | |
| 453 | - else if (st.Status == "Error") { statuscolor = ConsoleColor.Red; } | |
| 454 | - else if (st.Status == "Installed") { statuscolor = ConsoleColor.Yellow; } | |
| 455 | - else if (st.Status == "Ready") { statuscolor = ConsoleColor.Green; } | |
| 456 | - else { statuscolor = ConsoleColor.Red; } | |
| 457 | - ColorConsole.Write(st.Status, statuscolor, bracket: "[]", prefix: " ", suffix: ". "); | |
| 458 | - ColorConsole.WriteLine(); | |
| 459 | - return " "; | |
| 460 | - } | |
| 461 | - else if (lineix == 1) | |
| 462 | - { | |
| 463 | - var privatepublictext = st.Xml_Private ? "private" : "public"; | |
| 464 | - ColorConsole.Write($"{st.Xml_AddressPrefix}{st.Xml_Server}", ConsoleColor.Black, ConsoleColor.White, prefix: "Server:", suffix: $"Queue is { privatepublictext }."); | |
| 465 | - ColorConsole.WriteLine(); | |
| 466 | - return " "; | |
| 467 | - } | |
| 468 | - else if (lineix == 2) | |
| 469 | - { | |
| 470 | - ColorConsole.Write($"{st.Path}", ConsoleColor.Yellow, prefix: "Path ", suffix: ", "); | |
| 471 | - ColorConsole.WriteLine(); | |
| 472 | - return " "; | |
| 473 | - } | |
| 474 | - else if (lineix == 3) | |
| 475 | - { | |
| 476 | - if (st.StatusDescription != null) | |
| 477 | - { | |
| 478 | - ConsoleColor color = ConsoleColor.Yellow; | |
| 479 | - if (st.Status == "Ready") { color = ConsoleColor.Green; } | |
| 480 | - else if (st.Status == "Error") { color = ConsoleColor.Red; } | |
| 481 | - ColorConsole.Write($"{st.StatusDescription}", color, prefix: "Status description "); | |
| 482 | - ColorConsole.WriteLine(); | |
| 483 | - return " "; | |
| 484 | - } | |
| 485 | - return "";//empty=van még szöveg, de most nem történt kiírás | |
| 486 | - } | |
| 487 | - else if (lineix == 4) | |
| 488 | - { | |
| 489 | - if (st.Status == "Ready") | |
| 490 | - { | |
| 491 | - ColorConsole.Write($"{st.FormatName}", ConsoleColor.Yellow, prefix: "FormatName "); | |
| 492 | - ColorConsole.WriteLine(); | |
| 493 | - return " "; | |
| 494 | - } | |
| 495 | - return ""; | |
| 496 | - } | |
| 497 | - else if (lineix == 5) | |
| 498 | - { | |
| 499 | - if (st.Status == "Ready") | |
| 500 | - { | |
| 501 | - ColorConsole.Write(st.NumOfMessages.ToString(), ConsoleColor.Yellow, prefix: "Num.of msgs in queue ", suffix: ". "); | |
| 502 | - ColorConsole.Write($"{st.LastModifyTime}", ConsoleColor.Yellow, prefix: "LastModified ", suffix: ", "); | |
| 503 | - ColorConsole.WriteLine(); | |
| 504 | - return " "; | |
| 505 | - } | |
| 506 | - return ""; | |
| 507 | - } | |
| 508 | - else if (lineix == 6) | |
| 509 | - { | |
| 510 | - if (st.Status == "Ready") | |
| 511 | - { | |
| 512 | - ColorConsole.Write($"{st.AccessMode}", ConsoleColor.Yellow, prefix: "AccessMode ", suffix: ", "); | |
| 513 | - ColorConsole.Write($"{st.CanRead}", ConsoleColor.Yellow, prefix: "CanRead ", suffix: ", "); | |
| 514 | - ColorConsole.Write($"{st.CanWrite}", ConsoleColor.Yellow, prefix: "CanWrite ", suffix: ", "); | |
| 515 | - ColorConsole.WriteLine(); | |
| 516 | - return " "; | |
| 517 | - } | |
| 518 | - return ""; | |
| 519 | - } | |
| 520 | - return null; | |
| 506 | + return st.DisplayShortInfo(lineix); | |
| 507 | + } | |
| 508 | + private static object DisplayMSMQShortInfo(object obj, int lineix) | |
| 509 | + { | |
| 510 | + MSMQ st = (obj as Menu.ExecutorParameter).Parameters as MSMQ; | |
| 511 | + return st.DisplayVeryShortInfo(lineix); | |
| 521 | 512 | } |
| 522 | 513 | #endregion private method: DisplayTaskInfo |
| 523 | 514 | #endregion private methods |
| ... | ... | @@ -527,24 +518,17 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 527 | 518 | #region MSMQManagerCore class |
| 528 | 519 | internal static class MSMQManagerCore |
| 529 | 520 | { |
| 530 | - public static string CreateFullQueuePath(string addressprefix, string msmqservername, bool msmqprivate, string msmqname) | |
| 521 | + public static string CreateFullQueuePath(string addressprefix, string msmqservername, string msmqname) | |
| 531 | 522 | { |
| 532 | - CreateQueueNames(addressprefix, msmqservername, msmqprivate, msmqname, out string qqn, out string qfn); | |
| 523 | + CreateQueueNames(addressprefix, msmqservername, msmqname, out string qfn); | |
| 533 | 524 | return qfn; |
| 534 | 525 | } |
| 535 | - public static string CreateQualifiedQueueName(string addressprefix, string msmqservername, bool msmqprivate, string msmqname) | |
| 536 | - { | |
| 537 | - CreateQueueNames(addressprefix, msmqservername, msmqprivate, msmqname, out string qqn, out string qfn); | |
| 538 | - return qqn; | |
| 539 | - } | |
| 540 | - private static void CreateQueueNames(string addressprefix, string msmqservername, bool msmqprivate, string msmqname,out string queuequalifiedname, out string msmqFullname) | |
| 526 | + private static void CreateQueueNames(string addressprefix, string msmqservername, string msmqname, out string msmqFullname) | |
| 541 | 527 | { |
| 542 | - var msmqprivatenamepart = msmqprivate ? "private$\\" : ""; | |
| 543 | 528 | if (msmqservername == "." || msmqservername.ToLower() == "localhost") { msmqservername = System.Environment.MachineName; } |
| 544 | 529 | var msmqservernamepart = string.IsNullOrWhiteSpace(msmqservername) ? "" : $"{msmqservername}\\"; |
| 545 | 530 | addressprefix = string.IsNullOrWhiteSpace(addressprefix) ? "" : addressprefix; |
| 546 | - msmqFullname = $"{addressprefix}{msmqservernamepart}{msmqprivatenamepart}{msmqname}"; | |
| 547 | - queuequalifiedname = $"{msmqprivatenamepart}{msmqname}"; | |
| 531 | + msmqFullname = $"{addressprefix}{msmqservernamepart}{msmqname}"; | |
| 548 | 532 | } |
| 549 | 533 | public static bool CheckIfQueueExists(string servername,string queuefullname) |
| 550 | 534 | { |
| ... | ... | @@ -558,53 +542,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 558 | 542 | //var queuenamelist = queuearray.Select(q => q.Path == queuefullname || q.FormatName== queuefullname || q.QueueName== queuefullname).ToList(); |
| 559 | 543 | //return queuenamelist.Any(); |
| 560 | 544 | } |
| 561 | - public static MSMQ CollectMSMQInfo(MSMQ msmgqef) | |
| 562 | - { | |
| 563 | - string msmqaddressprefix = msmgqef.Xml_AddressPrefix; | |
| 564 | - string msmqservername = msmgqef.Xml_Server; | |
| 565 | - bool msmqprivate = msmgqef.Xml_Private; | |
| 566 | - string msmqname = msmgqef.Xml_Name; | |
| 567 | - var msmqprivatenamepart = msmqprivate ? "private$\\" : ""; | |
| 568 | - string msmqFullname = $"{msmqaddressprefix}{msmqservername}\\{msmqprivatenamepart}{msmqname}"; | |
| 569 | - msmgqef.QueueName = msmqname ; | |
| 570 | - msmgqef.MachineName = msmqservername; | |
| 571 | - msmgqef.Path = msmqFullname; | |
| 572 | - try | |
| 573 | - { | |
| 574 | - msmgqef.Status = MessageQueue.Exists(msmqFullname) ? "Installed" : "Uninstalled"; | |
| 575 | - if (msmgqef.Status == "Installed") | |
| 576 | - { | |
| 577 | - using (var msmq = new MessageQueue(msmqFullname)) | |
| 578 | - { | |
| 579 | - msmgqef.QueueName = msmq.QueueName; | |
| 580 | - msmgqef.MachineName = msmq.MachineName; | |
| 581 | - | |
| 582 | - msmgqef.Id = msmq.Id; | |
| 583 | - msmgqef.NumOfMessages = MSMQManagerCore.Count(msmq); | |
| 584 | - msmgqef.Label = msmq.Label; | |
| 585 | - msmgqef.Formatter = msmq.Formatter; | |
| 586 | - msmgqef.FormatName = msmq.FormatName; | |
| 587 | - msmgqef.Path = msmq.Path; | |
| 588 | - msmgqef.LastModifyTime = msmq.LastModifyTime; | |
| 589 | - msmgqef.AccessMode = msmq.AccessMode; | |
| 590 | - msmgqef.CanRead = msmq.CanRead; | |
| 591 | - msmgqef.CanWrite = msmq.CanWrite; | |
| 592 | - msmgqef.MaximumQueueSize = msmq.MaximumQueueSize; | |
| 593 | - msmgqef.UseJournalQueue = msmq.UseJournalQueue; | |
| 594 | - msmgqef.MaximumJournalSize = msmq.MaximumJournalSize; | |
| 595 | - | |
| 596 | - msmgqef.Transactional = msmq.Transactional; | |
| 597 | - msmgqef.Authenticate = msmq.Authenticate; | |
| 598 | - msmgqef.BasePriority = msmq.BasePriority; | |
| 599 | - msmgqef.EncryptionRequired = msmq.EncryptionRequired; | |
| 600 | - | |
| 601 | - msmgqef.Status = "Ready"; | |
| 602 | - } | |
| 603 | - } | |
| 604 | - } | |
| 605 | - catch (Exception ex) { msmgqef.Status = "Error"; msmgqef.StatusDescription = ex.Message + (ex.InnerException!=null? ("\n" + ex.InnerException.Message):""); } | |
| 606 | - return msmgqef; | |
| 607 | - } | |
| 608 | 545 | public static void CreateQueue(string msmqFullname, string label=null) |
| 609 | 546 | { |
| 610 | 547 | if (!MessageQueue.Exists(msmqFullname)) { MessageQueue.Create(msmqFullname); } |
| ... | ... | @@ -684,6 +621,38 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 684 | 621 | body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); |
| 685 | 622 | } |
| 686 | 623 | } |
| 624 | + public static void ReadLast(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) | |
| 625 | + { | |
| 626 | + body = ""; | |
| 627 | + label = ""; | |
| 628 | + using (var msmq = new MessageQueue(msmqFullname)) | |
| 629 | + { | |
| 630 | + if (Count(msmq)>0) | |
| 631 | + { | |
| 632 | + //frmA = new System.Messaging.ActiveXMessageFormatter(); | |
| 633 | + //frmA = new System.Messaging.BinaryMessageFormatter(); | |
| 634 | + //frmA = new System.Messaging.XmlMessageFormatter(); | |
| 635 | + msmq.Formatter = messageformatter; | |
| 636 | + //Message m = msmq.Receive(new TimeSpan(0)); | |
| 637 | + var m = msmq.ReceiveByLookupId(MessageLookupAction.Last, 0, null); | |
| 638 | + label = m.Label; | |
| 639 | + body = encoding.GetString((byte[])m.Body); | |
| 640 | + | |
| 641 | + | |
| 642 | + //m.BodyStream.Position = 0; | |
| 643 | + | |
| 644 | + //// encoding = System.Text.Encoding.UTF8; | |
| 645 | + //// encoding = System.Text.Encoding.UTF7; | |
| 646 | + //// encoding = System.Text.Encoding.UTF32; | |
| 647 | + //// encoding = System.Text.Encoding.Unicode; | |
| 648 | + //// encoding = System.Text.Encoding.BigEndianUnicode; | |
| 649 | + //// encoding = System.Text.Encoding.ASCII; | |
| 650 | + //// encoding = System.Text.Encoding.Default; | |
| 651 | + //var sr = new System.IO.StreamReader(m.BodyStream, encoding); | |
| 652 | + //body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); | |
| 653 | + } | |
| 654 | + } | |
| 655 | + } | |
| 687 | 656 | public static void Send(string msmqFullname, string messagetosend, string messagelabel, IMessageFormatter messageformatter, Encoding encoding) |
| 688 | 657 | { |
| 689 | 658 | using (var msmq = new MessageQueue(msmqFullname)) |
| ... | ... | @@ -821,187 +790,4 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
| 821 | 790 | } |
| 822 | 791 | } |
| 823 | 792 | #endregion Defaults class |
| 824 | - | |
| 825 | - #region MSMQ class | |
| 826 | - public class MSMQ : XmlLinqBase | |
| 827 | - { | |
| 828 | - #region fields | |
| 829 | - public bool Valid = true; | |
| 830 | - public string Xml_Key; | |
| 831 | - public string Xml_Name; | |
| 832 | - public string Xml_AddressPrefix = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT; | |
| 833 | - public string Xml_Server = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT; | |
| 834 | - public bool Xml_Private = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Private.Values.DEFAULT; | |
| 835 | - public string Xml_Mode = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT; | |
| 836 | - public string Xml_Label; | |
| 837 | - public string Xml_Formatter = XmlStructure.MSMQManager.General.DefaultFormatter.Values.DEFAULT; | |
| 838 | - public string Xml_Encoding = XmlStructure.MSMQManager.General.DefaultEncoding.Values.DEFAULT; | |
| 839 | - public List<AccessRights> Xml_AccessRights = new List<AccessRights>(); | |
| 840 | - | |
| 841 | - public string Status; | |
| 842 | - public string StatusDescription=null; | |
| 843 | - public Guid Id; | |
| 844 | - public string QueueName; | |
| 845 | - public long NumOfMessages; | |
| 846 | - public string Label; | |
| 847 | - public string MachineName; | |
| 848 | - public IMessageFormatter Formatter; | |
| 849 | - public string FormatName; | |
| 850 | - public string Path; | |
| 851 | - public DateTime LastModifyTime; | |
| 852 | - public QueueAccessMode AccessMode; | |
| 853 | - public bool CanRead; | |
| 854 | - public bool CanWrite; | |
| 855 | - public long MaximumQueueSize; | |
| 856 | - public bool UseJournalQueue; | |
| 857 | - public long MaximumJournalSize; | |
| 858 | - | |
| 859 | - public bool Transactional; | |
| 860 | - public bool Authenticate; | |
| 861 | - public int BasePriority; | |
| 862 | - public EncryptionRequired EncryptionRequired; | |
| 863 | - #endregion fields | |
| 864 | - | |
| 865 | - #region basic constructor | |
| 866 | - public MSMQ() { } | |
| 867 | - #endregion basic constructor | |
| 868 | - #region xml constructor | |
| 869 | - public string PriorityText(int pri) | |
| 870 | - { | |
| 871 | - return | |
| 872 | - (pri == 0 ? "Realtime" | |
| 873 | - : pri == 1 ? "High" | |
| 874 | - : pri == 2 ? "High" | |
| 875 | - : pri == 3 ? "Normal" | |
| 876 | - : pri == 4 ? "Normal" | |
| 877 | - : pri == 5 ? "Normal" | |
| 878 | - : pri == 6 ? "Normal" | |
| 879 | - : pri == 7 ? "Low" | |
| 880 | - : pri == 8 ? "Low" | |
| 881 | - : pri == 9 ? "Idle" | |
| 882 | - : pri == 10 ? "Idle" | |
| 883 | - : "Idle") + $"({pri})"; | |
| 884 | - } | |
| 885 | - public MSMQ(XElement msmqxml,MSMQDefaults msmqdefaults) | |
| 886 | - { | |
| 887 | - Valid = true; | |
| 888 | - string ATTRIBUTEMANDATORY = nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue) + " attribute is mandatory! Name: {0}"; | |
| 889 | - Xml_Key = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key.Values.DEFAULT); | |
| 890 | - Xml_Name = msmqxml.Attribute(XName.Get(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name)))?.Value; | |
| 891 | - if (string.IsNullOrWhiteSpace(Xml_Name)) { throw new ApplicationException(string.Format(ATTRIBUTEMANDATORY, nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name))); } | |
| 892 | - Xml_AddressPrefix = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT); | |
| 893 | - Xml_Server = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT); | |
| 894 | - if (Xml_Server == "." || Xml_Server.ToLower() == "localhost") { Xml_Server = System.Environment.MachineName; } | |
| 895 | - | |
| 896 | - Xml_Private = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Private), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Private.Values.DEFAULT); | |
| 897 | - Xml_Mode = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT); | |
| 898 | - Xml_Label = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Label), msmqxml, Xml_Name); | |
| 899 | - Xml_Formatter = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter), msmqxml, msmqdefaults.Xml_DefaultFormatter); | |
| 900 | - Xml_Encoding = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Encoding), msmqxml, msmqdefaults.Xml_DefaultEncoding); | |
| 901 | - | |
| 902 | - foreach (var ar in msmqdefaults.Xml_AccessRights) { Xml_AccessRights.Add(ar); } | |
| 903 | - try | |
| 904 | - { | |
| 905 | - var arxmllist = GetAllXElements(msmqxml, nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.AccessRight)); | |
| 906 | - foreach (var arxml in arxmllist) { var newa = AccessRights.Factory(arxml); if (newa != null) { Xml_AccessRights.Add(newa); } } | |
| 907 | - } | |
| 908 | - catch{ } | |
| 909 | - | |
| 910 | - | |
| 911 | - } | |
| 912 | - #endregion xml constructor | |
| 913 | - #region cloner constructor | |
| 914 | - public MSMQ(MSMQ msmq) | |
| 915 | - { | |
| 916 | - Valid = msmq.Valid; | |
| 917 | - Xml_Key = msmq.Xml_Key; | |
| 918 | - Xml_Name = msmq.Xml_Name; | |
| 919 | - Xml_Server = msmq.Xml_Server; | |
| 920 | - Xml_Private = msmq.Xml_Private; | |
| 921 | - Xml_Mode = msmq.Xml_Mode; | |
| 922 | - Xml_Label = msmq.Xml_Label; | |
| 923 | - Xml_Formatter= msmq.Xml_Formatter; | |
| 924 | - Xml_Encoding = msmq.Xml_Encoding; | |
| 925 | - } | |
| 926 | - #endregion cloner constructor | |
| 927 | - #region XmlStructure | |
| 928 | - public static class XmlStructure | |
| 929 | - { | |
| 930 | - public static class MSMQManager | |
| 931 | - { | |
| 932 | - public static class General | |
| 933 | - { | |
| 934 | - public static class AccessRights | |
| 935 | - { | |
| 936 | - public static class AccessRight | |
| 937 | - { | |
| 938 | - public static class Attributes | |
| 939 | - { | |
| 940 | - public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } | |
| 941 | - public static class Right {public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } | |
| 942 | - public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } | |
| 943 | - } | |
| 944 | - } | |
| 945 | - } | |
| 946 | - public static class MessageFiles | |
| 947 | - { | |
| 948 | - public static class Attributes | |
| 949 | - { | |
| 950 | - public static class Directory { public static class Values { public const string DEFAULT = ""; } } | |
| 951 | - public static class SendToMask { public static class Values { public const string DEFAULT = "*.*"; } } | |
| 952 | - public static class ReadToMask { public static class Values { public const string DEFAULT = "*.*"; } } | |
| 953 | - } | |
| 954 | - } | |
| 955 | - public static class DefaultFormatter { public static class Values { public const string DEFAULT = nameof(ActiveXMessageFormatter); } } | |
| 956 | - public static class DefaultEncoding { public static class Values { public const string DEFAULT = nameof(System.Text.Encoding.UTF8); } } | |
| 957 | - } | |
| 958 | - | |
| 959 | - public static class MessageQueues | |
| 960 | - { | |
| 961 | - public static class MessageQueue | |
| 962 | - { | |
| 963 | - public static class Attributes | |
| 964 | - { | |
| 965 | - public static class Key { public static class Values { public const string DEFAULT = ""; } } | |
| 966 | - public static class AddressPrefix{ public static class Values { public const string DEFAULT = ""; } } | |
| 967 | - public static class Server { public static class Values { public const string DEFAULT = "."; } } | |
| 968 | - public static class Name { } | |
| 969 | - public static class Label { } | |
| 970 | - public static class Private { public static class Values { public const bool DEFAULT = true; } } | |
| 971 | - public static class Mode | |
| 972 | - { | |
| 973 | - public static class Values | |
| 974 | - { | |
| 975 | - public const string DEFAULT = "In"; | |
| 976 | - public static class In { } | |
| 977 | - public static class Out { } | |
| 978 | - } | |
| 979 | - } | |
| 980 | - public static class Formatter | |
| 981 | - { | |
| 982 | - public static class Values | |
| 983 | - { | |
| 984 | - public static class ActiveXMessageFormatter { } | |
| 985 | - public static class BinaryMessageFormatter { } | |
| 986 | - public static class XmlMessageFormatter { } | |
| 987 | - } | |
| 988 | - } | |
| 989 | - public static class Encoding { } | |
| 990 | - } | |
| 991 | - public static class AccessRight | |
| 992 | - { | |
| 993 | - public static class Attributes | |
| 994 | - { | |
| 995 | - public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } | |
| 996 | - public static class Right { public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } | |
| 997 | - public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } | |
| 998 | - } | |
| 999 | - } | |
| 1000 | - } | |
| 1001 | - } | |
| 1002 | - } | |
| 1003 | - } | |
| 1004 | - #endregion XmlStructure | |
| 1005 | - } | |
| 1006 | - #endregion MSMQ class | |
| 1007 | 793 | } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs
| ... | ... | @@ -71,7 +71,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS |
| 71 | 71 | #region RegexTester |
| 72 | 72 | public static object StartAsSystem(object parameter, object o) |
| 73 | 73 | { |
| 74 | - OtherTools.StartAsSystem(false); | |
| 74 | + OtherTools.StartAsSystem(true); | |
| 75 | 75 | return o; |
| 76 | 76 | } |
| 77 | 77 | private static object RegexTester(object parameter, object o) | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Program.cs
| ... | ... | @@ -37,8 +37,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole |
| 37 | 37 | { |
| 38 | 38 | static void Main(string[] args) |
| 39 | 39 | { |
| 40 | + var startassystemstr = CommandLine.GetCommandLineArgument(args, CLP.CMD_STARTASSYSTEM); | |
| 41 | + var startassystem = startassystemstr!=null && startassystemstr.ToLower() == "yes"; | |
| 42 | + | |
| 40 | 43 | OtherTools.StartAsAdmin(); |
| 41 | - OtherTools.StartAsSystem(silent:false); | |
| 44 | + OtherTools.StartAsSystem(silent:startassystem); | |
| 42 | 45 | //while (true) |
| 43 | 46 | //{ |
| 44 | 47 | // Console.Clear(); | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
| ... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
| 32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
| 33 | 33 | // by using the '*' as shown below: |
| 34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
| 35 | -[assembly: AssemblyVersion("1.9.0.0")] | |
| 36 | -[assembly: AssemblyFileVersion("1.9.0.0")] | |
| 35 | +[assembly: AssemblyVersion("1.9.2.0")] | |
| 36 | +[assembly: AssemblyFileVersion("1.9.2.0")] | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj
| ... | ... | @@ -359,6 +359,7 @@ |
| 359 | 359 | <Compile Include="ConsoleFunction - Tools.cs" /> |
| 360 | 360 | <Compile Include="Manager - BackupPackageManager.cs" /> |
| 361 | 361 | <Compile Include="Manager - InstallManager.cs" /> |
| 362 | + <Compile Include="Manager - MSMQManager - MSMQ.cs" /> | |
| 362 | 363 | <Compile Include="Manager - MSMQManager.cs" /> |
| 363 | 364 | <Compile Include="Manager - UserManager.cs" /> |
| 364 | 365 | <Compile Include="Manager - SQLDataBaseManager.cs" /> | ... | ... |