Example #1
0
 private void SetAttribute(string namespaceUri, string localName, string value, bool isIdAttribute)
 {
     lock (_document)
     {
         XmlQName xmlQName = new XmlQName(this, namespaceUri, localName);
         if (xmlQName.HasLocalNamespace())
         {
             if (_element.HasAttribute(xmlQName.LocalName))
             {
                 _element.Attributes.RemoveNamedItem(xmlQName.LocalName);
             }
             _element.SetAttribute(xmlQName.LocalName, null, value);
             //if (isIdAttribute)
             //{
             //    _element.SetAttribute(xmlQName.LocalName, null);
             //}
         }
         else
         {
             if (_element.HasAttribute(xmlQName.PrefixedName))
             {
                 _element.Attributes.RemoveNamedItem(xmlQName.PrefixedName);
             }
             _element.SetAttribute(xmlQName.PrefixedName, xmlQName.NamespaceUri, value);
             //if (isIdAttribute)
             //{
             //    _element.SetAttribute(xmlQName.LocalName, xmlQName.NamespaceUri, null);
             //}
         }
     }
 }
Example #2
0
 public virtual string GetAttribute(string namespaceUri, string localName)
 {
     lock (_document)
     {
         XmlQName xmlQName = new XmlQName(this, namespaceUri, localName);
         string   value;
         if (xmlQName.HasLocalNamespace())
         {
             //value = element.GetAttribute( xmlQName.LocalName, null);
             value = _element.GetAttribute(xmlQName.LocalName, xmlQName.NamespaceUri);
         }
         else
         {
             value = _element.GetAttribute(xmlQName.LocalName);
         }
         if (value.Length == 0)
         {
             return(null);
         }
         else
         {
             return(value);
         }
     }
 }
Example #3
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);
        }
Example #4
0
 public virtual IDomElement CreateElement(string namespaceUri, string localName)
 {
     lock (_document)
     {
         XmlQName   xmlQName = new XmlQName(this, namespaceUri, localName);
         XmlElement element  = _document.CreateElement(xmlQName.PrefixedName, xmlQName.NamespaceUri);
         return(new DomElementImpl(element));
     }
 }
Example #5
0
 public virtual DomElement createElement(string namespaceUri, string localName)
 {
     lock (document)
     {
         XmlQName xmlQName = new XmlQName(this, namespaceUri, localName);
         Element  element  = document.createElementNS(xmlQName.NamespaceUri, xmlQName.PrefixedName);
         return(new DomElementImpl(element));
     }
 }
        // 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);
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        /// <param name="resolver"></param>
        /// <param name="resolution"></param>
        /// <returns></returns>
        private static Dictionary <string, string> ResolveStatic(XLANGMessage message)
        {
            Dictionary <string, string> resolverDictionary = new Dictionary <string, string>();
            string        result        = null;
            StringWriter  stringWriter  = null;
            XmlTextWriter xmlTextWriter = null;

            try
            {
                stringWriter             = new StringWriter();
                xmlTextWriter            = new XmlTextWriter(stringWriter);
                xmlTextWriter.Formatting = Formatting.Indented;
                xmlTextWriter.WriteStartDocument();
                xmlTextWriter.WriteStartElement("ContextProperties");

                foreach (DictionaryEntry dictionary in GetContext(message))
                {
                    XmlQName qName = (XmlQName)dictionary.Key;
                    xmlTextWriter.WriteStartElement("Property");
                    xmlTextWriter.WriteAttributeString("name", qName.Name);
                    xmlTextWriter.WriteAttributeString("namespace", qName.Namespace);
                    xmlTextWriter.WriteString(dictionary.Value.ToString());
                    xmlTextWriter.WriteEndElement();
                }
                xmlTextWriter.WriteFullEndElement();
                xmlTextWriter.WriteEndDocument();
                result = stringWriter.ToString();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (xmlTextWriter != null)
                {
                    xmlTextWriter.Close();
                }
                if (stringWriter != null)
                {
                    stringWriter.Close();
                    stringWriter.Dispose();
                }
            }

            resolverDictionary.Add("MessageContext", result);

            return(resolverDictionary);
        }
Example #8
0
 public virtual void RemoveAttribute(string namespaceUri, string localName)
 {
     lock (_document)
     {
         XmlQName xmlQName = new XmlQName(this, namespaceUri, localName);
         if (xmlQName.HasLocalNamespace())
         {
             _element.RemoveAttribute(xmlQName.LocalName, null);
         }
         else
         {
             _element.RemoveAttribute(xmlQName.LocalName, xmlQName.NamespaceUri);
         }
     }
 }
