Commit f732e5c9d2a0f91b2e45a25836aae87329f4911a
1 parent
c4219940
v17.0.0
- messagequeue-ba küldés funkcióba beépítésre került az előre definiált üzenet templétek lehetősége, - valamint több üzenet ciklikusban való elküldése ciklus és időbélyeg változók helyettesítésével
Showing
2 changed files
with
114 additions
and
25 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs
... | ... | @@ -232,19 +232,22 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
232 | 232 | { |
233 | 233 | var msmq = p.Parameters as MSMQ; |
234 | 234 | msmq.DisplayInfo(); ix++; |
235 | - var sp = SendParameters.Get(msmq.Xml_Encoding, msmq.Xml_Formatter); | |
235 | + var sp = SendParameters.Get(msmq,msmq.Xml_Encoding, msmq.Xml_Formatter); | |
236 | 236 | if (sp != null) |
237 | 237 | { |
238 | - var fullpath = msmq.Xml_FullPath; | |
239 | - MSMQManagerCore.Send(fullpath, sp.messagebody, sp.messagelabel, sp.messageformatter, sp.encoding); | |
240 | - ColorConsole.WriteLine($"Sending to '{fullpath}' ....", ConsoleColor.Yellow); | |
241 | - Message msg = MSMQManagerCore.PeekLast(fullpath, sp.messageformatter, sp.encoding, out string body, out string label); | |
242 | - TestSendCheckMessage(fullpath, msg, sp, body, label, "message sending/peek back"); | |
243 | - var ans = ColorConsole.ReadLine($"Do You want to remove this test message (lookup id='{msg.LookupId}') from quue?", ConsoleColor.Yellow, validitylist: new List<string> { "yes", "no" }, defaultvalue: "yes"); | |
244 | - if (ans.ToLower() == "yes") | |
245 | - { | |
246 | - msg = MSMQManagerCore.ReadById(fullpath, msg.LookupId, sp.messageformatter, sp.encoding, out body, out label); | |
247 | - TestSendCheckMessage(fullpath, msg, sp, body, label, "Read back."); | |
238 | + for (var msgindex=1; msgindex <= sp.numofmessages; msgindex++) | |
239 | + { | |
240 | + sp.Substitute(msgindex); | |
241 | + MSMQManagerCore.Send(msmq.Xml_FullPath, sp.messagebodysubstituted, sp.messagelabelsubstituted, sp.messageformatter, sp.encoding); | |
242 | + ColorConsole.WriteLine($"Sending to '{msmq.Xml_FullPath}' ....", ConsoleColor.Yellow); | |
243 | + Message msg = MSMQManagerCore.PeekLast(msmq.Xml_FullPath, sp.messageformatter, sp.encoding, out string body, out string label); | |
244 | + TestSendCheckMessage(msmq.Xml_FullPath, msg, sp, body, label, "message sending/peek back"); | |
245 | + var ans = ColorConsole.ReadLine($"Do You want to remove this test message (lookup id='{msg.LookupId}') from quue?", ConsoleColor.Yellow, validitylist: new List<string> { "yes", "no" }, defaultvalue: "yes"); | |
246 | + if (ans.ToLower() == "yes") | |
247 | + { | |
248 | + msg = MSMQManagerCore.ReadById(msmq.Xml_FullPath, msg.LookupId, sp.messageformatter, sp.encoding, out body, out label); | |
249 | + TestSendCheckMessage(msmq.Xml_FullPath, msg, sp, body, label, "Read back."); | |
250 | + } | |
248 | 251 | } |
249 | 252 | } |
250 | 253 | } |
... | ... | @@ -382,12 +385,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
382 | 385 | { |
383 | 386 | try |
384 | 387 | { |
385 | - var sp = SendParameters.Get(st.Xml_Encoding, st.Xml_Formatter); | |
388 | + var sp = SendParameters.Get(st,st.Xml_Encoding, st.Xml_Formatter); | |
386 | 389 | if (sp == null) { break; } |
387 | - | |
388 | - var fullpath = st.Xml_FullPath; | |
389 | - MSMQManagerCore.Send(fullpath, sp.messagebody, sp.messagelabel, sp.messageformatter, sp.encoding); | |
390 | - ColorConsole.WriteLine($"Message sent to MSMQ:{st.Xml_Name}.", ConsoleColor.Green); | |
390 | + for (var msgindex = 1; msgindex <= sp.numofmessages; msgindex++) | |
391 | + { | |
392 | + sp.Substitute(msgindex); | |
393 | + MSMQManagerCore.Send(st.Xml_FullPath, sp.messagebodysubstituted, sp.messagelabelsubstituted, sp.messageformatter, sp.encoding); | |
394 | + ColorConsole.WriteLine($"Message sent to MSMQ:{st.Xml_Name}.", ConsoleColor.Green); | |
395 | + } | |
391 | 396 | } |
392 | 397 | catch (ApplicationException ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } |
393 | 398 | catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } |
... | ... | @@ -419,32 +424,68 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
419 | 424 | } |
420 | 425 | private class SendParameters |
421 | 426 | { |
427 | + public string messagebodysubstituted; | |
428 | + public string messagelabelsubstituted; | |
422 | 429 | public string messagebody; |
423 | 430 | public string messagelabel; |
424 | 431 | public IMessageFormatter messageformatter; |
425 | 432 | public Encoding encoding; |
433 | + public int numofmessages; | |
426 | 434 | public SendParameters() { } |
427 | - public static SendParameters Get(string defaultencoding, string defaultformatter) | |
435 | + public SendParameters Substitute(int index) | |
436 | + { | |
437 | + var dtnow = DateTime.Now; | |
438 | + messagebodysubstituted = messagebody.Replace("{IX}", $"{index}").Replace("{TS}", dtnow.ToString("HHmmss")).Replace("{DS}", dtnow.ToString("yyyyMMdd")).Replace("{DTS}", dtnow.ToString("yyyyMMddHHmmss")); | |
439 | + messagelabelsubstituted = messagelabel.Replace("{IX}", $"{index}").Replace("{TS}", dtnow.ToString("HHmmss")).Replace("{DS}", dtnow.ToString("yyyyMMdd")).Replace("{DTS}", dtnow.ToString("yyyyMMddHHmmss")); | |
440 | + return this; | |
441 | + } | |
442 | + public static SendParameters Get(MSMQ st, string defaultencoding, string defaultformatter) | |
428 | 443 | { |
429 | - ColorConsole.WriteLine("Enter test message data!", ConsoleColor.Yellow); | |
444 | + ColorConsole.Write("Enter test message data", ConsoleColor.Yellow); | |
445 | + if (st.MessageTemplates != null && st.MessageTemplates.Any()) { ColorConsole.Write(", or select one from the predefined list!", ConsoleColor.Yellow); } | |
446 | + ColorConsole.WriteLine("!", ConsoleColor.Yellow); | |
447 | + ColorConsole.WriteLine("Use {IX},{DS},{TS},{DTS} variables in the message text to substitute them with the message number index,date stamp,time stamp and date-time stamp, respectively.", ConsoleColor.Yellow); | |
448 | + Console.WriteLine(); | |
449 | + var templatekeylist = new Dictionary<string,int>(); | |
450 | + if (st.MessageTemplates != null && st.MessageTemplates.Any()) | |
451 | + { | |
452 | + var index = 1; | |
453 | + foreach (var mt in st.MessageTemplates) | |
454 | + { | |
455 | + var tk = $"S{index}"; templatekeylist.Add(tk, index - 1); | |
456 | + ColorConsole.WriteLine(mt.Xml_TemplateString, ConsoleColor.White, prefix:$"[{tk}] "); | |
457 | + index++; | |
458 | + } | |
459 | + } | |
460 | + | |
430 | 461 | var sp = new SendParameters() { }; |
431 | 462 | var now = DateTime.Now.ToString(); |
432 | - sp.messagebody = ColorConsole.ReadLine("Enter message body:", ConsoleColor.Yellow, defaultvalue: "TEST MESSAGE " + now); | |
433 | - if (sp.messagebody.ToUpper() == "EX") { return null; } | |
463 | + var messagebody = ColorConsole.ReadLine("Enter message body (text or template key):", ConsoleColor.Yellow, defaultvalue: "TEST MESSAGE " + now); | |
464 | + if (messagebody.ToUpper() == "EX") { return null; } | |
465 | + if (templatekeylist.ContainsKey(messagebody)) messagebody = st.MessageTemplates.ElementAt(templatekeylist[messagebody]).Xml_TemplateString; | |
466 | + sp.messagebody = messagebody; | |
434 | 467 | |
435 | 468 | sp.messagelabel = ColorConsole.ReadLine("Enter message label:", ConsoleColor.Yellow, defaultvalue: "TESTLABEL" + now); |
436 | 469 | if (sp.messagelabel.ToUpper() == "EX") { return null; } |
437 | 470 | |
471 | + const string VALUEISINCORRECT = "{0} value is incorrect! Value:{1}. Repeat data entry!"; | |
472 | + getformatter: | |
438 | 473 | var messageformatterstring = ColorConsole.ReadLine("Enter formatter:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetFormatterNames(), defaultvalue: defaultformatter); |
439 | 474 | if (messageformatterstring.ToUpper() == "EX") { return null; } |
440 | 475 | sp.messageformatter = MSMQManagerCore.SetFormatter(messageformatterstring); |
441 | - if (sp.messageformatter == null) { var exmsg = $"Message formatter value is incorrect! Value:{messageformatterstring }."; throw new ApplicationException(exmsg); } | |
476 | + if (sp.messageformatter == null) { Console.WriteLine(string.Format(VALUEISINCORRECT ,"Message formatter",messageformatterstring),ConsoleColor.Red); goto getformatter; } | |
442 | 477 | |
478 | + getencoder: | |
443 | 479 | string encodingstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetEncodingNames(), defaultvalue: defaultencoding); |
444 | 480 | if (encodingstring.ToUpper() == "EX") { return null; } |
445 | 481 | sp.encoding = MSMQManagerCore.SetEncoding(encodingstring); |
446 | - if (sp.encoding == null) { var exmsg = $"Message encoder value is incorrect! Value:{encodingstring}."; throw new ApplicationException(exmsg); } | |
482 | + if (sp.encoding == null) { Console.WriteLine(string.Format(VALUEISINCORRECT, "Message encoder",encodingstring), ConsoleColor.Red); goto getencoder; } | |
447 | 483 | |
484 | + getnumofmessages: | |
485 | + string numofmessagesstring = ColorConsole.ReadLine("Enter number of messages:", ConsoleColor.Yellow, defaultvalue: "1"); | |
486 | + if (numofmessagesstring.ToUpper() == "EX") { return null; } | |
487 | + if (!int.TryParse(numofmessagesstring, out sp.numofmessages) || sp.numofmessages<=0) { sp.numofmessages = -1; } | |
488 | + if (sp.numofmessages == -1) { Console.WriteLine(string.Format(VALUEISINCORRECT, "Number of messages",numofmessagesstring), ConsoleColor.Red); goto getnumofmessages; } | |
448 | 489 | return sp; |
449 | 490 | } |
450 | 491 | } |
... | ... | @@ -836,7 +877,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
836 | 877 | var msmqxmllist = GetAllXElements(nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues), nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue)); |
837 | 878 | if (msmqxmllist != null && msmqxmllist.Any()) |
838 | 879 | { |
839 | - foreach (var msmqxml in msmqxmllist) { var st = new MSMQ(msmqxml, new MSMQDefaults(RootElement)); if (st.Valid) { _msmqlist.Add(st); } } | |
880 | + var msmqdefaults = new MSMQDefaults(RootElement); | |
881 | + var msmqmsgtemplates = new MSMQMessageTemplates(RootElement); | |
882 | + foreach (var msmqxml in msmqxmllist) | |
883 | + { | |
884 | + var msmq = new MSMQ(msmqxml, msmqdefaults); | |
885 | + msmq.AddTemplates(msmqmsgtemplates.GetTemplatesForMSMQ(msmq.Xml_Key)); | |
886 | + if (msmq.Valid) { _msmqlist.Add(msmq); } | |
887 | + } | |
840 | 888 | } |
841 | 889 | } |
842 | 890 | #endregion constructor |
... | ... | @@ -876,6 +924,35 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
876 | 924 | public MessageQueueAccessRights ar; |
877 | 925 | public AccessControlEntryType ac; |
878 | 926 | } |
927 | + public class MSMQMessageTemplates : XmlLinqBase | |
928 | + { | |
929 | + public List<MSMQMessageTemplate> Xml_MessageTemplateList=new List<MSMQMessageTemplate>(); | |
930 | + public MSMQMessageTemplates(XElement rootxml) | |
931 | + { | |
932 | + var messagetemplatesxmls = GetXElement(rootxml, nameof(MSMQ.XmlStructure.MSMQManager.MessageTemplates)); | |
933 | + var messagetemplatexmllist = GetAllXElements(messagetemplatesxmls,nameof(MSMQ.XmlStructure.MSMQManager.MessageTemplates.MessageTemplate)); | |
934 | + if (messagetemplatexmllist == null || !messagetemplatexmllist.Any()) return; | |
935 | + foreach (var mtxml in messagetemplatexmllist) { var mt = new MSMQMessageTemplate(mtxml); if (mt.isValid) { Xml_MessageTemplateList.Add(mt); } } | |
936 | + } | |
937 | + public List<MSMQMessageTemplate> GetTemplatesForMSMQ(string msmqid) | |
938 | + { | |
939 | + return this.Xml_MessageTemplateList.Where(mt=> mt.Xml_QueueIdList==null || !mt.Xml_QueueIdList.Any() || mt.Xml_QueueIdList.Contains("*") || mt.Xml_QueueIdList.Contains(msmqid)).ToList(); | |
940 | + } | |
941 | + } | |
942 | + public class MSMQMessageTemplate : XmlLinqBase | |
943 | + { | |
944 | + public string Xml_TemplateString; | |
945 | + public bool isValid = true; | |
946 | + public List<string> Xml_QueueIdList; | |
947 | + public MSMQMessageTemplate(XElement messagetemplatexml) | |
948 | + { | |
949 | + Xml_TemplateString = GetValue(messagetemplatexml, ""); | |
950 | + if (string.IsNullOrWhiteSpace(Xml_TemplateString)) { isValid = false; return; } | |
951 | + Xml_QueueIdList = new List<string>(); | |
952 | + var queueidlistcsvstring = GetValue(nameof(MSMQ.XmlStructure.MSMQManager.MessageTemplates.MessageTemplate.Attributes.QueueIdList), messagetemplatexml, MSMQ.XmlStructure.MSMQManager.MessageTemplates.MessageTemplate.Attributes.QueueIdList.Values.DEFAULT); | |
953 | + if (!string.IsNullOrWhiteSpace(queueidlistcsvstring)) Xml_QueueIdList = queueidlistcsvstring.Split(new char[] { ',', ';' },StringSplitOptions.RemoveEmptyEntries).ToList(); | |
954 | + } | |
955 | + } | |
879 | 956 | public class MSMQDefaults : XmlLinqBase |
880 | 957 | { |
881 | 958 | public string Xml_MessageFilesDirectory; |
... | ... | @@ -920,6 +997,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
920 | 997 | public string Xml_Formatter = XmlStructure.MSMQManager.General.DefaultFormatter.Values.DEFAULT; |
921 | 998 | public string Xml_Encoding = XmlStructure.MSMQManager.General.DefaultEncoding.Values.DEFAULT; |
922 | 999 | public List<AccessRights> Xml_AccessRights = new List<AccessRights>(); |
1000 | + public List<MSMQMessageTemplate> MessageTemplates = new List<MSMQMessageTemplate>(); | |
923 | 1001 | |
924 | 1002 | public string Status; |
925 | 1003 | public string StatusDescription = null; |
... | ... | @@ -964,6 +1042,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
964 | 1042 | } |
965 | 1043 | #endregion constructor from MessageQueue |
966 | 1044 | |
1045 | + public MSMQ AddTemplates(List<MSMQMessageTemplate> mtl) { MessageTemplates = mtl; return this; } | |
967 | 1046 | #region xml constructor |
968 | 1047 | public MSMQ(XElement msmqxml, MSMQDefaults msmqdefaults) |
969 | 1048 | { |
... | ... | @@ -1291,6 +1370,16 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS |
1291 | 1370 | public static class DefaultEncoding { public static class Values { public const string DEFAULT = nameof(System.Text.Encoding.UTF8); } } |
1292 | 1371 | } |
1293 | 1372 | |
1373 | + public static class MessageTemplates | |
1374 | + { | |
1375 | + public static class MessageTemplate | |
1376 | + { | |
1377 | + public static class Attributes | |
1378 | + { | |
1379 | + public static class QueueIdList { public static class Values { public const string DEFAULT = ""; } } | |
1380 | + } | |
1381 | + } | |
1382 | + } | |
1294 | 1383 | public static class MessageQueues |
1295 | 1384 | { |
1296 | 1385 | public static class MessageQueue | ... | ... |
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.16.3.0")] | |
36 | -[assembly: AssemblyFileVersion("1.16.3.0")] | |
35 | +[assembly: AssemblyVersion("1.17.0.0")] | |
36 | +[assembly: AssemblyFileVersion("1.17.0.0")] | ... | ... |