Implementing a Seek Method in a Managed Streaming Pipeline Component

The native IStream interface does not provide a method to check the current stream position, so the messaging engine uses the following Seek method.

pStream->Seek(0, STREAM_SEEK_CUR, &pNewPosition);

This method does not move the stream pointer; instead it queries the current position. So if you implement a pipeline component that works with a nonseekable stream, you can use the Stream.Seek method as in the following example.

Example

[C#]
override public long Seek(long offset, SeekOrigin origin)
{
   long pos = -1;

   switch(origin)
   {
      case SeekOrigin.Begin :
         pos = offset;
         break;
      case SeekOrigin.Current :
         pos = Position + offset;
         break;
      case SeekOrigin.End :
         break;
   }

   // We generally disallow seeking of the stream
   // However, in unmanaged code, many people use Seek(0,CURR) to retrieve    // the current position
   // Special case (that is, if Seek does not change position, do not 
   // throw an exception)
   if (pos==Position)
   {
      return pos;
   }
   else
   {
      throw new NotSupportedException("ForwardOnlyEventingReadStream does not support Seek()");
   }
}

See Also

Developing Pipeline Components

To download updated BizTalk Server 2004 Help from www.microsoft.com, go to http://go.microsoft.com/fwlink/?linkid=20616.

Copyright © 2004 Microsoft Corporation.
All rights reserved.
Show: