DiscardBufferedData() публичный Метод

public DiscardBufferedData ( ) : void
Результат void
Пример #1
0
        public IEnumerable <Line> ReadLines(ScrollRequest scroll)
        {
            var page = GetPage(scroll);

            if (page.Size == 0)
            {
                yield break;
            }

            using (var stream = File.Open(Info.FullName, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite))
            {
                using (var reader = new StreamReaderExtended(stream, Encoding, false))
                {
                    if (page.Size == 0)
                    {
                        yield break;
                    }

                    foreach (var i in Enumerable.Range(page.Start, page.Size))
                    {
                        if (i > Count - 1)
                        {
                            continue;
                        }

                        var start         = Matches[i];
                        var startPosition = reader.AbsolutePosition();

                        if (startPosition != start)
                        {
                            reader.DiscardBufferedData();
                            reader.BaseStream.Seek(start, SeekOrigin.Begin);
                        }

                        startPosition = reader.AbsolutePosition();

                        var line        = reader.ReadLine();
                        var endPosition = reader.AbsolutePosition();
                        var info        = new LineInfo(i + 1, i, startPosition, endPosition);

                        var ontail = endPosition >= TailInfo.TailStartsAt && DateTime.Now.Subtract(TailInfo.LastTail).TotalSeconds < 1
                                    ? DateTime.Now
                                    : (DateTime?)null;

                        yield return(new Line(info, line, ontail));
                    }
                }
            }
        }
Пример #2
0
 public static IEnumerable <Line> ReadLinesByPosition(this FileInfo source, long[] positions, Func <int, bool> isEndOfTail = null)
 {
     using (var stream = File.Open(source.FullName, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite))
     {
         using (var reader = new StreamReaderExtended(stream, Encoding.Default, true))
         {
             foreach (var position in positions)
             {
                 if (reader.AbsolutePosition() != position)
                 {
                     reader.DiscardBufferedData();
                     stream.Seek(position, SeekOrigin.Begin);
                 }
                 var line = reader.ReadLine();
                 yield return(new Line((int)position, line, null));
             }
         }
     }
 }
Пример #3
0
        public static IEnumerable<Line> ReadLinesByPosition(this FileInfo source, long[] positions, Func<int, bool> isEndOfTail = null)
        {
            using (var stream = File.Open(source.FullName, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.ReadWrite))
            {
                using (var reader = new StreamReaderExtended(stream, Encoding.Default, true))
                {
                    foreach (var position in positions)
                    {
                        if (reader.AbsolutePosition() != position)
                        {
                            reader.DiscardBufferedData();
                            stream.Seek(position, SeekOrigin.Begin);

                        }
                        var line = reader.ReadLine();
                        yield return new Line((int)position, line,null);
                    }
                }
            }
        }
        public IEnumerable <Line> ReadLines(ScrollRequest scroll)
        {
            var current          = ReverseLinking(this);
            var page             = GetPage(scroll, this);
            var lastValueWrapper = new LastValueWrapper();

            if (page.Size == 0)
            {
                yield break;
            }
            while (current != null)
            {
                using (
                    var stream = File.Open(current.Info.FullName, FileMode.Open, FileAccess.Read,
                                           FileShare.Delete | FileShare.ReadWrite))
                {
                    using (var reader = new StreamReaderExtended(stream, current.Encoding, false))
                    {
                        if (page.Size == 0)
                        {
                            yield break;
                        }

                        if (lastValueWrapper.LastPageIndex == page.Start + page.Size)
                        {
                            yield break;
                        }
                        var  counter    = 0;
                        long lastEndPos = 0;
                        foreach (
                            var i in
                            Enumerable.Range(
                                lastValueWrapper.LastPageIndex > 0 ? lastValueWrapper.LastPageIndex : page.Start,
                                page.Size - counter))
                        {
                            if (i == page.Start + page.Size)
                            {
                                yield break;
                            }
                            if (i - lastValueWrapper.LastMatchesSize > current.Count - 1)
                            {
                                lastValueWrapper.LastEndPosition += lastEndPos + 1;
                                lastValueWrapper.LastMatchesSize += current.Count;
                                break;
                            }

                            var start         = current.Matches[i - lastValueWrapper.LastMatchesSize];
                            var startPosition = reader.AbsolutePosition();

                            if (startPosition != start)
                            {
                                reader.DiscardBufferedData();
                                reader.BaseStream.Seek(start, SeekOrigin.Begin);
                            }

                            startPosition = reader.AbsolutePosition();

                            var line        = reader.ReadLine();
                            var endPosition = reader.AbsolutePosition();
                            var info        = new LineInfo(i + 1, i, startPosition + lastValueWrapper.LastEndPosition,
                                                           endPosition + lastValueWrapper.LastEndPosition);

                            var ontail = endPosition >= TailInfo.TailStartsAt &&
                                         DateTime.Now.Subtract(TailInfo.LastTail).TotalSeconds < 1
                                ? DateTime.Now
                                : (DateTime?)null;

                            yield return(new Line(info, line, ontail));

                            lastValueWrapper.LastPageIndex = i + 1;
                            counter++;
                            lastEndPos = endPosition;

                            if (reader.EndOfStream)
                            {
                                lastValueWrapper.LastEndPosition += endPosition + 1;
                                lastValueWrapper.LastMatchesSize += current.Count;
                                break;
                            }
                        }
                    }
                }
                current = current.Next as FileSearchResult;
            }
        }