Esempio n. 1
0
        public async Task <ICollection <GameEvent> > ReadEventsFromLog(Server server, long fileSizeDiff, long startPosition)
        {
            // allocate the bytes for the new log lines
            List <string> logLines = new List <string>();

            // open the file as a stream
            using (var rd = new StreamReader(new FileStream(LogFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Utilities.EncodingType))
            {
                // todo: max async
                // take the old start position and go back the number of new characters
                rd.BaseStream.Seek(-fileSizeDiff, SeekOrigin.End);

                string newLine;
                while (!string.IsNullOrEmpty(newLine = await rd.ReadLineAsync()))
                {
                    logLines.Add(newLine);
                }
            }

            List <GameEvent> events = new List <GameEvent>();

            // parse each line
            foreach (string eventLine in logLines)
            {
                if (eventLine.Length > 0)
                {
                    try
                    {
                        // todo: catch elsewhere
                        events.Add(Parser.GetEvent(server, eventLine));
                    }

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

            return(events);
        }
Esempio n. 2
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);
        }