protected virtual void ReadFile()
        {
            while (true)
            {
                var next = Dequeue();

                if (next == null)
                {
                    Thread.Sleep(100);
                    continue;
                }

                try
                {
                    if (!lastPositionDict.ContainsKey(next))
                    {
                        lastPositionDict.Add(next, 0L);
                        fileStatistics.Add(next, new TailStatistics());
                    }

                    StartCallback?.Invoke(initialLoad);
                    var totalLineCount = 0;
                    var minLineCount   = 0;
                    var clear          = false;
                    using (var reader = readerFactory.CreateReader(next))
                    {
                        var loadLastLines = LoadLastLines();
                        if (initialLoad && loadLastLines >= 0 && lastPositionDict[next] == 0)
                        {
                            totalLineCount = reader.CountLines();
                            minLineCount   = totalLineCount > loadLastLines ? totalLineCount - loadLastLines : 0;
                        }

                        var lastPosition = lastPositionDict[next];

                        if (lastPosition > reader.Length)
                        {
                            lastPositionDict[next] = lastPosition = 0L;
                            fileStatistics[next].Reset();
                            initialLoad = true;
                            StartCallback?.Invoke(initialLoad);
                            clear = true;
                        }

                        reader.Seek(lastPosition);
                        ReadLines(reader, next, minLineCount, clear);
                        lastPositionDict[next] = reader.Position;
                    }

                    FinishCallback?.Invoke(initialLoad, fileStatistics[next]);
                    initialLoad = false;
                }
                catch (Exception ex)
                {
                    ExceptionCallback?.Invoke(ex);
                }
            }
        }
Beispiel #2
0
        public void Start()
        {
            _IsDone = false;
            StartCallback?.Invoke(this, new EventArgs());
            if (_IsDone)
            {
                return;
            }

            _IsPlaying = true;
            synchronizationContext.Post((o) => {
                timer1.Enabled = true;
            }, null);
        }
Beispiel #3
0
 void Start() => StartCallback?.Invoke();