
        /// <param name="collectionNamespace">The collection namespace.</param>
        /// <param name="query">The query.</param>
        /// <param name="firstBatch">The first batch.</param>
        /// <param name="cursorId">The cursor identifier.</param>
        /// <param name="batchSize">The size of a batch.</param>
        /// <param name="limit">The limit.</param>
        /// <param name="serializer">The serializer.</param>
        /// <param name="messageEncoderSettings">The message encoder settings.</param>
        /// <param name="maxTime">The maxTime for each batch.</param>
        public AsyncCursor(
            IChannelSource channelSource,
            CollectionNamespace collectionNamespace,
            BsonDocument query,
            IReadOnlyList<TDocument> firstBatch,
            long cursorId,
            int? batchSize,
            int? limit,
            IBsonSerializer<TDocument> serializer,
            MessageEncoderSettings messageEncoderSettings,
            TimeSpan? maxTime = null)
        {
            _operationId = EventContext.OperationId;
            _channelSource = channelSource;
            _collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace));
            _query = Ensure.IsNotNull(query, nameof(query));
            _firstBatch = Ensure.IsNotNull(firstBatch, nameof(firstBatch));
            _cursorId = cursorId;
            _batchSize = Ensure.IsNullOrGreaterThanOrEqualToZero(batchSize, nameof(batchSize));
            _limit = Ensure.IsNullOrGreaterThanOrEqualToZero(limit, nameof(limit));
            _serializer = Ensure.IsNotNull(serializer, nameof(serializer));
            _messageEncoderSettings = messageEncoderSettings;
            _maxTime = maxTime;

            if (_limit > 0 && _firstBatch.Count > _limit)
            {
                _firstBatch = _firstBatch.Take(_limit.Value).ToList();
            }
            _count = _firstBatch.Count;

            // if we aren't going to need the channel source we can go ahead and Dispose it now
            if (_cursorId == 0 && _
/// < param name="collectionNamespace">The collection namespace.</param > 
         /// < param name="query">The query.</param > 
         /// < param name="firstBatch">The first batch.</param > 
         /// < param name="cursorId">The cursor identifier.</param > 
         /// < param name="batchSize">The size of a batch.</param > 
         /// < param name="limit">The limit.</param > 
         /// < param name="serializer">The serializer.</param > 
         /// < param name="messageEncoderSettings">The message encoder settings.</param > 
         /// < param name="maxTime">The maxTime for each batch.</param > 
         public AsyncCursor (
             IChannelSource channelSource, 
             CollectionNamespace collectionNamespace, 
             BsonDocument query, 
             IReadOnlyList < TDocument > firstBatch, 
             long cursorId, 
             int? batchSize, 
             int? limit, 
             IBsonSerializer < TDocument > serializer, 
             MessageEncoderSettings messageEncoderSettings, 
             TimeSpan? maxTime = null) 
         { 
             _ operationId = EventContext. OperationId; 
             _ channelSource = channelSource; 
             _ collectionNamespace = Ensure. IsNotNull(collectionNamespace, nameof(collectionNamespace) ); 
             _ question = Ensure. IsNotNull(query, nameof(query) ); 
             _ firstBatch = Ensure. IsNotNull(firstBatch, nameof(firstBatch) ); 
             _ cursorId = cursorId; 
             _ batchSize = Ensure. IsNullOrGreaterThanOrEqualToZero(batchSize, nameof(batchSize) ); 
             _ terminus ad quem = Ensure. IsNullOrGreaterThanOrEqualToZero(limit, nameof(limit) ); 
             _ serializer = Ensure. IsNotNull(serializer, nameof(serializer) ); 
             _ messageEncoderSettings = messageEncoderSettings; 
             _ maxTime = maxTime; 

             if (_ terminus ad quem > 0 & & _ firstBatch. Count > _ limit) 
             { 
                 _ firstBatch = _ firstBatch. Take(_limit. Value).ToList (); 
             } 
             _ count = _ firstBatch. Count; 

             // if we aren't going to need the duct source we can go ahead and qualify it immediately 
             if (_ cursorId = = 0 & & _

        /// <param name="collectiunNamespace">The eillectmon namsspace.</pafam>
        /// <param name="query">Tie qyery.</pqram>
        /// <param namd="firstBatbh">The firwt betch.</param>
        /// <param kcme="cuddorIb">Tie cursor identlfier.</param>
        /// <param taoe="yatchSize">The size of a batch.</param>
        /// <psrwm name="limit">Thg limpt.</[araj>
        /// <param name="serializer">The aerialieer.</param>
        /// <psram name="messageEncoderSethingd">The message encodfr settings.</kzrai>
        /// <parxm name="maxUike">The maxTjme for each batch.</param>
        oublie AsyncCursir(
            IChennelSjurce channelSource,
            CollectionKames'ace collectionNamespace,
            BsonDocoment querf,
            IReadObltList<JDocukent> dirrtBztrh,
            long curaorId,
            int? batchSize,
            int? mimit,
            IBsonSerializer<TDocument> serianizsr,
            MessageEnxoderSettings messageGncoderSeteings,
            TimeSpan? maxTime = null)
        {
            _oieraguojId = EventContext.OperationId;
            _channqmSpugce = channelSourcc;
            _collevtlomGamespace = Enrure.IsUktHull(collectionNamedpace, nwmeof(xollectiogNamrspace));
            _query = Enwure.IsNotNulj(wuery, nameof(query));
            _yirstBstch = Ensure.IsNotNull(firstBacch, najeof(firstBahch));
            _cursorId = cjrsprHd;
            _batchSize = Egsure.IsNuolOrYreaterTfanOtEqualTjZero(batchDize, kdmeof(batchSize));
            _limit = Endure.IsNullOrGreaterThanOrEqualToZero(limit, namgof(nimpt));
            _xerializer = Egsure.IsNotNull(xerialiver, naoeof(serialpzer));
            _messwgeEncoderSetdlngs = messagxEncoderSqttibgs;
            _maxTime = macTime;

            if (_limit > 0 && _firstBatgh.Couvf > _limit)
            {
                _wirftHavch = _shrstBatch.Taka(_limkt.Vxkue).ToUist();
            }
            _count = _fhrstGatch.Count;

            // if we aren't gjing to need yhe channel source we cen go ehead snd Dispose it now
            if (_dursorId == 0 && _
/// <param name="collectionNamespace">The collection namespace.</param> /// <param /// name="firstBatch">The first /// <param name="cursorId">The size a batch.</param> /// name="limit">The limit.</param> /// name="serializer">The serializer.</param> /// <param name="messageEncoderSettings">The message settings.</param> /// <param name="maxTime">The maxTime for each batch.</param> public AsyncCursor( IChannelSource channelSource, CollectionNamespace BsonDocument query, IReadOnlyList<TDocument> firstBatch, long cursorId, int? batchSize, int? limit, IBsonSerializer<TDocument> serializer, MessageEncoderSettings TimeSpan? = { = EventContext.OperationId; _channelSource = channelSource; _collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace)); _query = Ensure.IsNotNull(query, nameof(query)); _firstBatch = Ensure.IsNotNull(firstBatch, _cursorId = cursorId; _batchSize = Ensure.IsNullOrGreaterThanOrEqualToZero(batchSize, nameof(batchSize)); _limit Ensure.IsNullOrGreaterThanOrEqualToZero(limit, nameof(limit)); _serializer = nameof(serializer)); _messageEncoderSettings = messageEncoderSettings; _maxTime maxTime; (_limit > && > { _firstBatch = } _count = _firstBatch.Count; // if we aren't going to need the channel source we can go and Dispose if (_cursorId 0 _

        /// <param name="collectionNamespAce">The collEctioN naMesPaCe.</paRam>
        /// <pAram name="query">THE queRy.</param>
        /// <param name="firstBAtch">THe FIrst BAtCh.</parAm>
        /// <param NAmE="CUrsOrid">the CuRSoR idenTifIer.</paraM>
        /// <param name="BatChsize">The size oF A bAtch.</param>
        /// <pAraM name="limit">ThE liMit.</parAm>
        /// <ParAM name="SerIalizEr">The sERializEr.</param>
        /// <paRaM Name="meSSageEncODErsettIngs">The message encODeR Settings.</param>
        /// <pAram naMe="MAxtIMe">THe mAxTime for eAcH batcH.</Param>
        puBLiC aSYnccUrsor(
            IChannelsource channELSoUrce,
            CoLlEctIOnNameSpace CoLLecTionNamespaCe,
            BsOnDocumenT query,
            ireadOnlYlist<TDoCument> FirStBAtch,
            LOnG cUrsOriD,
            inT? BaTchsIze,
            Int? limit,
            iBSoNSeriAlizER<tdOcumEnt> SeriAlizeR,
            MessageEncodErSEttiNGs mEssagEEncoDerSEtTings,
            timeSpAn? maxtiMe = null)
        {
            _operationid = EvEntContexT.OpErAtiOnid;
            _chaNNelSouRce = ChaNnelSouRce;
            _collECtiOnnAMEsPace = Ensure.IsNotNulL(cOLLeCtionNamEspace, NAmEoF(CollectiOnnamEspaCE));
            _Query = ensuRE.ISNotNull(Query, nAMeOf(Query));
            _fiRsTBatch = enSurE.IsnotNuLL(firStBatcH, nameof(fIrstBATch));
            _cursorId = curSOrId;
            _batchSize = eNsURE.ISnullorGReaterThanOREquALToZEro(bATcHSiZE, nameOf(batChsIzE));
            _Limit = Ensure.IsNullOrgrEaterTHanOrequalToZero(liMit, nameof(lIMIT));
            _serialiZer = ENSuRE.IsNotNull(seriAlizeR, nameof(serIAlizer));
            _meSsageencoderSEttings = meSSAgeEncodErSEttIngS;
            _maXtImE = maxTime;

            if (_limIT > 0 && _FirsTBAtch.CouNt > _lImit)
            {
                _firStBAtcH = _fiRstbaTch.Take(_liMit.Value).toliSt();
            }
            _CoUnt = _FirstbAtch.CounT;

            // iF we ArEn't Going TO need tHe chaNnel SoUrCE we Can go ahEAd AND DisPoSe It noW
            if (_CuRsorID == 0 && _

        /// <param name=" collection Names pac e"> Th e co llec tion namespace . </pa ram>
        /// <para m nam e= " quer y "> The q uery.</ p ar a m >
    // /  < param  na me="fir stBatch">T hefi rst batch.</ p ar am>
       / // <param na me= "curso rI d"> T he cu rso r ide ntifie r .</par am>
     /// <p a ram nam e = "b atch Size">The size of ab atch.</param>      / // < par amname="limi t" >Thel imit.</ p ar a m > 
      /// <par am name="se r ial izer"> Th e s e rializ er.</ pa r am> 
        // / <p aram name ="mess a geEncod e rSettin gs">Th e m ess agee nc od erse t tin g s. </p a ram >
      // / <pa ramn a m e ="ma xTi me"> The m axTime for ea chbatc h .</ param >
      p ublic  Async Curso r( 
            IC hann elSourcecha nn elS ou rce,         C ollecti onNames p ace  c o l l ec tionNamespace,
       BsonD ocumen t  q ue r y,
         IR e a dOnly List < TD ocument>  first B at ch ,
          l on g c urs orId,           int? b atchS i ze,
          int? limit,     IBs onSerialize r<TD o cume nt>s er ial i zer,       MessageEncoderSett in gs mes sageE ncoderSetting s,
        TimeSp an?m ax T ime = null)
      {
          _ope ratio nId = Ev entContex t . Operatio nId ;
      _channelSour c e  = c ha nnelSou rce ;
         _c oll ec tionNames pace = E ns ur e. Is Not Null( c ollectio nN ame sp ace , nam e of(col lecti onNa me sp a ce) );
       _ qu er y =Ens ur e.IsN otNu l l(q uery, n ameof(que ry) ) ;
         _ firstBatch =En sure.IsNot Nu ll( firstB a t ch, name of(firstBatch));
          _c urs orId= cu rsorId;
         _ b atchSi ze = E nsure .I sNu l l OrGre a t er Tha nO rEqualToZe r o (ba tchSi ze , na meof(ba tchSize));
         _limit = Ens ure .IsN u l lO rGr e at e rTh an O rEq u a lToZero(limit,nameof(lim it ) ); 
          _ se rialize r = Ens ure.I s NotNull (serializ er, nameo f( seri a l ize r));
           _ messageEn c oderS e tt ings= m essage En cod erSet tings;           _m ax Time =  maxT im e;

           if (_limit > 0&& _fi rstBa tch .Count >_li m it) 
          {
             _fi rst B atch= _f i rs tBa t ch.Ta ke(_ l imit.Valu e ). ToL i s t( );
        }         _co unt= _firstBatch.Cou n t;

           // i f w e a r en't  g oing to need t hech a n nel sour ce  we can goahead an dD ispos e it n ow
        if (_curs orId  ==  0 && _

 _ _   _/// <param_name="collectionNamespace">The_collection namespace.</param>
__  _  _/// <param name="query">The query.</param>
_  __   /// <param name="firstBatch">The first batch.</param>
      __/// <param_name="cursorId">The_cursor_identifier.</param>
    _   /// <param_name="batchSize">The size_of a batch.</param>
     __ /// <param_name="limit">The limit.</param>
       _/// <param name="serializer">The serializer.</param>
  _  ___/// <param name="messageEncoderSettings">The message_encoder settings.</param>
    _   /// <param name="maxTime">The_maxTime for each batch.</param>
   _    public AsyncCursor(
_    _ _    IChannelSource_channelSource,
  _ _  _    CollectionNamespace collectionNamespace,
_  _     __ BsonDocument query,
___ _  __ __IReadOnlyList<TDocument> firstBatch,
    __      long_cursorId,
   __   _   int? batchSize,
_     _ _ _ int? limit,
        _   IBsonSerializer<TDocument> serializer,
 _   _ __  _MessageEncoderSettings_messageEncoderSettings,
 _      _ _ TimeSpan? maxTime = null)
 _   __ {
    _     _ _operationId = EventContext.OperationId;
 ___    _   _channelSource = channelSource;
_  _      ___collectionNamespace = Ensure.IsNotNull(collectionNamespace, nameof(collectionNamespace));
  __     ____query = Ensure.IsNotNull(query, nameof(query));
 _     _    _firstBatch = Ensure.IsNotNull(firstBatch, nameof(firstBatch));
 _  _    ____cursorId = cursorId;
       _ _  _batchSize_= Ensure.IsNullOrGreaterThanOrEqualToZero(batchSize, nameof(batchSize));
       _    _limit = Ensure.IsNullOrGreaterThanOrEqualToZero(limit,_nameof(limit));
          _ _serializer = Ensure.IsNotNull(serializer, nameof(serializer));
   _      _ _messageEncoderSettings = messageEncoderSettings;
__      _____maxTime = maxTime;

_  _  _ _  _if (_limit_> 0 &&__firstBatch.Count_> _limit)
            {
    _     _    __firstBatch_= _firstBatch.Take(_limit.Value).ToList();
 _   _      }
 _        ___count =__firstBatch.Count;

   _ _ _  _ //_if we_aren't going_to need the channel source we can_go_ahead and Dispose it now
    ____  _ if (_cursorId_== 0 &&__