Exemplo n.º 1
0
 // clear the ChunkValue
 public void Clear()
 {
     m_fIsValid = false;
     m_chunk    = default;
     m_propVariant.Clear();
     m_pszValue = null;
 }
        /// <summary>
        /// GetChunk
        /// </summary>
        /// <returns>the next chunk</returns>
        public STAT_CHUNK GetChunk()
        {
            // Get the managed chunk
            ManagedChunk managedChunk = _implementation.GetChunk();

            if (managedChunk == null)
            {
                // End of chunks.

                if (ThrowOnEndOfChunks)
                {
                    // Throw exception.
                    throw new COMException(SR.Get(SRID.FilterEndOfChunks),
                                           (int)FilterErrorCode.FILTER_E_END_OF_CHUNKS);
                }

                // Return STAT_CHUNK with idChunk as 0.

                STAT_CHUNK chunk = new STAT_CHUNK();
                chunk.idChunk = 0;
                return(chunk);
            }

            // Valid chunk. Return corresponding STAT_CHUNK.
            return(MarshalChunk(managedChunk));
        }
        internal static STAT_CHUNK MarshalChunk(ManagedChunk chunk)
        {
            STAT_CHUNK result = default(STAT_CHUNK);

            result.idChunk = chunk.ID;
            Invariant.Assert(chunk.BreakType >= CHUNK_BREAKTYPE.CHUNK_NO_BREAK && chunk.BreakType <= CHUNK_BREAKTYPE.CHUNK_EOC);
            result.breakType = chunk.BreakType;
            Invariant.Assert(chunk.Flags >= (CHUNKSTATE)0 && chunk.Flags <= (CHUNKSTATE.CHUNK_TEXT | CHUNKSTATE.CHUNK_VALUE | CHUNKSTATE.CHUNK_FILTER_OWNED_VALUE));
            result.flags          = chunk.Flags;
            result.locale         = chunk.Locale;
            result.idChunkSource  = chunk.ChunkSource;
            result.cwcStartSource = chunk.StartSource;
            result.cwcLenSource   = chunk.LenSource;
            IndexingFilterMarshaler.MarshalFullPropSpec(chunk.Attribute, ref result.attribute);
            return(result);
        }
        private static void ReadChunk(IFilter filter, STAT_CHUNK chunk, StringBuilder text)
        {
            var textResult = IFilterReturnCodes.S_OK;

            while (textResult == IFilterReturnCodes.S_OK)
            {
                var bufferSize = 4096U;
                var buffer     = new char[bufferSize];
                textResult = filter.GetText(ref bufferSize, buffer);
                if ((textResult == IFilterReturnCodes.S_OK || textResult == IFilterReturnCodes.FILTER_S_LAST_TEXT) && bufferSize > 0)
                {
                    if (chunk.breakType == CHUNK_BREAKTYPE.CHUNK_EOP)
                    {
                        text.Append('\n');
                    }
                    text.Append(buffer, 0, (int)bufferSize);
                }
            }
        }
        /// <summary>
        /// GetChunk
        /// </summary>
        /// <returns>An interop STAT_CHUNK from a ManagedChunk</returns>
        internal static STAT_CHUNK MarshalChunk(ManagedChunk chunk)
        {
            STAT_CHUNK native = new STAT_CHUNK();

            native.idChunk = chunk.ID;
            Invariant.Assert(chunk.BreakType >= CHUNK_BREAKTYPE.CHUNK_NO_BREAK && chunk.BreakType <= CHUNK_BREAKTYPE.CHUNK_EOC);
            native.breakType = chunk.BreakType;
            Invariant.Assert(
                chunk.Flags >= 0
                &&
                chunk.Flags <= (CHUNKSTATE.CHUNK_TEXT | CHUNKSTATE.CHUNK_VALUE | CHUNKSTATE.CHUNK_FILTER_OWNED_VALUE));
            native.flags          = chunk.Flags;
            native.locale         = chunk.Locale;
            native.idChunkSource  = chunk.ChunkSource;
            native.cwcStartSource = chunk.StartSource;
            native.cwcLenSource   = chunk.LenSource;
            MarshalFullPropSpec(chunk.Attribute, ref native.attribute);

            return(native);
        }
 // Token: 0x06006CB6 RID: 27830 RVA: 0x001F4644 File Offset: 0x001F2844
 public STAT_CHUNK GetChunk()
 {
     if (this._progress == PackageFilter.Progress.FilteringNotStarted)
     {
         this.MoveToNextFilter();
     }
     if (this._progress == PackageFilter.Progress.FilteringCompleted)
     {
         throw new COMException(SR.Get("FilterEndOfChunks"), -2147215616);
     }
     do
     {
         try
         {
             STAT_CHUNK chunk = this._currentFilter.GetChunk();
             if ((!this._isInternalFilter || chunk.idChunk != 0U) && (this._progress == PackageFilter.Progress.FilteringCoreProperties || (chunk.flags & CHUNKSTATE.CHUNK_VALUE) != CHUNKSTATE.CHUNK_VALUE))
             {
                 chunk.idChunk       = this.AllocateChunkID();
                 chunk.idChunkSource = chunk.idChunk;
                 if (this._firstChunkFromFilter)
                 {
                     chunk.breakType            = CHUNK_BREAKTYPE.CHUNK_EOP;
                     this._firstChunkFromFilter = false;
                 }
                 return(chunk);
             }
         }
         catch (COMException)
         {
         }
         catch (IOException ex)
         {
             if (this._isInternalFilter)
             {
                 throw ex;
             }
         }
         this.MoveToNextFilter();
     }while (this._progress != PackageFilter.Progress.FilteringCompleted);
     throw new COMException(SR.Get("FilterEndOfChunks"), -2147215616);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Returns description of the next chunk.
        /// </summary>
        /// <returns>
        /// Chunk descriptor.
        /// </returns>
        /// <remarks>
        /// <para>
        /// On end of stream, this function will throw an exception so as to return FILTER_E_END_OF_CHUNKS
        /// to client code, in keeping with the IFilter specifications.
        /// </para>
        /// <para>
        /// Non-fatal exceptions from external filters, identified for all practical purposes
        /// with COMException and IOException, are `swallowed by this method.
        /// </para>
        /// </remarks>
        public STAT_CHUNK GetChunk()
        {
            //
            // _progress is Progress.FilteringNotStarted initially and
            // subsequently gets updated in MoveToNextFilter().
            //

            if (_progress == Progress.FilteringNotStarted)
            {
                MoveToNextFilter();
            }

            if (_progress == Progress.FilteringCompleted)
            {
                throw new COMException(SR.Get(SRID.FilterEndOfChunks),
                                       (int)FilterErrorCode.FILTER_E_END_OF_CHUNKS);
            }

            while (true)
            {
                try
                {
                    STAT_CHUNK chunk = _currentFilter.GetChunk();

                    //
                    // No exception raised.
                    // If _currentFilter is internal filter,
                    // this might be end of chunks if chunk.idChunk is 0.
                    //

                    if (!_isInternalFilter || chunk.idChunk != 0)
                    {
                        //
                        // There are more chunks.
                        //

                        //
                        // Consider value chunks only when filtering core properties.
                        // Else, ignore the chunk and move to the next.
                        //
                        if (_progress == Progress.FilteringCoreProperties ||
                            (chunk.flags & CHUNKSTATE.CHUNK_VALUE) != CHUNKSTATE.CHUNK_VALUE)
                        {
                            //
                            // Found the next chunk to return.
                            //

                            // Replace ID from auxiliary filter by unique ID across the package.
                            chunk.idChunk = AllocateChunkID();

                            // Since pseudo-properties (a.k.a. internal values) are not supported,
                            // all chunks we return are expected to have idChunkSource equal to idChunk.
                            // (See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/indexsrv/html/ixufilt_8ib8.asp)
                            chunk.idChunkSource = chunk.idChunk;

                            // Some filters (such as the plain text filter)
                            // will return "no break" before the first chunk.
                            // However, the correct break type at the beginning
                            // of a part is "end of paragraph".
                            if (_firstChunkFromFilter)
                            {
                                chunk.breakType = CHUNK_BREAKTYPE.CHUNK_EOP;

                                // This flag gets set in MoveToNextFilter.
                                _firstChunkFromFilter = false;
                            }

                            return(chunk);
                        }
                    }
                }
                // Ignore IO and COM exceptions raised by an external filter.
                catch (COMException)
                {
                    // Most of the time, this will be a FILTER_E_END_OF_CHUNKS exception.
                    // In general, we don't really care: when an external filter gets in trouble
                    // we simply move to the next filter.
                }
                catch (IOException)
                {
                    // Internal filters do not throw expected exceptions; so something bad
                    // must have happened. Let the client code get the exception and possibly
                    // choose to ignore it.
                    if (_isInternalFilter)
                    {
                        throw;
                    }
                }

                //
                // Either there was FILTER_E_END_OF_CHUNKS exception
                // from _currentFilter.GetChunk(),
                // or _isInternalFilter is true and the returned chunk has
                // idChunk as 0, which also indicates end of chunks.
                //
                // Move to the next filter.
                //

                MoveToNextFilter();

                if (_progress == Progress.FilteringCompleted)
                {
                    //
                    // No more filters. Filtering completed.
                    // Throw FILTER_E_END_OF_CHUNKS exception.
                    //

                    throw new COMException(SR.Get(SRID.FilterEndOfChunks),
                                           (int)FilterErrorCode.FILTER_E_END_OF_CHUNKS);
                }
            }
        }
Exemplo n.º 8
0
 // copy the chunk
 public void CopyChunk(out STAT_CHUNK pStatChunk) => pStatChunk = m_chunk;