Example #9
0
        /// <summary>
        /// Handle fault
        /// </summary>
        /// <param name="xlangMsg"></param>
        /// <param name="faultType"></param>
        public static void HandleFault(XLANGMessage xlangMsg, string btsMsgType, FaultType faultType)
        {
            string eventMessage       = string.Empty;
            string serviceName        = string.Empty;
            string serviceType        = string.Empty;
            string transportLocation  = string.Empty;
            string transportDirection = string.Empty;
            string description        = string.Empty;
            Stream faultStream        = null;;

            try
            {
                faultStream = (Stream)xlangMsg[0].RetrieveAs(typeof(Stream));

                if (faultType == FaultType.DeliveryException)
                {
                    serviceName = GetMsgProperty(xlangMsg, typeof(ErrorReport.SendPortName));
                    description = GetMsgProperty(xlangMsg, typeof(ErrorReport.Description));
                    if (!string.IsNullOrEmpty(serviceName))
                    {
                        serviceType        = "Send";
                        transportLocation  = GetMsgProperty(xlangMsg, typeof(ErrorReport.OutboundTransportLocation)).ToString();
                        transportDirection = "Outbound";
                    }
                    else
                    {
                        serviceName        = GetMsgProperty(xlangMsg, typeof(ErrorReport.ReceivePortName));
                        serviceType        = "Receive";
                        transportLocation  = GetMsgProperty(xlangMsg, typeof(ErrorReport.InboundTransportLocation));
                        transportDirection = "Inbound";
                    }

                    eventMessage = String.Format("A message of type '{0}' could not be routed by BizTalk.", btsMsgType) + Environment.NewLine +
                                   String.Format("{0} Port = {1}", serviceType, serviceName) + Environment.NewLine +
                                   String.Format("{0} Transport Location = {1}", transportDirection, transportLocation) + Environment.NewLine +
                                   description;
                }
                else if (faultType == FaultType.SoapException)
                {
                    serviceName       = GetMsgProperty(xlangMsg, typeof(BTS.SPName));
                    transportLocation = GetMsgProperty(xlangMsg, typeof(BTS.InboundTransportLocation));

                    eventMessage = "A SOAP Fault message was encountered by BizTalk." + Environment.NewLine +
                                   String.Format("Send Port = {0}", serviceName) + Environment.NewLine +
                                   String.Format("Outbound Transport Location = {0}", transportLocation) + Environment.NewLine + Environment.NewLine +
                                   "Refer 'FaultMsgBody' node in the archived message for more details.";
                }
                else
                {
                    serviceName = GetMsgProperty(xlangMsg, typeof(Microsoft.BizTalk.XLANGs.BTXEngine.SendingOrchestrationType));
                    serviceName = serviceName.Contains(",") ? serviceName.Substring(0, serviceName.IndexOf(",")) : serviceName;

                    eventMessage = "A System Exception was encountered by BizTalk " + Environment.NewLine +
                                   String.Format("Orchestration Name = {0}", serviceName) + Environment.NewLine + Environment.NewLine +
                                   "Refer 'FaultMsgBody' node in the archived message for more details.";
                }

                eventMessage += Environment.NewLine + Environment.NewLine + "================= Archived Message =================" + Environment.NewLine + Environment.NewLine;

                StreamReader reader = new StreamReader(faultStream);
                eventMessage += reader.ReadToEnd() + Environment.NewLine;

                eventMessage += Environment.NewLine + "================= Context Properties =================" + Environment.NewLine;

                foreach (DictionaryEntry dictionary in GetContext(xlangMsg))
                {
                    XmlQName qName = (XmlQName)dictionary.Key;
                    eventMessage += qName.Namespace + "#" + qName.Name + " : " + dictionary.Value.ToString() + Environment.NewLine;
                }

                EsbFaultEvent faultEvent = ExceptionEventDetails.Instance.ExceptionEvents.FirstOrDefault <EsbFaultEvent>
                                               (e => e.FaultSvcName.Equals(serviceName, StringComparison.OrdinalIgnoreCase) &&
                                               e.FaultType.Equals(faultType.ToString(), StringComparison.OrdinalIgnoreCase));

                if (faultEvent != null)
                {
                    Logger.WriteEvent(faultEvent.EventSource, eventMessage, (EventLogEntryType)Enum.Parse(typeof(EventLogEntryType), faultEvent.EventType), faultEvent.EventId);
                }
                else
                {
                    throw new Exception(string.Format("'{0}' fault is not configured for the service '{1}' in [AvistaESBLookup].[dbo].[EsbFaultEvents] table", faultType.ToString(), serviceName));
                }
            }
            catch (Exception ex)
            {
                eventMessage = "A Fault was encountered by BizTalk and a further error occurred while handling the message. " + Environment.NewLine + "Error Details: " + ex.ToString()
                               + Environment.NewLine + Environment.NewLine + "Original Fault Details: " + Environment.NewLine + eventMessage;

                Logger.WriteError(eventMessage, 14004);
            }
            finally
            {
                if (xlangMsg != null)
                {
                    xlangMsg.Dispose();
                    xlangMsg = null;
                }
                if (faultStream != null)
                {
                    faultStream = null;
                }
            }
        }
Example #10
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();
                }
            }
        }