Exemplo n.º 1
0
        /// <summary>
        /// Load one older log entry from temp file
        /// </summary>
        /// <returns></returns>
        public override bool LoadOlderLogEntry()
        {
            if (IsAddingNewestEntries)
            {
                return(false);
            }
            if (LineNumberTopTempFile == 0 && LogEntryCollection[0].ID < 1)
            {
                return(false);
            }
            Log9KEntry entry   = null;
            bool       success = false;
            uint       tries   = 0;

            while (!success)
            {
                if (tries > 100)
                {
                    break;
                }

                entry = ReadEntry(LineNumberTopTempFile);
                if (entry == null)
                {
                    return(false);
                }

                uint firstLogEntryInCollectionID = LogEntryCollection[0].ID;
                uint entryIDshoulBe = firstLogEntryInCollectionID - 1;
                if (entry.ID != entryIDshoulBe)
                {
                    if (entry.ID < entryIDshoulBe)
                    {
                        LineNumberTopTempFile++;
                    }
                    else if (entry.ID > entryIDshoulBe)
                    {
                        LineNumberTopTempFile--;
                    }
                }
                else
                {
                    success = true;
                }

                tries++;
            }
            if (tries > 100)
            {
                uint lineNumber = LineNumberTopTempFile;
                for (int i = 0; i < 30; i++)
                {
                    lineNumber--;
                    if (ReadOlderLogEntryAndCheckIt(out entry, lineNumber))
                    {
                        LineNumberTopTempFile = lineNumber;
                        break;
                    }
                }
                for (int i = 0; i < 30; i++)
                {
                    lineNumber++;
                    if (ReadOlderLogEntryAndCheckIt(out entry, lineNumber))
                    {
                        LineNumberTopTempFile = lineNumber;
                        break;
                    }
                }
            }
            if (entry == null || LogEntryCollection.Contains(entry))
            {
                uint lineNumber;
                if (FindLineNumber(LogEntryCollection[0].ID - 1, out lineNumber))
                {
                    entry = ReadEntry(lineNumber);
                }
            }
            if (entry != null)
            {
                CollectionInsert(0, entry);
            }
            return(true);
        }