Ejemplo n.º 1
0
 static IEnumerableAsync <FileRange.Range> IterateMatchRanges(
     IEnumerableAsync <Checkpoint> checkpoints, long threshhold, ProgressAndCancellation progressAndCancellation)
 {
     return(EnumerableAsync.Produce <FileRange.Range>(async yieldAsync =>
     {
         FileRange.Range?lastMatch = null;
         await checkpoints.ForEach(async checkpoint =>
         {
             if (lastMatch == null)
             {
                 if (checkpoint.IsMatch)
                 {
                     lastMatch = new FileRange.Range(checkpoint.Position, checkpoint.EndPosition);
                 }
                 else
                 {
                     progressAndCancellation.continuationToken.NextPosition = checkpoint.EndPosition;
                     progressAndCancellation.HandleTextIterationProgress(checkpoint.EndPosition);
                 }
             }
             else
             {
                 FileRange.Range lastMatchVal = lastMatch.Value;
                 if (checkpoint.Position - lastMatchVal.End < threshhold)
                 {
                     if (checkpoint.IsMatch)
                     {
                         lastMatch = new FileRange.Range(lastMatchVal.Begin, checkpoint.EndPosition);
                     }
                 }
                 else
                 {
                     await yieldAsync.YieldAsync(lastMatchVal);
                     progressAndCancellation.continuationToken.NextPosition = checkpoint.EndPosition;
                     progressAndCancellation.HandleTextIterationProgress(checkpoint.EndPosition);
                     if (checkpoint.IsMatch)
                     {
                         lastMatch = new FileRange.Range(checkpoint.Position, checkpoint.EndPosition);
                     }
                     else
                     {
                         lastMatch = null;
                     }
                 }
             }
             return true;
         });
         if (lastMatch != null)
         {
             await yieldAsync.YieldAsync(lastMatch.Value);
         }
     }));
 }
Ejemplo n.º 2
0
        static IEnumerable <FileRange.Range> IterateMatchRanges(
            IEnumerable <Checkpoint> checkpoints, long threshhold, ProgressAndCancellation progressAndCancellation)
        {
            FileRange.Range?lastMatch = null;
            foreach (var checkpoint in checkpoints)
            {
                if (lastMatch == null)
                {
                    if (checkpoint.IsMatch)
                    {
                        lastMatch = new FileRange.Range(checkpoint.Position, checkpoint.EndPosition);
                    }
                    else
                    {
                        progressAndCancellation.continuationToken.NextPosition = checkpoint.EndPosition;
                        progressAndCancellation.HandleTextIterationProgress(checkpoint.EndPosition);
                    }
                }
                else
                {
                    FileRange.Range lastMatchVal = lastMatch.Value;
                    if (checkpoint.Position - lastMatchVal.End < threshhold)
                    {
                        if (checkpoint.IsMatch)
                        {
                            lastMatch = new FileRange.Range(lastMatchVal.Begin, checkpoint.EndPosition);
                        }
                    }
                    else
                    {
                        yield return(lastMatchVal);

                        progressAndCancellation.continuationToken.NextPosition = checkpoint.EndPosition;
                        progressAndCancellation.HandleTextIterationProgress(checkpoint.EndPosition);
                        if (checkpoint.IsMatch)
                        {
                            lastMatch = new FileRange.Range(checkpoint.Position, checkpoint.EndPosition);
                        }
                        else
                        {
                            lastMatch = null;
                        }
                    }
                }
            }
            if (lastMatch != null)
            {
                yield return(lastMatch.Value);
            }
        }