示例#1
0
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            String value   = null;
            bool   suspend = false;

            IBaseMessagePart bodyPart = pInMsg.BodyPart;



            Stream                 inboundStream          = bodyPart.GetOriginalDataStream();
            VirtualStream          virtualStream          = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk);
            ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream);

            XmlTextReader   xmlTextReader   = new XmlTextReader(readOnlySeekableStream);
            XPathCollection xPathCollection = new XPathCollection();
            XPathReader     xPathReader     = new XPathReader(xmlTextReader, xPathCollection);

            xPathCollection.Add(XPath);

            while (xPathReader.ReadUntilMatch())
            {
                if (xPathReader.Match(0))
                {
                    if (xPathReader.NodeType == XmlNodeType.Attribute)
                    {
                        value = xPathReader.GetAttribute(xPathReader.Name);
                    }
                    else
                    {
                        value = xPathReader.ReadString();
                    }

                    break;
                }
            }


            suspend = ScriptExpressionHelper.ValidateExpression(value, Expression);

            if (suspend)
            {
                readOnlySeekableStream.Position = 0;
                pContext.ResourceTracker.AddResource(readOnlySeekableStream);
                bodyPart.Data = readOnlySeekableStream;
                pInMsg.Context.Write("SuspendAsNonResumable", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);
                pInMsg.Context.Write("SuppressRoutingFailureDiagnosticInfo", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);

                throw new Exception(String.Format("Expression {0} {1} did not evaluate to true", value, Expression));
            }
            else
            {
                pInMsg = null;
            }


            return(pInMsg);
        }
        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            IBaseMessagePart bodyPart = pInMsg.BodyPart;

            bool   found      = false;
            string value      = string.Empty;
            string evalString = string.Empty;

            Stream                 inboundStream          = bodyPart.GetOriginalDataStream();
            VirtualStream          virtualStream          = new VirtualStream(VirtualStream.MemoryFlag.AutoOverFlowToDisk);
            ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream);

            XmlTextReader   xmlTextReader   = new XmlTextReader(readOnlySeekableStream);
            XPathCollection xPathCollection = new XPathCollection();
            XPathReader     xPathReader     = new XPathReader(xmlTextReader, xPathCollection);

            int lastxpath = XPath.LastIndexOf("][");

            if (lastxpath > -1)
            {
                evalString = XPath.Substring(lastxpath + 2, XPath.LastIndexOf(']') - (lastxpath + 2));
                XPath      = XPath.Substring(0, lastxpath + 1);

                if (evalString.Contains("text(") || evalString.Contains("number("))
                {
                    evalString = evalString.Substring(evalString.IndexOf(')') + 1);
                }

                evalString = replaceHTMLOpearators(evalString);

                if (evalString.Contains(" = "))//c# equal sign
                {
                    evalString = evalString.Replace("=", "==");
                }
            }

            xPathCollection.Add(XPath);

            while (xPathReader.ReadUntilMatch())
            {
                if (xPathReader.Match(0))
                {
                    if (evalString != string.Empty)
                    {
                        if (xPathReader.NodeType == XmlNodeType.Attribute)
                        {
                            value = xPathReader.GetAttribute(xPathReader.Name);
                        }
                        else
                        {
                            value = xPathReader.ReadString();
                        }

                        string literal = String.Empty;
                        if (evalString.Contains("'"))
                        {
                            literal    = "\"";
                            evalString = evalString.Replace("'", "\"");
                        }

                        found = ScriptExpressionHelper.ValidateExpression(String.Format("{0}{1}{0}", literal, value), evalString);
                    }
                    else
                    {
                        found = true;
                    }



                    break;
                }
            }

            readOnlySeekableStream.Seek(0, SeekOrigin.Begin);
            pInMsg.BodyPart.Data = readOnlySeekableStream;

            if (found)
            {
                pInMsg = null;
            }


            return(pInMsg);
        }