DataServiceProcessingPipeline.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Server / System / Data / Services / DataServiceProcessingPipeline.cs / 1305376 / DataServiceProcessingPipeline.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//  
//      Class declaring events for the data service processing pipeline
//  
// 
// @owner  [....]
//--------------------------------------------------------------------- 

namespace System.Data.Services
{
    using System; 
    using System.Diagnostics;
 
    ///  
    /// Class declaring the events for the data service processing pipeline
    ///  
    public sealed class DataServiceProcessingPipeline
    {
#if DEBUG
        // *************************************************************************************** 
        // The debug code here is for basic assertions on call orders if the request is successful.
        // *************************************************************************************** 
 
        /// 
        /// Number of times InvokeProcessingRequest() is called. 
        /// 
        private int ProcessingRequestInvokeCount;

        ///  
        /// Number of times InvokeProcessedRequest() is called
        ///  
        private int ProcessedRequestInvokeCount; 

        ///  
        /// Number of times InvokeProcessingChangeset() is called
        /// 
        private int ProcessingChangesetInvokeCount;
 
        /// 
        /// Number of times InvokeProcessedChangeset() is called 
        ///  
        private int ProcessedChangesetInvokeCount;
 
        /// 
        /// Set to true if we have seen an exception in the current request or we are in the $metadata path
        /// 
        ///  
        /// If the current request encounters an exception, there is no guarantee that all the
        /// events will be fired, we may skip the debug asserts when that happens. 
        ///  
        internal bool SkipDebugAssert;
 
        /// 
        /// Set to true if DataServiceProviderWrapper.GetService() is called.
        /// 
        internal bool HasInstantiatedProviderInterfaces; 

        ///  
        /// Set to true if any of the service is disposed from WebUtil.Dispose() 
        /// 
        internal bool HasDisposedProviderInterfaces; 

        /// 
        /// Number of times DataService<T>.OnStartProcessingRequest() is called.
        ///  
        internal int OnStartProcessingRequestInvokeCount;
#endif 
 
        /// 
        /// Request start event 
        /// 
        public event EventHandler ProcessingRequest;

        ///  
        /// Request end event
        ///  
        public event EventHandler ProcessedRequest; 

        ///  
        /// Change set start event
        /// 
        public event EventHandler ProcessingChangeset;
 
        /// 
        /// Change set end event 
        ///  
        public event EventHandler ProcessedChangeset;
 
#if DEBUG
        /// 
        /// Assert ProcessingPipeline state before any event has been fired
        ///  
        internal void AssertInitialDebugState()
        { 
            Debug.Assert(!this.HasInstantiatedProviderInterfaces, "!this.HasInstantiatedProviderInterfaces"); 
            Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
            Debug.Assert(this.OnStartProcessingRequestInvokeCount == 0, "this.OnStartProcessingRequestInvokeCount == 0"); 
            Debug.Assert(this.ProcessingRequestInvokeCount == 0, "this.ProcessingRequestInvokeCount == 0");
            Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0");
            Debug.Assert(this.ProcessingChangesetInvokeCount == 0, "this.ProcessingChangesetInvokeCount == 0");
            Debug.Assert(this.ProcessedChangesetInvokeCount == 0, "this.ProcessedChangesetInvokeCount == 0"); 
        }
 
        ///  
        /// Assert ProcessingPipeline state at DataService<T>.OnStartProcessingRequest
        ///  
        internal void AssertDebugStateAtOnStartProcessingRequest()
        {
            // If the current request encounters an exception, there is no guarantee that all the
            // events will be fired, we skip the debug asserts when that happens. 
            if (!this.SkipDebugAssert)
            { 
                Debug.Assert( 
                    this.OnStartProcessingRequestInvokeCount > 0 || !this.HasInstantiatedProviderInterfaces,
                    "this.OnStartProcessingRequestInvokeCount > 0 || !this.HasInstantiatedProviderInterfaces"); 
                Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
                Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1");
                Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0");
                Debug.Assert( 
                    this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount || this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1,
                    "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount || this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1"); 
            } 
        }
 
