Exemplo n.º 1
0
        public Task FlushAsync()
        {
            Action flushAction = () =>
            {
                LogEntryEventArgs args;
                while (_eventQueue.TryDequeue(out args))
                {
                    LogEntryCollection.AddLast(new LogEntryEventArgsViewModel(args));
                }
            };

            return(_asyncUiThreadRunner.Invoke(flushAction));
        }
Exemplo n.º 2
0
        public override DispatcherOperation LoadEntries(uint startFromID)
        {
            if (startFromID > Log9KEntry.Counter)
            {
                return(null);
            }
            startFromID--;
            if (IsAddingNewestEntries)
            {
                IsAddingNewestEntries = false;
            }
            if (ScrollToLastLog)
            {
                ScrollToLastLog = false;
            }

            uint lineNumber;

            if (startFromID == 0)
            {
                return(null);
            }

            if (Application.Current == null)
            {
                return(null);
            }

            DispatcherOperation a = Application.Current.Dispatcher.BeginInvoke(new Action(() => {
                if (!FindLineNumber(startFromID, out lineNumber))
                {
                    Log9KCore.Instance.InnerLog("Ошибка: при загрузке логов метод FindLineNumber вернул false");
                    return;
                }

                LineNumberTopTempFile = lineNumber;
                LogEntryCollection.Clear();
                for (int i = 0; i < LogEntryCollection.MaxCollectionSize; i++)
                {
                    Log9KEntry entry = ReadEntry(lineNumber);
                    if (entry == null)
                    {
                        break;
                    }
                    LogEntryCollection.Add(entry);
                    lineNumber++;
                }
            }), DispatcherPriority.Background);

            return(a);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load most recent logs from temporary file
        /// </summary>
        public override void LoadLastLogs()
        {
            LogEntryCollection.StartRemovingFromTop();
            LogEntryCollection.Clear();

            uint entriesNumber;
            bool success = Log9KUtil.GetEntriesNumberInFile(
                FilenameTempFile, Log9KEntry.ENTRY_SIZE, out entriesNumber
                );

            if (!success)
            {
                Log9KCore.Instance.InnerLog("Ошибка: метод Log9KUtil.GetEntriesNumberInFile вернул false");
                return;
            }

            if (Application.Current == null)
            {
                return;
            }
            Application.Current.Dispatcher.BeginInvoke(
                new Action(() => {
                bool notEnd = true;
                uint z      = 0;
                for (uint i = entriesNumber; notEnd; i--)
                {
                    Log9KEntry e = ReadEntry(i);
                    if (e != null)
                    {
                        LogEntryCollection.Insert(0, e);
                    }
                    if (i == 0 || z >= LogEntryCollection.MaxCollectionSize)
                    {
                        notEnd = false;
                    }
                    z++;
                }
            }),
                DispatcherPriority.Background
                );
        }
Exemplo n.º 4
0
        private void FilterApplyToCollection(uint lineStart, uint lineEnd)
        {
            IsAddingNewestEntries = false;
            LogEntryCollection.Clear();
            uint i = 0;

            for (uint j = lineStart; j < lineEnd; j++)
            {
                Log9KEntry entry = ReadEntry(j);
                if (entry != null)
                {
                    CollectionAdd(entry);
                    i++;
                }
                if (i >= LogEntryCollection.MaxCollectionSize)
                {
                    break;
                }
            }
            LineNumberTopTempFile = lineStart;
        }
Exemplo n.º 5
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);
        }