コード例 #1
0
        // Assumes that the reader is current parked at the filter's start tag
        void ReadFrom(XmlReader reader, XmlNamespaceManager namespaces)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }

            if (!reader.IsStartElement())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("reader", SR.GetString(SR.FilterReaderNotStartElem));
            }

            bool   found   = false;
            string dialect = null;

            while (reader.MoveToNextAttribute())
            {
                if (QueryDataModel.IsAttribute(reader.NamespaceURI))
                {
                    if (found || reader.LocalName != DialectAttr || reader.NamespaceURI != WSEventingNamespace)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.FilterInvalidAttribute)));
                    }
                    dialect = reader.Value;
                    found   = true;
                }
            }
            if (reader.NodeType == XmlNodeType.Attribute)
            {
                reader.MoveToElement();
            }

            if (dialect != null && dialect != XPathDialect)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.FilterInvalidDialect, XPathDialect)));
            }

            bool wasEmpty = reader.IsEmptyElement;

            reader.ReadStartElement();

            if (wasEmpty)
            {
                this.Init(string.Empty, namespaces);
            }
            else
            {
                ReadXPath(reader, namespaces);
                reader.ReadEndElement();
            }
        }
コード例 #2
0
        private void ReadFrom(XmlReader reader, XmlNamespaceManager namespaces)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }
            if (!reader.IsStartElement())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("reader", System.ServiceModel.SR.GetString("FilterReaderNotStartElem"));
            }
            bool   flag = false;
            string str  = null;

            while (reader.MoveToNextAttribute())
            {
                if (QueryDataModel.IsAttribute(reader.NamespaceURI))
                {
                    if ((flag || (reader.LocalName != "Dialect")) || (reader.NamespaceURI != "http://schemas.xmlsoap.org/ws/2004/06/eventing"))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("FilterInvalidAttribute")));
                    }
                    str  = reader.Value;
                    flag = true;
                }
            }
            if (reader.NodeType == XmlNodeType.Attribute)
            {
                reader.MoveToElement();
            }
            if ((str != null) && (str != "http://www.w3.org/TR/1999/REC-xpath-19991116"))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("FilterInvalidDialect", new object[] { "http://www.w3.org/TR/1999/REC-xpath-19991116" })));
            }
            bool isEmptyElement = reader.IsEmptyElement;

            reader.ReadStartElement();
            if (isEmptyElement)
            {
                this.Init(string.Empty, namespaces);
            }
            else
            {
                this.ReadXPath(reader, namespaces);
                reader.ReadEndElement();
            }
        }
コード例 #3
0
        protected virtual void OnReadXml(XmlReader reader)
        {
            if (reader == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }
            if (!reader.IsStartElement())
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("reader", System.ServiceModel.SR.GetString("FilterReaderNotStartElem"));
            }
            if (reader.IsEmptyElement)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("reader", System.ServiceModel.SR.GetString("FilterInvalidInner", new object[] { "XPath" }));
            }
            string s = null;

            while (reader.MoveToNextAttribute())
            {
                if ((QueryDataModel.IsAttribute(reader.NamespaceURI) && (reader.LocalName == "NodeQuota")) && (reader.NamespaceURI.Length == 0))
                {
                    s = reader.Value;
                    break;
                }
            }
            if (reader.NodeType == XmlNodeType.Attribute)
            {
                reader.MoveToElement();
            }
            int num = (s == null) ? 0x7fffffff : int.Parse(s, NumberFormatInfo.InvariantInfo);

            reader.ReadStartElement();
            reader.MoveToContent();
            if (reader.LocalName != "XPath")
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("reader", System.ServiceModel.SR.GetString("FilterInvalidInner", new object[] { "XPath" }));
            }
            this.ReadFrom(reader, new XPathMessageContext());
            reader.MoveToContent();
            reader.ReadEndElement();
            this.NodeQuota = num;
        }
