QueryResultOp.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 / QueryResultOp.cs / 1 / QueryResultOp.cs

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

    /// 
    /// Base class for opcodes that produce the query's final result 
    /// 
    internal abstract class QueryResultOpcode : Opcode 
    { 
        internal QueryResultOpcode(OpcodeID id)
            : base(id) 
        {
            this.flags |= OpcodeFlags.Result;
        }
    } 

    internal class MatchQueryResultOpcode : QueryResultOpcode 
    { 
        internal MatchQueryResultOpcode()
            : this(OpcodeID.MatchQueryResult) 
        {
        }

        protected MatchQueryResultOpcode(OpcodeID id) 
            : base(id)
        { 
            this.flags |= OpcodeFlags.Result; 
        }
 
        internal override Opcode Eval(ProcessingContext context)
        {
            context.Processor.Result = this.IsSuccess(context);
            context.PopFrame(); 
            return this.next;
        } 
 
        protected bool IsSuccess(ProcessingContext context)
        { 
            StackFrame topFrame = context.TopArg;

#if FILTER_SELECT
            if (context.Processor.IsMatch) 
            {
#endif 
                if (1 == topFrame.Count) 
                {
                    return context.Values[topFrame.basePtr].ToBoolean(); 
                }
                else
                {
                    context.Processor.Result = false; 
                    for (int i = topFrame.basePtr; i <= topFrame.endPtr; ++i)
                    { 
                        if (context.Values[i].ToBoolean()) 
                        {
                            return true; 
                        }
                    }
                }
#if FILTER_SELECT 
            }
            else if (context.Processor.IsSelect) 
            { 
                string results = string.Empty;
                if (topFrame.Count > 0) 
                {
                    DiagnosticUtility.DebugAssert(topFrame.Count == 1, "");
                    results = context.Values[topFrame.basePtr].ToString();
                } 
                context.Processor.SelectResults = results;
            } 
#endif 

            return false; 
        }
    }

#if NO 
    internal class MatchFilterResultOpcode : MatchQueryResultOpcode
    { 
        MessageFilter resultFilter; 

        internal MatchFilterResultOpcode(MessageFilter resultFilter) 
            : base(OpcodeID.MatchFilterResult)
        {
            DiagnosticUtility.DebugAssert(null != resultFilter, "");
            this.resultFilter = resultFilter; 
        }
 
        internal MessageFilter Result 
        {
            get 
            {
                return this.resultFilter;
            }
        } 

        internal override void Add(Opcode op) 
        { 
            MatchFilterResultOpcode filterResult = op as MatchFilterResultOpcode;
            if (null == filterResult) 
            {
                base.Add(op);
                return;
            } 

            MatchMultipleFilterResultOpcode multipleResults = new MatchMultipleFilterResultOpcode(); 
            DiagnosticUtility.DebugAssert(null != this.prev, ""); 
            this.prev.Replace(this, multipleResults);
 
            if (null != this.next)
            {
                this.next.Prev = multipleResults;
                this.next = null; 
            }
            multipleResults.Add(filterResult); 
            multipleResults.Add(this); 
        }
 
        // One MatchFilterResultOpcode result code is always treated equivalent to another
        internal override bool Equals(Opcode op)
        {
            if (base.Equals(op)) 
            {
                MatchFilterResultOpcode resultOp = op as MatchFilterResultOpcode; 
                return object.ReferenceEquals(resultOp.resultFilter, this.resultFilter); 
            }
 
            return false;
        }

        internal override Opcode Eval(ProcessingContext context) 
        {
            if (this.IsSuccess(context)) 
            { 
                context.Processor.ResultSet.Add(this.resultFilter);
            } 

            return null;
        }
 
        internal override void Remove()
        { 
            if (null == this.resultFilter) 
            {
                base.Remove(); 
            }
        }

        internal void Remove(MessageFilter resultFilter) 
        {
            if (resultFilter == this.resultFilter) 
            { 
                this.resultFilter = null;
                DiagnosticUtility.DebugAssert(null != this.next, ""); 
                base.Remove();
            }
        }
    } 
#endif
 
    internal class MatchMultipleFilterResultOpcode : MatchQueryResultOpcode 
    {
        internal QueryBuffer results; 

        internal MatchMultipleFilterResultOpcode(XPathMessageFilter filter)
            : this()
        { 
            this.results = new QueryBuffer(1);
            this.results.Add(filter); 
        } 

        internal MatchMultipleFilterResultOpcode() 
            : base(OpcodeID.MatchMultipleFilterResult)
        {
            this.results = new QueryBuffer(0);
        } 

        internal override void Add(Opcode op) 
        { 
#if NO
            MatchFilterResultOpcode resultOp = op as MatchFilterResultOpcode; 
            if (null != resultOp)
            {
                this.results.Add(resultOp.Result);
                return; 
            }
#endif 
            MatchMultipleFilterResultOpcode results = op as MatchMultipleFilterResultOpcode; 
            if (null != results)
            { 
                this.results.Add(ref results.results);
                this.results.TrimToCount();
                return;
            } 

            base.Add(op); 
        } 

        internal override void CollectXPathFilters(ICollection filters) 
        {
            for(int i = 0; i < this.results.Count; ++i)
            {
                filters.Add(this.results[i]); 
            }
        } 
 
        internal override bool Equals(Opcode op)
        { 
            if (base.Equals (op))
            {
                return object.ReferenceEquals(this, op);
            } 

            return false; 
        } 

        internal override Opcode Eval(ProcessingContext context) 
        {
            if (this.IsSuccess(context))
            {
                ICollection matches = context.Processor.ResultSet; 
                for (int i = 0, count = this.results.Count; i < count; ++i)
                { 
                    matches.Add(this.results[i]); 
                }
            } 

            context.PopFrame();

            return this.next; 
        }
 
        internal override void Remove() 
        {
            if (0 == this.results.Count) 
            {
                base.Remove();
            }
        } 

        internal void Remove(XPathMessageFilter resultFilter) 
        { 
            DiagnosticUtility.DebugAssert(null != resultFilter, "");
            this.results.Remove(resultFilter); 
            this.Remove();
        }

        internal override void Trim() 
        {
            this.results.TrimToCount(); 
        } 
    }
} 

// 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