/// <summary> /// Gets Part Properties from XLANGPart /// </summary> /// <param name="partId"></param> /// <param name="part"></param> /// <returns></returns> private List <PartProperty> GetPartProperties(Guid partId, XLANGPart part) { List <PartProperty> prtProperties = new List <PartProperty>(); if (part is PartWrapperForUserCode) { PartWrapperForUserCode partWrapper = (PartWrapperForUserCode)part; Microsoft.XLANGs.Core.Part xPart = (Microsoft.XLANGs.Core.Part)(partUnwrapMethod.Invoke(partWrapper, null)); if (xPart != null) { XmlQNameTable propertyTable = xPart.GetPartProperties(); if (propertyTable != null) { int propertyIndex = 0; foreach (DictionaryEntry property in propertyTable) { XmlQName qName = (XmlQName)property.Key; PartProperty prtProp = new PartProperty(); prtProp.PartId = partId; prtProp.PropertyIndex = propertyIndex; prtProp.Name = qName.Name; prtProp.Namespace = qName.Namespace; prtProp.Value = property.Value.ToString(); propertyIndex++; prtProperties.Add(prtProp); } } } } return(prtProperties); }
/// <summary> /// Gets Message Part from XLANGMessage /// </summary> /// <param name="messageId"></param> /// <param name="partIndex"></param> /// <param name="xMessage"></param> /// <param name="part"></param> /// <returns></returns> private Part GetMessagePart(Guid messageId, int partIndex, XMessage xMessage, XLANGPart part) { Part prt = null; if (part != null) { prt = new Part(); prt.PartId = Guid.NewGuid(); prt.MessageId = messageId; prt.PartIndex = partIndex; prt.PartName = part.Name; prt.CharSet = "UTF-8"; if (part is PartWrapperForUserCode) { Type partWrapperType = typeof(PartWrapperForUserCode); partUnwrapMethod = partWrapperType.GetMethod("Unwrap", BindingFlags.Instance | BindingFlags.NonPublic); PartWrapperForUserCode partWrapper = (PartWrapperForUserCode)part; Microsoft.XLANGs.Core.Part xPart = (Microsoft.XLANGs.Core.Part)(partUnwrapMethod.Invoke(partWrapper, null)); if (xPart != null) { try { try { XmlDocument contentAsXmlDocument = (XmlDocument)part.RetrieveAs(typeof(XmlDocument)); if (contentAsXmlDocument != null) { prt.TextData = contentAsXmlDocument.OuterXml; prt.ContentType = "text/xml"; partType = MessageHelper.GetMessageType(contentAsXmlDocument); } } catch (Exception) { using (Stream partStream = (Stream)part.RetrieveAs(typeof(Stream))) { using (StreamReader streamReader = new StreamReader(partStream)) { prt.TextData = streamReader.ReadToEnd(); prt.ContentType = "text/plain"; partType = "FlatFile"; } } } } finally { // When the PartWrapperForUserCode is unrwapped the reference count for the // owning message is incremented, so we must release it now. xMessage.Release(); } } else { throw new Exception("Could not unwrap Part from PartWrapperForUserCode."); } } else { throw new Exception("Error constructing BizTalkMessagePart. Expected XLANGPart to be a PartWrapperForUserCode. " + part.GetType().FullName + " is not a recognized XLANGPart type."); } } return(prt); }