コード例 #4
0
ファイル: XPathParser.cs プロジェクト: dox0/DotNet471RS3
        NodeSelectCriteria ParseNodeTest(QueryAxisType axisType)
        {
            Fx.Assert(QueryAxisType.None != axisType, "");

            QueryAxis  axis = QueryDataModel.GetAxis(axisType);
            XPathToken token;
            NodeQName  qname = NodeQName.Empty;

            if (null != (token = this.NextTokenClass(XPathTokenID.NameTest)))
            {
                switch (token.TokenID)
                {
                default:
                    this.ThrowError(QueryCompileError.UnexpectedToken);
                    break;

                case XPathTokenID.Wildcard:
                    qname = new NodeQName(QueryDataModel.Wildcard, QueryDataModel.Wildcard);
                    break;

                case XPathTokenID.NameTest:
                    qname = this.QualifyName(token.Prefix, token.Name);
                    break;

                case XPathTokenID.NameWildcard:
                    qname = this.QualifyName(token.Prefix, QueryDataModel.Wildcard);
                    break;
                }
            }

            QueryNodeType nodeType = QueryNodeType.Any;

            if (qname.IsEmpty)
            {
                // Check for nodeTests
                if (null == (token = this.NextTokenClass(XPathTokenID.NodeType)))
                {
                    // Not a NodeTest either.
                    return(null);
                }

                switch (token.TokenID)
                {
                default:
                    this.ThrowError(QueryCompileError.UnsupportedNodeTest);
                    break;

                case XPathTokenID.Comment:
                    nodeType = QueryNodeType.Comment;
                    break;

                case XPathTokenID.Text:
                    nodeType = QueryNodeType.Text;
                    break;

                case XPathTokenID.Processing:
                    nodeType = QueryNodeType.Processing;
                    break;

                case XPathTokenID.Node:
                    nodeType = QueryNodeType.All;
                    break;
                }

                // Make sure the nodes being selected CAN actually be selected from this axis
                if (0 == (axis.ValidNodeTypes & nodeType))
                {
                    this.ThrowError(QueryCompileError.InvalidNodeType);
                }

                // Eat ()
                this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidNodeTest);
                this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidNodeTest);
            }
            else
            {
                nodeType = axis.PrincipalNodeType;
            }

            return(new NodeSelectCriteria(axisType, qname, nodeType));
        }
コード例 #5
0
        private NodeSelectCriteria ParseNodeTest(QueryAxisType axisType)
        {
            QueryNodeType principalNodeType;
            QueryAxis     axis  = QueryDataModel.GetAxis(axisType);
            NodeQName     empty = NodeQName.Empty;
            XPathToken    token = this.NextTokenClass(XPathTokenID.NameTest);

            if (token != null)
            {
                switch (token.TokenID)
                {
                case XPathTokenID.Wildcard:
                    empty = new NodeQName(QueryDataModel.Wildcard, QueryDataModel.Wildcard);
                    goto Label_0085;

                case XPathTokenID.NameWildcard:
                    empty = this.QualifyName(token.Prefix, QueryDataModel.Wildcard);
                    goto Label_0085;

                case XPathTokenID.NameTest:
                    empty = this.QualifyName(token.Prefix, token.Name);
                    goto Label_0085;
                }
                this.ThrowError(QueryCompileError.UnexpectedToken);
            }
Label_0085:
            principalNodeType = QueryNodeType.Any;
            if (!empty.IsEmpty)
            {
                principalNodeType = axis.PrincipalNodeType;
            }
            else
            {
                token = this.NextTokenClass(XPathTokenID.NodeType);
                if (token == null)
                {
                    return(null);
                }
                switch (token.TokenID)
                {
                case XPathTokenID.Comment:
                    principalNodeType = QueryNodeType.Comment;
                    break;

                case XPathTokenID.Text:
                    principalNodeType = QueryNodeType.Text;
                    break;

                case XPathTokenID.Processing:
                    principalNodeType = QueryNodeType.Processing;
                    break;

                case XPathTokenID.Node:
                    principalNodeType = QueryNodeType.All;
                    break;

                default:
                    this.ThrowError(QueryCompileError.UnsupportedNodeTest);
                    break;
                }
                if (((byte)(axis.ValidNodeTypes & principalNodeType)) == 0)
                {
                    this.ThrowError(QueryCompileError.InvalidNodeType);
                }
                this.NextToken(XPathTokenID.LParen, QueryCompileError.InvalidNodeTest);
                this.NextToken(XPathTokenID.RParen, QueryCompileError.InvalidNodeTest);
            }
            return(new NodeSelectCriteria(axisType, empty, principalNodeType));
        }