Commit 4f42525397cbea4c426ad5789d81499637cb1b92

Authored by Schwirg László
1 parent 6cd93dfa

v1.22

-MSMQ Send és Read rutinok tisztába tétele
Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs
@@ -16,6 +16,7 @@ using VRH.Common; @@ -16,6 +16,7 @@ using VRH.Common;
16 using System.Xml.Linq; 16 using System.Xml.Linq;
17 using System.Text.RegularExpressions; 17 using System.Text.RegularExpressions;
18 using System.ComponentModel; 18 using System.ComponentModel;
  19 +using System.IO;
19 20
20 namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS 21 namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS
21 { 22 {
@@ -728,28 +729,15 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS @@ -728,28 +729,15 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS
728 using (var msmq = new MessageQueue(msmqFullname)) 729 using (var msmq = new MessageQueue(msmqFullname))
729 { 730 {
730 if (Count(msmq) == 0) { return null; } 731 if (Count(msmq) == 0) { return null; }
731 -  
732 - //frmA = new System.Messaging.ActiveXMessageFormatter();  
733 - //frmA = new System.Messaging.BinaryMessageFormatter();  
734 - //frmA = new System.Messaging.XmlMessageFormatter();  
735 msmq.Formatter = messageformatter; 732 msmq.Formatter = messageformatter;
736 -  
737 - Message m = msmq.Receive(new TimeSpan(0));  
738 - label = m.Label;  
739 - //m.BodyStream.Position = 0;  
740 - //var sr = new System.IO.StreamReader(m.BodyStream, encoding);  
741 - //body = sr.ReadToEnd().Replace(((char)0).ToString(), "");  
742 - // encoding = System.Text.Encoding.UTF8;  
743 - // encoding = System.Text.Encoding.UTF7;  
744 - // encoding = System.Text.Encoding.UTF32;  
745 - // encoding = System.Text.Encoding.Unicode;  
746 - // encoding = System.Text.Encoding.BigEndianUnicode;  
747 - // encoding = System.Text.Encoding.ASCII;  
748 - // encoding = System.Text.Encoding.Default;  
749 - body = encoding.GetString((byte[])m.Body);  
750 - return m; 733 + Message msg = msmq.Receive(new TimeSpan(0));
  734 + label = msg.Label;
  735 + body = GetBody(msg, encoding);
  736 + return msg;
751 } 737 }
752 } 738 }
  739 +
  740 +
753 public static Message ReadLast(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) 741 public static Message ReadLast(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label)
754 { 742 {
755 body = ""; 743 body = "";
@@ -758,28 +746,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS @@ -758,28 +746,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS
758 { 746 {
759 if (Count(msmq) == 0) { return null; } 747 if (Count(msmq) == 0) { return null; }
760 748
761 - //frmA = new System.Messaging.ActiveXMessageFormatter();  
762 - //frmA = new System.Messaging.BinaryMessageFormatter();  
763 - //frmA = new System.Messaging.XmlMessageFormatter();  
764 msmq.Formatter = messageformatter; 749 msmq.Formatter = messageformatter;
765 - //Message m = msmq.Receive(new TimeSpan(0));  
766 - var m = msmq.ReceiveByLookupId(MessageLookupAction.Last, 0, null);  
767 - label = m.Label;  
768 - body = encoding.GetString((byte[])m.Body);  
769 -  
770 -  
771 - //m.BodyStream.Position = 0;  
772 -  
773 - //// encoding = System.Text.Encoding.UTF8;  
774 - //// encoding = System.Text.Encoding.UTF7;  
775 - //// encoding = System.Text.Encoding.UTF32;  
776 - //// encoding = System.Text.Encoding.Unicode;  
777 - //// encoding = System.Text.Encoding.BigEndianUnicode;  
778 - //// encoding = System.Text.Encoding.ASCII;  
779 - //// encoding = System.Text.Encoding.Default;  
780 - //var sr = new System.IO.StreamReader(m.BodyStream, encoding);  
781 - //body = sr.ReadToEnd().Replace(((char)0).ToString(), "");  
782 - return m; 750 + var msg = msmq.ReceiveByLookupId(MessageLookupAction.Last, 0, null);
  751 + label = msg.Label;
  752 + body = GetBody(msg, encoding);
  753 + return msg;
783 } 754 }
784 } 755 }
785 public static Message ReadById(string msmqFullname, long msgid, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) 756 public static Message ReadById(string msmqFullname, long msgid, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label)
@@ -791,23 +762,58 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS @@ -791,23 +762,58 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS
791 if (Count(msmq) == 0) { return null; } 762 if (Count(msmq) == 0) { return null; }
792 763
793 msmq.Formatter = messageformatter; 764 msmq.Formatter = messageformatter;
794 - var m = msmq.ReceiveByLookupId(msgid);  
795 - label = m.Label;  
796 - body = encoding.GetString((byte[])m.Body);  
797 - return m; 765 + var msg = msmq.ReceiveByLookupId(msgid);
  766 + label = msg.Label;
  767 + body = GetBody(msg, encoding);
  768 + return msg;
