Message becomes unreadable after setting string property (IBM MQ) - c#

I am trying to send MQ message from .NET application using amqmdnet library.
I put to queue simple message with two string properties like that:
var message = new MQMessage();
message.SetStringProperty("MessageID", Guid.NewGuid().ToString());
message.SetStringProperty("DocType", docTypeVal);
foreach (var b in content)
{
message.WriteByte(b);
}
var o = new MQPutMessageOptions();
var q = IBM_mqm.AccessQueue(ConnectionOptions.QueueNameOutput, MQC.MQOO_OUTPUT
+ MQC.MQOO_FAIL_IF_QUIESCING);
q.Put(message, o);
q.Close();
It works perfect when property "DocType" contains only latin symbols, digits and other general symbols.
message.SetStringProperty("DocType", "SomeEngText");
But when the property contains cyrillic symbols the message becomes unreadable. It's format becomes MQRFH2 despite the fact that I never set it. And named properties are empty.
message.SetStringProperty("DocType", "Договор купли продажи ТС");
When I am trying to read this message from my client an error 6106 MQRC_ENCODING_ERROR comes.
Some cyrillic values works fine (for example, "Кредитный договор"), but most of them breaks the message.
I tried to specify CCSID of the message like that:
message.CharacterSet = MQC.CODESET_UTF;
And also to set format:
message.Format = MQC.MQFMT_NONE;
But it didn't help.
How can I fix it?

Related

Keep optional pipe in HL7 after parsing

