Exemple #1
0
 // returns false if log processing should not continue
 bool ProcessLogPath(string path)
 {
     try
     {
         FileInfo information = new FileInfo(path);
         long size = information.Length;
         LogStatus status;
         bool doProcessLog = false;
         lock (history)
         {
             if (!running)
                 return false;
             if (history.logMap.ContainsKey(path))
             {
                 status = history.logMap[path];
                 if (status.LogHasChanged(size))
                 {
                     // there is new data to be parsed
                     doProcessLog = true;
                 }
             }
             else
             {
                 // it's a new file which is not part of the history yet
                 status = new LogStatus();
                 history.logMap.Add(path, status);
                 doProcessLog = true;
             }
         }
         if (doProcessLog)
         {
             StreamReader reader = new StreamReader(path, Encoding.Default);
             reader.BaseStream.Seek(status.offset, SeekOrigin.Begin);
             int bufferSize = (int)(size - status.offset);
             char[] buffer = new char[bufferSize];
             reader.Read(buffer, 0, bufferSize);
             reader.Close();
             string contents = new string(buffer);
             if (!running)
                 return true;
             bool noNetworkErrorOccurred = ProcessLogContents(path, status, contents);
             return noNetworkErrorOccurred;
         }
     }
     catch (IOException exception)
     {
         PrintLine("An error occurred during the processing of \"" + path + "\": " + exception.Message);
     }
     return true;
 }
Exemple #2
0
        // returns false when a network error occurred
        bool ProcessLogContents(string path, LogStatus status, string contents)
        {
            string beginningMarker = "  body = (com.riotgames.platform.gameclient.domain::EndOfGameStats)#1";
            string endMarker = "\n  timeToLive = 0";
            for (int offset = 0; offset < contents.Length; )
            {
                int beginningOffset = contents.IndexOf(beginningMarker, offset);
                if (beginningOffset == -1)
                    break;
                int endOffset = contents.IndexOf(endMarker, beginningOffset);
                if (endOffset == -1)
                {
                    PrintLine("Encountered an incomplete end of game stats section in \"" + path + "\"");
                    break;
                }
                offset = endOffset + endMarker.Length;
                string endOfGameStats = contents.Substring(beginningOffset, endOffset - beginningOffset);

                endOffset = contents.LastIndexOf('\n', beginningOffset);
                if (endOffset == -1)
                {
                    PrintLine("Unable to locate the preceding line");
                    break;
                }
                beginningOffset = contents.LastIndexOf('\n', endOffset - 1);
                if (beginningOffset == -1)
                {
                    PrintLine("Unable to determine the beginning of the preceding line");
                    break;
                }
                beginningOffset++;
                string precedingLine = contents.Substring(beginningOffset, endOffset - beginningOffset);
                string timeZonestring = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalSeconds.ToString();
                string output = timeZonestring + "\n" + precedingLine + "\n" + endOfGameStats;
                PrintLine("Discovered stats for a game of size " + endOfGameStats.Length.ToString() + " in file \"" + path + "\"");
                if (!TransmitContents(output))
                    return false;
            }
            lock (history)
            {
                if (!running)
                    return true;
                status.offset = contents.Length;
            }
            return true;
        }