MatchSingleFxEngineOpcode.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / MatchSingleFxEngineOpcode.cs / 1 / MatchSingleFxEngineOpcode.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Dispatcher
{ 
    using System;
    using System.ServiceModel.Channels; 
    using System.Collections.Generic; 
    using System.Xml;
    using System.Xml.XPath; 
    using System.Diagnostics;

    /// 
    /// Opcode that evaluates a single xpath query using the framework engine 
    /// 
    internal class MatchSingleFxEngineOpcode : QueryResultOpcode 
    { 
        XPathExpression xpath;
 	    XPathMessageFilter filter; 
	
        internal MatchSingleFxEngineOpcode()
            : base(OpcodeID.MatchSingleFx)
        { 
            this.flags |= OpcodeFlags.FxMatch;
        } 
		 
		internal XPathMessageFilter Filter
 		{ 
#if NO
		    get
 		    {
 		        return this.filter; 
		    }
#endif 
            set 
 		    {
		        this.filter = value; 
		    }
		}
 				
        internal XPathExpression XPath 
        {
#if NO 
            get 
            {
                return this.xpath; 
            }
#endif
            set
            { 
                this.xpath = value;
            } 
        } 

        internal override void CollectXPathFilters(ICollection filters) 
        {
            filters.Add(filter);
        }
 
        internal override bool Equals(Opcode op)
        { 
            return false; 
        }
 
        internal override Opcode Eval(ProcessingContext context)
        {
            DiagnosticUtility.DebugAssert(null != this.xpath, "");
 
            SeekableXPathNavigator targetNav = context.Processor.ContextNode;
 
#if FILTER_SELECT 
            if (context.Processor.IsMatch)
            { 
#endif
                bool result = this.Match(targetNav);
                context.Processor.Result = result;
                if (result && null != this.filter && null != context.Processor.ResultSet) 
                {
                    context.Processor.ResultSet.Add(this.filter); 
                } 
#if FILTER_SELECT
            } 
            else if (context.Processor.IsSelect)
            {
                context.Processor.SelectResults = this.Select(targetNav);
            } 
#endif
            return this.next; 
        } 

        internal object Evaluate(XPathNavigator nav) 
        {
            SeekableMessageNavigator messageNav = nav as SeekableMessageNavigator;
            if (null != messageNav)
            { 
                // If operating on messages, we would have avoided atomizing unless we were using the Framework
                // This ensures that atomization has taken place 
                messageNav.Atomize(); 
            }
 
            object evalResult;
            if (XPathResultType.NodeSet == xpath.ReturnType)
            {
                evalResult = nav.Select(xpath); 
            }
            else 
            { 
                evalResult = nav.Evaluate(xpath);
            } 

            return evalResult;
        }
 
        internal bool Match(XPathNavigator nav)
        { 
            bool retVal; 
            object evalResult = this.Evaluate(nav);
            switch (xpath.ReturnType) 
            {
                default:
                    retVal = false;
                    break; 

                case XPathResultType.Any: 
                    retVal = (null != evalResult); 
                    break;
 
                case XPathResultType.Boolean:
                    retVal = (bool)evalResult;
                    break;
 
                case XPathResultType.NodeSet:
                    XPathNodeIterator iterator = (XPathNodeIterator) evalResult; 
                    retVal = (null != iterator && iterator.Count > 0); 
                    break;
 
                case XPathResultType.Number:
                    retVal = (((double)evalResult) != 0.0);
                    break;
 
                case XPathResultType.String:
                    string strVal = (string)evalResult; 
                    retVal = (null != strVal && strVal.Length > 0); // see XPath 1.0 
                    break;
            } 

            return retVal;
        }
 
        internal string Select(XPathNavigator nav)
        { 
            string retVal = string.Empty; 
            object evalResult = this.Evaluate(nav);
            switch (xpath.ReturnType) 
            {
                default:
                    break;
 
                case XPathResultType.Boolean:
                    retVal = QueryValueModel.String((bool)evalResult); 
                    break; 

                case XPathResultType.NodeSet: 
                    XPathNodeIterator iterator = (XPathNodeIterator) evalResult;
                    if (iterator.MoveNext())
                    {
                        retVal = iterator.Current.Value; 
                    }
                    break; 
 
                case XPathResultType.Number:
                    retVal = QueryValueModel.String((double) evalResult); 
                    break;

                case XPathResultType.String:
                    retVal = (string)evalResult; 
                    break;
            } 
 
            return retVal;
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK