Example #1
0
        public int FillCache(LogFileStream logFileStream, int endindex)
        {
            if (endindex > FirstIndex + Items.Count)
            {
                return(-1);
            }

            int lastItem = Items.Count - 1;

            for (int i = 0; i < Items.Count; i++)
            {
                if (FirstIndex + i > endindex)
                {
                    lastItem = i - 1;
                    break;
                }

                if (Items[i] != null)
                {
                    continue;   // Already cached
                }
                if (i == 0)
                {
                    // We are filling the cache
                    if (FillCacheEvent != null)
                    {
                        FillCacheEvent(this, null);
                    }
                }

                string line = logFileStream.ReadLine(FirstIndex + i + 1);
                if (line == null)
                {
                    lastItem = i - 1;
                    break;
                }

                Items[i] = new ListViewItem(line);
                Items[i].SubItems.Add("");
            }

            // We are done filling the cache
            if (FillCacheEvent != null)
            {
                FillCacheEvent(null, null);
            }

            if (lastItem != Items.Count - 1)
            {
                return(lastItem);
            }
            else
            {
                return(Items.Count - 1);
            }
        }
Example #2
0
        public int FillCache(LogFileStream logFileStream, int endindex)
        {
            if (endindex > FirstIndex + Items.Count)
                return -1;

            int lastItem = Items.Count - 1;

            for (int i = 0; i < Items.Count; i++)
            {
                if (FirstIndex + i > endindex)
                {
                    lastItem = i - 1;
                    break;
                }

                if (Items[i] != null)
                    continue;   // Already cached

                if (i == 0)
                {
                    // We are filling the cache
                    if (FillCacheEvent != null)
                        FillCacheEvent(this, null);
                }

                string line = logFileStream.ReadLine(FirstIndex + i + 1);
                if (line == null)
                {
                    lastItem = i - 1;
                    break;
                }

                Items[i] = new ListViewItem(line);
                Items[i].SubItems.Add("");
            }

            // We are done filling the cache
            if (FillCacheEvent != null)
                FillCacheEvent(null, null);

            if (lastItem != Items.Count - 1)
                return lastItem;
            else
                return Items.Count - 1;
        }
Example #3
0
        public int FillTailCache(LogFileStream logFileStream)
        {
            int lineCount = 0;

            // Quickly fast forward to near the file bottom
            if (!logFileStream.CloseToEnd(Items.Count))
            {
                do
                {
                    if (logFileStream.ReadLine(lineCount + 1) != null)
                        lineCount++;

                    // We have read a good part of the file
                    if (lineCount % Items.Count == 0)
                    {
                        if (LoadingFileEvent != null)
                            LoadingFileEvent(logFileStream, null);
                    }
                }
                while (!logFileStream.CloseToEnd(Items.Count));

                // We are almost finished with loading the file
                if (LoadingFileEvent != null)
                    LoadingFileEvent(null, null);
            }

            // Read the last lines of the file into the cache
            bool continueReading = false;
            PrepareCache(lineCount, lineCount, true);
            do
            {
                int lastCacheIndex = FillCache(logFileStream, FirstIndex + Items.Count);
                System.Diagnostics.Debug.Assert(lastCacheIndex != -1 || logFileStream.Length == 0);
                continueReading = (lastCacheIndex == Items.Count - 1);
                lineCount = FirstIndex + lastCacheIndex + 1;
                if (continueReading)
                    PrepareCache(lineCount + Items.Count / 2, lineCount + Items.Count / 2, true);
            } while (continueReading);

            return lineCount;
        }