798 } 769 }
799 } 770 }
  771 + private static string GetBody(Message msg, Encoding encoding)
  772 + {
  773 + //////////////////////////////////////////////
  774 + StreamReader reader;
  775 + string body;
  776 + if (msg.Formatter is XmlMessageFormatter)
  777 + {
  778 + ((XmlMessageFormatter)msg.Formatter).TargetTypes = new Type[] { typeof(string), };
  779 + body = (string)msg.Body;
  780 + }
  781 + else
  782 + {
  783 + if (encoding == null) { body = (string)msg.Body; }
  784 + else { reader = new StreamReader(msg.BodyStream, encoding); body = reader.ReadToEnd(); }
  785 + }
  786 + //////////////////////////////////////////////
  787 + //body = encoding.GetString((byte[])msg.Body);
  788 + //////////////////////////////////////////////////
  789 + return body;
  790 + }
800 public static void Send(string msmqFullname, string messagetosend, string messagelabel, IMessageFormatter messageformatter, Encoding encoding) 791 public static void Send(string msmqFullname, string messagetosend, string messagelabel, IMessageFormatter messageformatter, Encoding encoding)
801 { 792 {
802 using (var msmq = new MessageQueue(msmqFullname)) 793 using (var msmq = new MessageQueue(msmqFullname))
803 { 794 {
804 - ///frmA = new System.Messaging.ActiveXMessageFormatter();  
805 - //enc = System.Text.Encoding.UTF8;  
806 msmq.Formatter = messageformatter; 795 msmq.Formatter = messageformatter;
807 - byte[] encodedmessage = encoding.GetBytes(messagetosend);  
808 -  
809 - msmq.Send(encodedmessage, messagelabel); 796 + Message msg = new System.Messaging.Message();
  797 + SetBody(msg, messagetosend, messageformatter, encoding);
  798 + msg.Label = messagelabel;
  799 + msmq.Send(msg);
  800 + }
  801 + }
  802 + private static Message SetBody(Message msg, string messagetosend, IMessageFormatter messageformatter, Encoding encoding)
  803 + {
  804 + //////////////////////////////////////////////////////////////////////////
  805 + msg.Formatter = messageformatter;
  806 + if (msg.Formatter is XmlMessageFormatter) { msg.Body = messagetosend; }
  807 + else
  808 + {
  809 + if (encoding == null) { msg.Body = messagetosend; }
  810 + else { msg.BodyStream = new MemoryStream(encoding.GetBytes(messagetosend)); }
810 } 811 }
  812 + //////////////////////////////////////////////////////////////////////////
  813 + //byte[] encodedmessage = encoding.GetBytes(messagetosend);
  814 + //msmq.Send(encodedmessage, messagelabel);
  815 + //////////////////////////////////////////////////////////////////////////
  816 + return msg;
811 } 817 }
812 public static long Count(MessageQueue messageQueue) 818 public static long Count(MessageQueue messageQueue)
813 { 819 {
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices; @@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
32 // You can specify all the values or you can default the Build and Revision Numbers 32 // You can specify all the values or you can default the Build and Revision Numbers
33 // by using the '*' as shown below: 33 // by using the '*' as shown below:
34 // [assembly: AssemblyVersion("1.0.*")] 34 // [assembly: AssemblyVersion("1.0.*")]
35 -[assembly: AssemblyVersion("1.21.0.0")]  
36 -[assembly: AssemblyFileVersion("1.21.0.0")] 35 +[assembly: AssemblyVersion("1.22.0.0")]
  36 +[assembly: AssemblyFileVersion("1.22.0.0")]