internal void FilterIntegrated(bool finalFiltering, IIS7WorkerRequest wr) {
            // no filter?
            if (_installedFilter == null)
                return;

            // flush char buffer and remember old buffers
            if (_charBufferLength != _charBufferFree)
                FlushCharBuffer(true);

            _lastBuffer = null;

            // ISAPI mode bails if it has no buffers
            // to filter, in integrated mode we need
            // to check the unified response buffers
            // maintained by IIS for content, as well

            // remember current buffers (if any) that might be
            // response entity from this transition 
            // (not yet pushed through to IIS response buffers)
            ArrayList oldBuffers = _buffers;
            _buffers = new ArrayList();
            
            // now, get what's in the IIS buffers
            ArrayList nativeBuffers = null;            
            bool fDummy = false;
            nativeBuffers = wr.GetBufferedResponseChunks(false, null, ref fDummy);
            
            Debug.Assert(_filterSink != null);
            _filterSink.Filtering = true;
           
            try {
                // push buffers through installed filters
                // push the IIS ones through first since we need to maintain order
                if (null != nativeBuffers) {
                    for (int i = 0; i < nativeBuffers.Count; i++) {
                        IHttpResponseElement buf = (IHttpResponseElement)nativeBuffers[i];

                        long len = buf.GetSize();

                        if (len > 0)
                            _installedFilter.Write(buf.GetBytes(), 0, Convert.ToInt32(len));

                    }

                    // if we had stuff there, we now need to clear it since we may have
                    // transformed it
                    wr.ClearResponse(true /* entity */, false /* headers */);
                }

                // current buffers, if any
                if (null != oldBuffers) {
                    for (int i = 0; i < oldBuffers.Count; i++) {
                        IHttpResponseElement buf = (IHttpResponseElement)oldBuffers[i];

                        long len = buf.GetSize();

                        if (len > 0)
                            _installedFilter.Write(buf.GetBytes(), 0, Convert.ToInt32(len));

                    }
                }

                _installedFilter.Flush();
            }
            finally {
                try {
                    if (finalFiltering)
                        _installedFilter.Close();
                }
                finally {
                    _filterSink.Filtering = false;
                }
            }
        }
 internal ArrayList GetIntegratedSnapshot(out bool hasSubstBlocks, IIS7WorkerRequest wr)
 {
     ArrayList list = null;
     ArrayList snapshot = this.GetSnapshot(out hasSubstBlocks);
     ArrayList list3 = wr.GetBufferedResponseChunks(true, this._substElements, ref hasSubstBlocks);
     if (list3 != null)
     {
         for (int i = 0; i < snapshot.Count; i++)
         {
             list3.Add(snapshot[i]);
         }
         list = list3;
     }
     else
     {
         list = snapshot;
     }
     if ((this._substElements != null) && (this._substElements.Count > 0))
     {
         int num2 = 0;
         for (int j = 0; j < list.Count; j++)
         {
             if (list[j] is HttpSubstBlockResponseElement)
             {
                 num2++;
                 if (num2 == this._substElements.Count)
                 {
                     break;
                 }
             }
         }
         if (num2 != this._substElements.Count)
         {
             throw new InvalidOperationException(System.Web.SR.GetString("Substitution_blocks_cannot_be_modified"));
         }
         this._response.Context.Request.SetDynamicCompression(true);
     }
     return list;
 }
        // in integrated mode, snapshots need to pull the chunks from the IIS
        // buffers since they may have already been pushed through
        // Therefore, we can't rely solely on what's in the HttpWriter
        // at the moment
        internal ArrayList GetIntegratedSnapshot(out bool hasSubstBlocks, IIS7WorkerRequest wr) {
            ArrayList buffers = null;

            // first, get what's in our buffers
            ArrayList writerBuffers = GetSnapshot(out hasSubstBlocks);

            // now, get what's in the IIS buffers
            ArrayList nativeBuffers = wr.GetBufferedResponseChunks(true, _substElements, ref hasSubstBlocks);
                 
            // try to append the current buffers to what we just
            // got from the native buffer
            if (null != nativeBuffers) {
                for (int i = 0; i < writerBuffers.Count; i++) {
                    nativeBuffers.Add(writerBuffers[i]);
                }
                buffers = nativeBuffers;
            }
            else {
                buffers = writerBuffers;
            }

            // if we have substitution blocks:
            // 1) throw exception if someone modified the subst blocks
            // 2) re-enable compression
            if (_substElements != null && _substElements.Count > 0) {
                int substCount = 0;
                // scan buffers for subst blocks
                for(int i = 0; i < buffers.Count; i++) {
                    if (buffers[i] is HttpSubstBlockResponseElement) {
                        substCount++;
                        if (substCount == _substElements.Count) {
                            break;
                        }
                    }
                }
                
                if (substCount != _substElements.Count) {
                    throw new InvalidOperationException(SR.GetString(SR.Substitution_blocks_cannot_be_modified));
                }

                // re-enable dynamic compression when we have a snapshot of the subst blocks.
                _response.Context.Request.SetDynamicCompression(true /*enable*/);
            }

            return buffers;
        }
 internal void FilterIntegrated(bool finalFiltering, IIS7WorkerRequest wr)
 {
     if (this._installedFilter != null)
     {
         if (this._charBufferLength != this._charBufferFree)
         {
             this.FlushCharBuffer(true);
         }
         this._lastBuffer = null;
         ArrayList list = this._buffers;
         this._buffers = new ArrayList();
         ArrayList list2 = null;
         bool hasSubstBlocks = false;
         list2 = wr.GetBufferedResponseChunks(false, null, ref hasSubstBlocks);
         this._filterSink.Filtering = true;
         try
         {
             if (list2 != null)
             {
                 for (int i = 0; i < list2.Count; i++)
                 {
                     IHttpResponseElement element = (IHttpResponseElement) list2[i];
                     long size = element.GetSize();
                     if (size > 0L)
                     {
                         this._installedFilter.Write(element.GetBytes(), 0, Convert.ToInt32(size));
                     }
                 }
                 wr.ClearResponse(true, false);
             }
             if (list != null)
             {
                 for (int j = 0; j < list.Count; j++)
                 {
                     IHttpResponseElement element2 = (IHttpResponseElement) list[j];
                     long num4 = element2.GetSize();
                     if (num4 > 0L)
                     {
                         this._installedFilter.Write(element2.GetBytes(), 0, Convert.ToInt32(num4));
                     }
                 }
             }
             this._installedFilter.Flush();
         }
         finally
         {
             try
             {
                 if (finalFiltering)
                 {
                     this._installedFilter.Close();
                 }
             }
             finally
             {
                 this._filterSink.Filtering = false;
             }
         }
     }
 }