Original HL7
MSH|^~\&|RadImage^124|xxx|EI-ARTEFACT|xxx|123456789||ORM^O01|1234||2.3|||AL
PID|1|xxxxxx|xxxx||xxxxx^xxxxx xxxxx|xxx xxx|19391007|F|||104-430, xxx^^xxx^xx^xx^xx||(999)999-999|"||V|||||"||||||||"|N
PV1|1|A|11^11-1^^^^^2|||||123^xxx, xxx|||||||||123^xxx, xxx|||01|||||||||||||||||||NA|||||20191211082900|||||||
ORC|XO|"^"|xxx||CM||^^^xxx^^R||123456789|INTERF^INTERFACE||123^xxx, xxx|HOSPI^Hospitalisé|||KDICTE|3A^3A||"^"
OBR|1|"^"|xxx|82561^SCAN SINUS C+^^82561^SCAN SINUS C+|VU|xxx|"|"|||||"|||1234^xxx, xxx||xx|xxx|xxx|IMAGES^|xxxx||CT|"||^^^xxx^^VU||||AAAA~BBB~CCC|"^"||","~"|"|xxx|A|B|||
ZDS|1.11.11.11.1.11.1.1.11^RadImage^Application^DICOM
End result HL7
MSH|^~\&|RadImage^124|xxx|EI-ARTEFACT|xxx|123456789||ORM^O01|1234||2.3|||AL
PID|1|xxxxxx|xxxx||xxxxx^xxxxx xxxxx|xxx xxx|19391007|F|||104-430, xxx^^xxx^xx^xx^xx||(999)999-999|"||V|||||"||||||||"|N
PV1|1|A|11^11-1^^^^^2|||||123^xxx, xxx|||||||||123^xxx, xxx|||01|||||||||||||||||||NA|||||20191211082900
ORC|XO|"^"|xxx||CM||^^^xxx^^R||123456789|INTERF^INTERFACE||123^xxx, xxx|HOSPI^Hospitalisé|||KDICTE|3A^3A||"^"
OBR|1|"^"|xxx|82561^SCAN SINUS C+^^82561^SCAN SINUS C+|VU|xxx|"|"|||||"|||1234^xxx, xxx||xx|xxx|xxx|IMAGES^|xxxx||CT|"||^^^xxx^^VU||||AAAA~BBB~CCC|"^"||","~"|"|xxx|A|B|||
ZDS|1.11.11.11.1.11.1.1.11^RadImage^Application^DICOM
Hi,
I'm making a DLL in C# for parsing and modyfing a HL7 message using the nhapi Hl7 DLL.
The only thing I'm struggling to is to keep the empty pipe at the end of the PV1 segment. It'S removing the pipe in the "End result HL7" vs "Orginal HL7".
I would like to keep those pipe
This is my actual code
...
using NHapi.Base.Model;
using NHapi.Base.Parser;
using NHapi.Base.Util;
using System.Diagnostics;
using NHapi.Model.V23.Segment;
using NHapi.Model.V22.Segment;
using NHapi.Model.V21.Segment;
using NHapi.Model.V231.Segment;
...
...
public void PreAnalysis(ITratmContext ctx, MemBuf mb)
{
var parser = new PipeParser();
Debug.WriteLine(mb.ToString());
var parsedMessage = parser.Parse(mb.ToString());
var pipeDelimitedMessage = parser.Encode(parsedMessage);
Debug.WriteLine(pipeDelimitedMessage); //Message lose the empty pipe HERE
var genericMethod = parsedMessage as AbstractMessage;
// create a terser object instance by wrapping it around the message object
Terser terser = new Terser(parsedMessage);
OurTerserHelper terserHelper = new OurTerserHelper(terser);
String terserExpression = "MSH-12";
String HL7Version = terserHelper.GetData(terserExpression);
if (HL7Version == "2.3")
{
var obr = genericMethod.GetStructure("OBR") as NHapi.Model.V23.Segment.OBR;
if (obr != null)
{
for (int i = 0; i < obr.ReasonForStudyRepetitionsUsed; i++)
{
obr.GetReasonForStudy(i).Identifier.Value = StringExtention.Clean(obr.GetReasonForStudy(i).Identifier.ToString());
}
}
//var obrRep = obr.ReasonForStudyRepetitionsUsed;
Debug.WriteLine(parser.Encode(genericMethod.Message));
mb.Init(parser.Encode(genericMethod.Message));
}
}
Thank you very much !!!!
There is no need to keep any field separators after the last populated field in a segment. They are superfluous and a waste of space.
I don`t see a point in having a field separator after the last populated field. But if you insist on doing this you could you could append a custom separator at the end.

Body or Message Contains method using MailKit

I'm using MailKit for received messages via Imap.
Now I need a search-logic for the software and I got a some troubles.
For ex, I using:
var query = SearchQuery.BodyContains("SomeTextfromEmail");
( or var query = SearchQuery.MessageContains("SomeTextfromEmail"); )
foreach (UniqueId uid in imapfolder.Search(query)){
//some logic
}
So, I can't get messages with text contains on it with Search filter.
I'm downloaded message ( message.WriteTo(string.Format(#"C:{0}.eml", uid)); )
and see the message content. Text of message in a base-64 format.
How do it correctly? I need decode message text from base64?
Problem are here:
var query = SearchQuery.BodyContains("Iphone").And(SearchQuery.All); //this construction find messages in folder
foreach (var uid in imapfolder.Search(query))
{
Console.WriteLine(message.From + " : " + uid.ToString());
}
var query = SearchQuery.BodyContains("Received from Iphone").And(SearchQuery.All); //this construction can't find message in folder
foreach (var uid in imapfolder.Search(query))
{
Console.WriteLine(message.From + " : " + uid.ToString());
}
Your question is a jumbled mess of confusion (your question starts out saying you are trying to figure out how to search and then you end with asking how to base64 decode the raw message that you saved to a file) so I have no idea exactly what you want to know.
If all you want is the decoded text body, you can do this:
var message = imapfolder.GetMessage (uid);
var text = message.TextBody;
This will be the decoded text string (either base64 decoded or quoted-printable decoded if it needs to be).
The MimeKit README and FAQ are both full of useful information on the basics of how to use them. I would highly recommend reading them as they may be helpful.
Update:
Based on the comment added to my answer, it sounds like what you want to do is this?
var matched = new UniqueIdSet ();
foreach (var uid in folder.Search (SearchQuery.BodyContains ("iPhone"))) {
var message = folder.GetMessage (uid);
var body = message.TextBody;
if (body != null && body.Contains ("Received from iPhone"))
matched.Add (uid);
}

How do I use custom emojis?

I've been trying to use custom emojis in my embed messages but it didn't work
I tried using Emoji and even Emote but neither of them worked
var questionMark = new Emoji("<:questionmark:640216780689637390>");
await ReplyAsync($"{questionMark}");
If I do this it only displays the ":questionmark:" but not the emoji and I want the emoji to show up
Copy pasted from the docs
public async Task SendAndReactAsync(ISocketMessageChannel channel)
{
var message = await channel.SendMessageAsync("I am a message.");
// Creates a Unicode-based emoji based on the Unicode string.
// This is effectively the same as new Emoji("💕").
var heartEmoji = new Emoji("\U0001f495");
// Reacts to the message with the Emoji.
await message.AddReactionAsync(heartEmoji);
// Parses a custom emote based on the provided Discord emote format.
// Please note that this does not guarantee the existence of
// the emote.
var emote = Emote.Parse("<:thonkang:282745590985523200>");
// Reacts to the message with the Emote.
await message.AddReactionAsync(emote);
}
In Emoji class, you don't need to put "<" and ">". So your code should look like this
var questionMark = new Emoji(":questionmark:640216780689637390");
await ReplyAsync($"{questionMark}");

Domain Label contains illegal character ':'

I am using Sharp.XMPP library for FCM. I can connect fine and it receives Upstream messages without issues. However, sending ack back to server has a response of Error Code 400 with following details
<JIDMalformed xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" />
<text>"Malformed JID 'XXXXXX:XXXXXXXXXXXXX-XXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXX_XXXXX_XXXXX-XXXXXXXXXXXXXXXXXXX': domain label contains illegal character ':'"</text>
whereas the Xs replace the device registration token from which the Upstream message was received.
The code I'm using to form a message and send:
Sharp.Xmpp.Im.Message x = new Sharp.Xmpp.Im.Message(vFrom);
x.Data.SetAttribute("message_id", vMessageID);
x.Data.SetAttribute("message_type", "ack");
cl.SendMessage(x);
The string vFrom contains the device_token. I can not replace : as it is an essential part of device token and \: does not escape it either. What is the correct way of using colon in XML formats?
The issue here is that you've added Attributes to <data> tag whereupon they should be Elements to <gcm>
var msg = Xml.Element("message");
var elem = Xml.Element("gcm" ,"google:mobile:data"); //the gcm tag with xmlns attribute
Xml.Child(msg, elem); //assign child to message tag
var data = new {to = vFrom; message_id = vMessageID, message_type = "ack"};
JavaScriptSerializer serializer = new JavaScriptSerializer();
elem.Text(serializer.Serialize(data)); //not adding attributes
cl.SendMessage(new Sharp.Xmpp.Im.Message(new Sharp.Xmpp.Core.Message(data: elem)));
This here is an improved version of Sharp.XMPP for FCM. It includes the class Sharp.Xmpp.Core.Message that is probably not committed to github. This might help clarify.

C# & XLW 5 - how to raise an exception with sensible error message displayed in Excel?

Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something goes wrong, and I am trying to propagate an exception message to Excel.
When i use throw new Exception("Message"), Excel just shows "System.Exception : " as the message back is sent on a number of lines and the message is cut off as the cell shows only the top line.
How to propagate the error message to Excel and disable all other text, i.e. to show just "Message" and not "System.Exception xxxxx" pls?
You should use
private static cellMatrixException ReportMessage(string errorMessage, string mainCategory, string minorCategory)
{
var theContent = new ArgumentList(mainCategory);
theContent.add(minorCategory, errorMessage);
return new cellMatrixException(errorMessage, theContent.AllData());
}
See my solution at http://jiripik.me/2012/06/17/project-financialdataforexcel and the source code at http://assembla.com/spaces/FinancialDataForExcel/wiki.

Categories