        /// 
        /// Assert ProcessingPipeline state before disposing provider interfaces
        /// 
        internal void AssertDebugStateAtDispose() 
        {
            // If the current request encounters an exception, there is no guarantee that all the 
            // events will be fired, we skip the debug asserts when that happens. 
            if (!this.SkipDebugAssert)
            { 
                Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0");
                Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1");
                Debug.Assert(this.ProcessedRequestInvokeCount == 1, "this.ProcessedRequestInvokeCount == 1");
                Debug.Assert( 
                    this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount,
                    "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount"); 
            } 
        }
 
        /// 
        /// Assert Processing Pipeline state during request processing
        /// 
        /// data service instance 
        internal void AssertDebugStateDuringRequestProcessing(IDataService dataService)
        { 
            // If the current request encounters an exception, there is no guarantee that all the 
            // events will be fired, we skip the debug asserts when that happens.
            if (!this.SkipDebugAssert) 
            {
                Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
                Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0");
                Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1"); 
                Debug.Assert(
                    (this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount && dataService.OperationContext.Host.AstoriaHttpVerb == AstoriaVerbs.GET) || 
                    (this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1 && dataService.OperationContext.Host.AstoriaHttpVerb != AstoriaVerbs.GET), 
                    "ProcessingChangesetInvokeCount must be 1 larger than ProcessedChangesetInvokeCount in CUD operation and they must be the same in a GET request.");
            } 
        }

        /// 
        /// Need to be able to reset the states since the caller can reuse the same service instance. 
        /// 
        internal void ResetDebugState() 
        { 
            this.HasInstantiatedProviderInterfaces = false;
            this.HasDisposedProviderInterfaces = false; 
            this.OnStartProcessingRequestInvokeCount = 0;
            this.ProcessingRequestInvokeCount = 0;
            this.ProcessedRequestInvokeCount = 0;
            this.ProcessingChangesetInvokeCount = 0; 
            this.ProcessedChangesetInvokeCount = 0;
        } 
#endif 

        ///  
        /// Invoke request start event
        /// 
        /// Sender, i.e. data service instance.
        /// event arg 
        internal void InvokeProcessingRequest(object sender, DataServiceProcessingPipelineEventArgs e)
        { 
#if DEBUG 
            this.AssertInitialDebugState();
            this.ProcessingRequestInvokeCount++; 
#endif
            if (this.ProcessingRequest != null)
            {
                this.ProcessingRequest(sender, e); 
            }
        } 
 
        /// 
        /// Invoke request end event 
        /// 
        /// Sender, i.e. data service instance.
        /// event arg
        internal void InvokeProcessedRequest(object sender, DataServiceProcessingPipelineEventArgs e) 
        {
#if DEBUG 
            Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces"); 
            Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0");
            Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1"); 
            Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0");
            if (!this.SkipDebugAssert)
            {
                Debug.Assert(this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount, "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount"); 
            }
 
            this.ProcessedRequestInvokeCount++; 
#endif
            if (this.ProcessedRequest != null) 
            {
                this.ProcessedRequest(sender, e);
            }
        } 

        ///  
        /// Invoke change set start event 
        /// 
        /// Sender, i.e. data service instance. 
        /// event arg
        internal void InvokeProcessingChangeset(object sender, EventArgs e)
        {
#if DEBUG 
            Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
            Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0"); 
            Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1"); 
            Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0");
            if (!this.SkipDebugAssert) 
            {
                Debug.Assert(this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount, "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount");
            }
 
            this.ProcessingChangesetInvokeCount++;
#endif 
            if (this.ProcessingChangeset != null) 
            {
                this.ProcessingChangeset(sender, e); 
            }
        }

