// This is the actuall method retrieving properties from the context.
        private object GetMsgCtxProperty(string contextMessage, string contextItemName, string contextItemNamespace)
        {
            object retval = null;

            try
            {
                // get the service parent of the context
                foreach (Microsoft.XLANGs.Core.Segment segment in Service.RootService._segments)
                {
                    // find the real name of the message
                    IDictionary fields = Context.FindFields(typeof(XLANGMessage), segment.ExceptionContext);
                    foreach (DictionaryEntry ctxfield in fields)
                    {
                        string field = ctxfield.Key.ToString();
                        if (field.EndsWith(contextMessage))
                        {
                            // get the XMessage object
                            XMessage xmsg = ctxfield.Value as XMessage;
                            // get the value of the property if the message was found
                            if (xmsg != null)
                            {
                                // create a XmlQName instance
                                XmlQName qName = new XmlQName(contextItemName, contextItemNamespace);
                                // find the message property in the message
                                if (xmsg.GetContextProperties().ContainsKey(qName))
                                {
                                    // get the property from GetContextProperties
                                    retval = xmsg.GetContextProperties()[qName];
                                }
                                else if (xmsg.GetContentProperties().ContainsKey(qName))
                                {
                                    // get the property from GetContentProperties
                                    retval = xmsg.GetContentProperties()[qName];
                                }
                            }
                            goto exit;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // If an exception occurs while retrieving the interface to the context or
                // accessing the properties with that interface, we ignore the failure and
                // force the retval to null.  In addition, the error is wrote in Trace
                Trace.WriteLine(string.Format("OrchContextAccessor functoid has failed, message: {0}... stack: {1}", e.Message, e.StackTrace));
                retval = null;
            }
exit:
            // return the value
            return(retval);
        }
Exemple #2
0
        /// <summary>
        /// Gets all message context properties assocciated with xlang message
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private static Hashtable GetContext(XLANGMessage message)
        {
            try
            {
                foreach (Segment segment in Service.RootService._segments)
                {
                    IDictionary fields = Context.FindFields(typeof(XLANGMessage), segment.ExceptionContext);

                    foreach (DictionaryEntry field in fields)
                    {
                        XMessage msg = (field.Value as XMessage);
                        if (msg == null)
                        {
                            continue;
                        }

                        if (String.Compare(msg.Name, message.Name) != 0)
                        {
                            continue;
                        }

                        return(msg.GetContextProperties());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteWarning(ex.ToString(), 14000);
            }
            return(new Hashtable());
        }
        public static Hashtable GetContext(XLANGMessage message)
        {
            try
            {
                foreach (Segment segment in Service.RootService._segments)
                {
                    IDictionary fields = Context.FindFields(typeof(XLANGMessage), segment.ExceptionContext);

                    foreach (DictionaryEntry field in fields)
                    {
                        XMessage msg = (field.Value as XMessage);
                        if (msg == null)
                        {
                            continue;
                        }

                        if (String.Compare(msg.Name, message.Name) != 0)
                        {
                            continue;
                        }

                        return(msg.GetContextProperties());
                    }
                }
            }
            catch (Exception ex /* e */)
            {
                throw new Exception(ex.InnerException.ToString());
            }

            return(new Hashtable());
        }
Exemple #4
0
        /// <summary>
        /// Gets all message context properties assocciated with xlang message
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        private static Hashtable GetContext(XLANGMessage message)
        {
            foreach (Segment segment in Service.RootService._segments)
            {
                IDictionary fields = Microsoft.XLANGs.Core.Context.FindFields(typeof(XLANGMessage), segment.ExceptionContext);

                foreach (DictionaryEntry field in fields)
                {
                    XMessage msg = (field.Value as XMessage);
                    if (msg == null)
                    {
                        continue;
                    }

                    if (String.Compare(msg.Name, message.Name) != 0)
                    {
                        continue;
                    }

                    return(msg.GetContextProperties());
                }
            }
            return(new Hashtable());
        }
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();
                }
            }
        }