Exemple #1
0
        /// <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);
        }
Exemple #2
0
 public static Stream AsStream(this XLANGPart messagePart)
 {
     if (messagePart == null)
     {
         throw new ArgumentNullException(nameof(messagePart));
     }
     return((Stream)messagePart.RetrieveAs(typeof(Stream)));
 }
Exemple #3
0
        /// <summary>
        /// Gets the target namespace for the specified part of an XLANG message.
        /// </summary>
        /// <param name="msg">The XLANG message.</param>
        /// <param name="partNumber">The part number.</param>
        /// <returns>The target namespace.</returns>
        public static string GetNamespace(XLANGMessage msg, int partNumber)
        {
            XLANGPart part = msg[partNumber];

            System.Xml.Schema.XmlSchema sch = part.XmlSchema;
            if (sch == null)
            {
                return(String.Empty);
            }
            else
            {
                return(sch.TargetNamespace);
            }
        }
 public static Stream AsStream(this XLANGPart messagePart)
 {
     return((Stream)messagePart.RetrieveAs(typeof(Stream)));
 }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="xLangMessage"></param>
        /// <param name="tag"></param>
        /// <param name="autoDispose"></param>
        public ArchiveBizTalkMessage(XLANGMessage xLangMessage, ArchiveTag tag, bool autoDispose = true)
        {
            this.Message           = new Message();
            this.MessageProperties = new List <MessageProperty>();
            this.Parts             = new List <Part>();
            this.PartsProperties   = new List <PartProperty>();

            Guid messageId = Guid.NewGuid();

            try
            {
                if (xLangMessage is MessageWrapperForUserCode)
                {
                    //-------------------------------------------------------------------------
                    // Add Message.
                    //-------------------------------------------------------------------------
                    this.Message.MessageId = messageId;
                    if (tag.ArchiveType.Id >= 0)
                    {
                        this.Message.ArchiveTypeId = tag.ArchiveType.Id;
                    }

                    this.Message.Tag = tag.Tag;

                    if (tag.SourceSystem.Id >= 0)
                    {
                        this.Message.SourceSystemId = tag.SourceSystem.Id;
                    }

                    if (tag.TargetSystem.Id >= 0)
                    {
                        this.Message.TargetSystemId = tag.TargetSystem.Id;
                    }

                    this.Message.Description  = tag.Description;
                    this.Message.InsertedDate = DateTime.UtcNow;

                    Type messageWrapperType = typeof(MessageWrapperForUserCode);
                    msgUnwrapMethod = messageWrapperType.GetMethod("Unwrap", BindingFlags.Instance | BindingFlags.NonPublic);

                    MessageWrapperForUserCode messageWrapper = (MessageWrapperForUserCode)xLangMessage;
                    XMessage xMessage = (XMessage)(msgUnwrapMethod.Invoke(messageWrapper, null));

                    if (xMessage != null)
                    {
                        try
                        {
                            //-------------------------------------------------------------------------
                            // Add the parts.
                            //-------------------------------------------------------------------------
                            int partCount = xLangMessage.Count;
                            for (int partIndex = 0; partIndex < partCount; partIndex++)
                            {
                                XLANGPart part = xLangMessage[partIndex];
                                try
                                {
                                    Part prt = GetMessagePart(messageId, partIndex, xMessage, part);
                                    if (prt != null)
                                    {
                                        this.Parts.Add(prt);
                                        //-------------------------------------------------------------------------
                                        // Add the parts properties.
                                        //-------------------------------------------------------------------------
                                        List <PartProperty> prtProperties = GetPartProperties(prt.PartId, part);
                                        foreach (PartProperty p in prtProperties)
                                        {
                                            this.PartsProperties.Add(p);
                                        }
                                    }
                                }
                                finally
                                {
                                    // part is actually a PartWrapperForUserCode. Calling its Dispose method causes
                                    // the PartWrapperForUserCode to be detached from the owning MessageWrapperForUserCode.
                                    part.Dispose();
                                }
                            }
                            //-------------------------------------------------------------------------
                            // Add the message properties.
                            //-------------------------------------------------------------------------
                            Hashtable propertyHashTable = xMessage.GetContextProperties();
                            if (propertyHashTable != null)
                            {
                                XmlQNameTable   propertyTable = new XmlQNameTable(propertyHashTable);
                                int             propertyIndex = 0;
                                MessageProperty msgProperties = new MessageProperty();
                                msgProperties.MessageId = messageId;
                                XElement      ContextData             = new XElement("ContextData");
                                List <string> listOfContextProperties = new List <string>();
                                listOfContextProperties = GetListOfContextProperties();
                                foreach (DictionaryEntry property in propertyTable)
                                {
                                    XmlQName qName = (XmlQName)property.Key;

                                    if (listOfContextProperties.Contains(qName.Name))
                                    {
                                        ContextData.Add(
                                            new XElement("Property", new XAttribute("Name", qName.Name),
                                                         new XAttribute("Namespace", qName.Namespace),
                                                         new XAttribute("Value", property.Value.ToString())));
                                    }

                                    if (qName.Namespace == "http://schemas.microsoft.com/BizTalk/2003/system-properties")
                                    {
                                        if (qName.Name == "InterchangeID")
                                        {
                                            string value = property.Value.ToString().Trim();
                                            this.Message.InterchangeId = GetGUIDWithoutBraces(value);
                                        }
                                        else if (qName.Name == "MessageType")
                                        {
                                            this.Message.MessageType = property.Value.ToString();
                                        }
                                    }
                                    else if (qName.Namespace == "http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties")
                                    {
                                        if (qName.Name == "ActivityIdentity")
                                        {
                                            string value = property.Value.ToString().Trim();
                                            this.Message.ActivityId = GetGUIDWithoutBraces(value);
                                        }
                                    }
                                    propertyIndex++;
                                }
                                msgProperties.ContextData = ContextData.ToString();
                                this.MessageProperties.Add(msgProperties);
                                // If the message type is still unknown, try to get it from part[0].
                                if (string.IsNullOrEmpty(this.Message.MessageType) || this.Message.MessageType == "Unknown")
                                {
                                    if (!string.IsNullOrEmpty(partType))
                                    {
                                        this.Message.MessageType = partType;
                                    }
                                }
                            }
                        }
                        finally
                        {
                            // When the MessageWrapperForUserCode is unrwapped the reference count
                            // for the message is incremented, so we must release it now.
                            xMessage.Release();
                        }
                    }
                    else
                    {
                        throw new Exception("Could not unwrap XMessage from MessageWrapperForUserCode.");
                    }
                }
                else
                {
                    throw new Exception("Expected XLANGMessage to be a MessageWrapperForUserCode. " + xLangMessage.GetType().FullName + " is not a recognized XLANGMessage type.");
                }
            }
            catch (Exception ex)
            {
                Logger.WriteTrace(string.Format("Error constructing BizTalkMessage from XLangMessage {0} \r\n Details: {1}", this.GetType().Name, ex.ToString()));
                throw ex;
            }
            finally
            {
                if (autoDispose)
                {
                    xLangMessage.Dispose();
                }
            }
        }
Exemple #6
0
        /// <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);
        }
 public override void AddPart(XLANGPart part)
 {
     throw new NotImplementedException();
 }