示例#1
0
        public async Task <ICollection <GameEvent> > ReadEventsFromLog(Server server, long fileSizeDiff, long startPosition)
        {
#if DEBUG == true
            server.Logger.WriteDebug($"Begin reading from http log");
#endif
            var    events   = new List <GameEvent>();
            string b64Path  = logPath;
            var    response = await Api.Log(b64Path);

            if (!response.Success)
            {
                server.Logger.WriteError($"Could not get log server info of {logPath}/{b64Path} ({server.LogPath})");
                return(events);
            }

            // parse each line
            foreach (string eventLine in response.Data.Split(Environment.NewLine))
            {
                if (eventLine.Length > 0)
                {
                    try
                    {
                        var e = Parser.GetEvent(server, eventLine);
#if DEBUG == true
                        server.Logger.WriteDebug($"Parsed event with id {e.Id}  from http");
#endif
                        events.Add(e);
                    }

                    catch (Exception e)
                    {
                        server.Logger.WriteWarning("Could not properly parse event line");
                        server.Logger.WriteDebug(e.Message);
                        server.Logger.WriteDebug(eventLine);
                    }
                }
            }

            return(events);
        }
示例#2
0
        public async Task <IEnumerable <GameEvent> > ReadEventsFromLog(long fileSizeDiff, long startPosition)
        {
            var events   = new List <GameEvent>();
            var response = await _logServerApi.Log(_safeLogPath, lastKey);

            lastKey = response.NextKey;

            if (!response.Success && string.IsNullOrEmpty(lastKey))
            {
                _logger.WriteError($"Could not get log server info of {_safeLogPath}");
                return(events);
            }

            else if (!string.IsNullOrWhiteSpace(response.Data))
            {
                // parse each line
                var lines = response.Data
                            .Split(Environment.NewLine)
                            .Where(_line => _line.Length > 0);

                foreach (string eventLine in lines)
                {
                    try
                    {
                        // this trim end should hopefully fix the nasty runaway regex
                        var gameEvent = _eventParser.GenerateGameEvent(eventLine.TrimEnd('\r'));
                        events.Add(gameEvent);
                    }

                    catch (Exception e)
                    {
                        _logger.WriteError("Could not properly parse event line from http");
                        _logger.WriteDebug(e.Message);
                        _logger.WriteDebug(eventLine);
                    }
                }
            }

            return(events);
        }