Ejemplo n.º 1
0
        public void Read(string file)
        {
            if (NewLines == null)
            {
                Assert.Fail("NewLines has no listeners");
            }
            var lines = File.ReadLines(file).Select(x => new Line("Power", x));

            NewLines.Invoke(new NewLinesEventArgs(lines));
        }
Ejemplo n.º 2
0
        internal async void Start(string hearthstonePath, string logDirectory = "Logs")
        {
            if (_running)
            {
                return;
            }
            Starting?.Invoke();
            var fullPath      = Path.Combine(hearthstonePath, "Logs");
            var startingPoint = GetStartingPoint(fullPath);

            Log.Debug($"Starting log readers in \"{fullPath}\", at [{startingPoint}]");
            foreach (var logReader in _watchers)
            {
                logReader.Start(fullPath, logReader.Info.Name == "Decks" ? startingPoint.Decks : startingPoint.Default);
            }
            _running = true;
            _stop    = false;
            var newLines = new SortedList <DateTime, List <Line> >();

            while (!_stop)
            {
                await Task.Factory.StartNew(() =>
                {
                    foreach (var logReader in _watchers)
                    {
                        var lines = logReader.Collect();
                        foreach (var line in lines)
                        {
                            if (!newLines.TryGetValue(line.Time, out var logLines))
                            {
                                newLines.Add(line.Time, logLines = new List <Line>());
                            }
                            logLines.Add(line);
                        }
                    }
                });

                NewLines?.Invoke(new NewLinesEventArgs(newLines.Values.SelectMany(x => x)));
                newLines.Clear();
                await Task.Delay(UpdateDelay);
            }
            _running = false;
        }