Пример #1
0
        /// <summary>
        /// This class will live-read a combat log found at FilePath and print to the console any time it finds a UNIT_DIED event
        /// </summary>
        public LiveParsing(string FilePath)
        {
            if (!File.Exists(FilePath))
            {
                throw new FileNotFoundException("Combat log not found", FilePath);
            }

            _fileInfo = new FileInfo(FilePath);
            LogParser = new CombatLogParser(FilePath);

            //Set initial position to 0 to parse existing file before live monitoring, or _fileInfo.Length to skip existing file and only read future changes
            long lastSeekPos = _fileInfo.Length;

            LogParser.PreParseEvent  += (clp, fs) => { fs.Position = lastSeekPos; };
            LogParser.PostParseEvent += (clp, fs) => { lastSeekPos = fs.Position; };

            _fsw                     = new FileSystemWatcher();
            _fsw.Path                = _fileInfo.DirectoryName;
            _fsw.NotifyFilter        = NotifyFilters.LastWrite;
            _fsw.Filter              = _fileInfo.Name;
            _fsw.EnableRaisingEvents = true;
            _fsw.Changed            += (x, y) =>
            {
                LogParser.ParseToEnd();
            };


            if (lastSeekPos != _fileInfo.Length)
            {
                LogParser.ParseToEnd();
            }
        }
        public UnhandledEventFinder(string path)
        {
            _clp = new CombatLogParser(path);

            // Will only be raised if the combat log at path has a line with an unrecognized event
            // Mostly used for extending the Events API
            _clp.OnUnhandledEvent += (s, e) =>
            {
                Console.WriteLine("Unhandled Event - " + e.ToString());
            };

            _clp.ParseToEnd();
        }
Пример #3
0
        /// <summary>
        /// This class will live-read a combat log found at FilePath and print to the console any time it finds a UNIT_DIED event
        /// </summary>
        public LiveParsing(string FilePath)
        {
            if (!File.Exists(FilePath))
            {
                throw new FileNotFoundException("Combat log not found", FilePath);
            }

            _fileInfo = new FileInfo(FilePath);
            _clp      = new CombatLogParser(FilePath);

            //Set initial position to 0 to parse existing file before live monitoring, or _fileInfo.Length to skip existing file and only read future changes
            long lastSeekPos = _fileInfo.Length;

            _clp.PreParseEvent  += (clp, fs) => { fs.Position = lastSeekPos; };
            _clp.PostParseEvent += (clp, fs) => { lastSeekPos = fs.Position; };

            _clp.RegisterEvent((s, e) =>
            {
                string name = e.Get(UNIT_DIED.UnitName);
                Console.WriteLine($"Unit {name} died");
            }, Events.UNIT_DIED);

            _fsw                     = new FileSystemWatcher();
            _fsw.Path                = _fileInfo.DirectoryName;
            _fsw.NotifyFilter        = NotifyFilters.LastWrite;
            _fsw.Filter              = _fileInfo.Name;
            _fsw.EnableRaisingEvents = true;
            _fsw.Changed            += (x, y) =>
            {
                _clp.ParseToEnd();
            };


            if (lastSeekPos != _fileInfo.Length)
            {
                _clp.ParseToEnd();
            }
        }