        ///  
        /// Invoke change set end event
        ///  
        /// Sender, i.e. data service instance. 
        /// event arg
        internal void InvokeProcessedChangeset(object sender, EventArgs e) 
        {
#if DEBUG
            Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
            Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0"); 
            Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1");
            Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0"); 
            if (!this.SkipDebugAssert) 
            {
                Debug.Assert(this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1, "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1"); 
            }

            this.ProcessedChangesetInvokeCount++;
#endif 
            if (this.ProcessedChangeset != null)
            { 
                this.ProcessedChangeset(sender, e); 
            }
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//  
//      Class declaring events for the data service processing pipeline
//  
// 
// @owner  [....]
//--------------------------------------------------------------------- 

namespace System.Data.Services
{
    using System; 
    using System.Diagnostics;
 
    ///  
    /// Class declaring the events for the data service processing pipeline
    ///  
    public sealed class DataServiceProcessingPipeline
    {
#if DEBUG
        // *************************************************************************************** 
        // The debug code here is for basic assertions on call orders if the request is successful.
        // *************************************************************************************** 
 
        /// 
        /// Number of times InvokeProcessingRequest() is called. 
        /// 
        private int ProcessingRequestInvokeCount;

        ///  
        /// Number of times InvokeProcessedRequest() is called
        ///  
        private int ProcessedRequestInvokeCount; 

        ///  
        /// Number of times InvokeProcessingChangeset() is called
        /// 
        private int ProcessingChangesetInvokeCount;
 
        /// 
        /// Number of times InvokeProcessedChangeset() is called 
        ///  
        private int ProcessedChangesetInvokeCount;
 
        /// 
        /// Set to true if we have seen an exception in the current request or we are in the $metadata path
        /// 
        ///  
        /// If the current request encounters an exception, there is no guarantee that all the
        /// events will be fired, we may skip the debug asserts when that happens. 
        ///  
        internal bool SkipDebugAssert;
 
        /// 
        /// Set to true if DataServiceProviderWrapper.GetService() is called.
        /// 
        internal bool HasInstantiatedProviderInterfaces; 

        ///  
        /// Set to true if any of the service is disposed from WebUtil.Dispose() 
        /// 
        internal bool HasDisposedProviderInterfaces; 

        /// 
        /// Number of times DataService<T>.OnStartProcessingRequest() is called.
        ///  
        internal int OnStartProcessingRequestInvokeCount;
#endif 
 
        /// 
        /// Request start event 
        /// 
        public event EventHandler ProcessingRequest;

        ///  
        /// Request end event
        ///  
        public event EventHandler ProcessedRequest; 

        ///  
        /// Change set start event
        /// 
        public event EventHandler ProcessingChangeset;
 
        /// 
        /// Change set end event 
        ///  
        public event EventHandler ProcessedChangeset;
 
#if DEBUG
        /// 
        /// Assert ProcessingPipeline state before any event has been fired
        ///  
        internal void AssertInitialDebugState()
        { 
            Debug.Assert(!this.HasInstantiatedProviderInterfaces, "!this.HasInstantiatedProviderInterfaces"); 
            Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
            Debug.Assert(this.OnStartProcessingRequestInvokeCount == 0, "this.OnStartProcessingRequestInvokeCount == 0"); 
            Debug.Assert(this.ProcessingRequestInvokeCount == 0, "this.ProcessingRequestInvokeCount == 0");
            Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0");
            Debug.Assert(this.ProcessingChangesetInvokeCount == 0, "this.ProcessingChangesetInvokeCount == 0");
            Debug.Assert(this.ProcessedChangesetInvokeCount == 0, "this.ProcessedChangesetInvokeCount == 0"); 
        }
 
        ///  
        /// Assert ProcessingPipeline state at DataService<T>.OnStartProcessingRequest
        ///  
        internal void AssertDebugStateAtOnStartProcessingRequest()
        {
            // If the current request encounters an exception, there is no guarantee that all the
            // events will be fired, we skip the debug asserts when that happens. 
            if (!this.SkipDebugAssert)
            { 
                Debug.Assert( 
                    this.OnStartProcessingRequestInvokeCount > 0 || !this.HasInstantiatedProviderInterfaces,
                    "this.OnStartProcessingRequestInvokeCount > 0 || !this.HasInstantiatedProviderInterfaces"); 
                Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
                Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1");
                Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0");
                Debug.Assert( 
                    this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount || this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1,
                    "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount || this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1"); 
            } 
        }
 
        /// 
        /// Assert ProcessingPipeline state before disposing provider interfaces
        /// 
        internal void AssertDebugStateAtDispose() 
        {
            // If the current request encounters an exception, there is no guarantee that all the 
            // events will be fired, we skip the debug asserts when that happens. 
            if (!this.SkipDebugAssert)
            { 
                Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0");
                Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1");
                Debug.Assert(this.ProcessedRequestInvokeCount == 1, "this.ProcessedRequestInvokeCount == 1");
                Debug.Assert( 
                    this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount,
                    "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount"); 
            } 
        }
 
        /// 
        /// Assert Processing Pipeline state during request processing
        /// 
        /// data service instance 
        internal void AssertDebugStateDuringRequestProcessing(IDataService dataService)
        { 
            // If the current request encounters an exception, there is no guarantee that all the 
            // events will be fired, we skip the debug asserts when that happens.
            if (!this.SkipDebugAssert) 
            {
                Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
                Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0");
                Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1"); 
                Debug.Assert(
                    (this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount && dataService.OperationContext.Host.AstoriaHttpVerb == AstoriaVerbs.GET) || 
                    (this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1 && dataService.OperationContext.Host.AstoriaHttpVerb != AstoriaVerbs.GET), 
                    "ProcessingChangesetInvokeCount must be 1 larger than ProcessedChangesetInvokeCount in CUD operation and they must be the same in a GET request.");
            } 
        }

        /// 
        /// Need to be able to reset the states since the caller can reuse the same service instance. 
        /// 
        internal void ResetDebugState() 
        { 
            this.HasInstantiatedProviderInterfaces = false;
            this.HasDisposedProviderInterfaces = false; 
            this.OnStartProcessingRequestInvokeCount = 0;
            this.ProcessingRequestInvokeCount = 0;
            this.ProcessedRequestInvokeCount = 0;
            this.ProcessingChangesetInvokeCount = 0; 
            this.ProcessedChangesetInvokeCount = 0;
        } 
#endif 

        ///  
        /// Invoke request start event
        /// 
        /// Sender, i.e. data service instance.
        /// event arg 
        internal void InvokeProcessingRequest(object sender, DataServiceProcessingPipelineEventArgs e)
        { 
#if DEBUG 
            this.AssertInitialDebugState();
            this.ProcessingRequestInvokeCount++; 
#endif
            if (this.ProcessingRequest != null)
            {
                this.ProcessingRequest(sender, e); 
            }
        } 
 
        /// 
        /// Invoke request end event 
        /// 
        /// Sender, i.e. data service instance.
        /// event arg
        internal void InvokeProcessedRequest(object sender, DataServiceProcessingPipelineEventArgs e) 
        {
#if DEBUG 
            Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces"); 
            Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0");
            Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1"); 
            Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0");
            if (!this.SkipDebugAssert)
            {
                Debug.Assert(this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount, "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount"); 
            }
 
            this.ProcessedRequestInvokeCount++; 
#endif
            if (this.ProcessedRequest != null) 
            {
                this.ProcessedRequest(sender, e);
            }
        } 

        ///  
        /// Invoke change set start event 
        /// 
        /// Sender, i.e. data service instance. 
        /// event arg
        internal void InvokeProcessingChangeset(object sender, EventArgs e)
        {
#if DEBUG 
            Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
            Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0"); 
            Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1"); 
            Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0");
            if (!this.SkipDebugAssert) 
            {
                Debug.Assert(this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount, "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount");
            }
 
            this.ProcessingChangesetInvokeCount++;
#endif 
            if (this.ProcessingChangeset != null) 
            {
                this.ProcessingChangeset(sender, e); 
            }
        }

        ///  
        /// Invoke change set end event
        ///  
        /// Sender, i.e. data service instance. 
        /// event arg
        internal void InvokeProcessedChangeset(object sender, EventArgs e) 
        {
#if DEBUG
            Debug.Assert(!this.HasDisposedProviderInterfaces, "!this.HasDisposedProviderInterfaces");
            Debug.Assert(this.OnStartProcessingRequestInvokeCount > 0, "this.OnStartProcessingRequestInvokeCount > 0"); 
            Debug.Assert(this.ProcessingRequestInvokeCount == 1, "this.ProcessingRequestInvokeCount == 1");
            Debug.Assert(this.ProcessedRequestInvokeCount == 0, "this.ProcessedRequestInvokeCount == 0"); 
            if (!this.SkipDebugAssert) 
            {
                Debug.Assert(this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1, "this.ProcessingChangesetInvokeCount == this.ProcessedChangesetInvokeCount + 1"); 
            }

            this.ProcessedChangesetInvokeCount++;
#endif 
            if (this.ProcessedChangeset != null)
            { 
                this.ProcessedChangeset(sender, e); 
            }
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

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