Re: Hi..I have a challenge with context to be saved to a file on file system

Home Page Forums BizTalk 2004 – BizTalk 2010 Hi..I have a challenge with context to be saved to a file on file system Re: Hi..I have a challenge with context to be saved to a file on file system

#18829

Hi.

 I am so happy now! We have done this!

We get a message from an orchestration “as is” and get it’s context as a separate XML file which is saved in a file system,in a case we get a catch (in an attempt to get as much information about “Dead Message” as we can).

 Here is the code :

#region

GetMsgContextFile//a method where we get public static XmlDocument GetMsgContextFile(IBaseMessageContext con)

{

string propName, propNs, propValue;StringBuilder ctxFile = new StringBuilder();

ctxFile.AppendFormat(

“<MessageInfo><ContextInfo PropertiesCount=\”{0}\”>”, con.CountProperties.ToString());for (int i = 0; i < con.CountProperties; i++)

{

propValue = System.Convert.ToString(con.ReadAt(i, out propName, out propNs));

propValue=propValue.Replace(

“<“, “&lt;”);propValue=propValue.Replace(“>”, “&gt;”);

propValue=propValue.Replace(

“\””, “&quot;”);ctxFile.AppendFormat(“<Property Name=\”{0}\” Namespace=\”{1}\” Value=\”{2}\” />”, propName, propNs, propValue);

}

ctxFile.Append(“</ContextInfo></MessageInfo>”);XmlDocument xDoc = new XmlDocument();

xDoc.LoadXml(ctxFile.ToString());

return xDoc;

}

 public static XmlDocument CreateContextDoc(XLANGMessage inputMessage)

{

XMessage inputXMessage;

MethodInfo myMethodInfo = inputMessage.GetType().GetMethod(“Unwrap”, BindingFlags.Instance | BindingFlags.NonPublic);inputXMessage = (XMessage)(myMethodInfo.Invoke(inputMessage, null));

Hashtable contextHashTable = inputXMessage.GetContextProperties();IDictionaryEnumerator contextEnumerator = contextHashTable.GetEnumerator();

 

string propName=string.Empty;

string propNs = string.Empty;string propValue = string.Empty;

XmlQName key;StringBuilder ctxStringBuilder = new StringBuilder();ctxStringBuilder.AppendFormat(“<MessageInfo><ContextInfo PropertiesCount=\”{0}\”>”, contextHashTable.Count.ToString());

 

while (contextEnumerator.MoveNext())

{

propValue = contextEnumerator.Value.ToString();

key = (XmlQName)contextEnumerator.Key;

propNs = key.Namespace;

propName = key.Name;

//This lines we need ’cause “<“, “>”, and ‘  ”  ‘ characters are not displayed well inside of XML (which are attributes : “XML-in-XML”)

propValue = propValue.Replace(“<“, “&lt;”);

propValue = propValue.Replace(

“>”, “&gt;”);propValue = propValue.Replace(“\””, “&quot;”);ctxStringBuilder.AppendFormat(“<Property Name=\”{0}\” Namespace=\”{1}\” Value=\”{2}\” />”, propName, propNs, propValue);

}

ctxStringBuilder.Append(“</ContextInfo></MessageInfo>”);

 

XmlDocument ctxXDoc = new XmlDocument();

ctxXDoc.LoadXml(ctxStringBuilder.ToString());

//FInal Xml-Document with context only

return ctxXDoc;

}