Ejemplo n.º 1
0
        static (Records, Records) ParseFile(this string path)
        {
            Error.WriteLine($"*** parsing {path}");

            var    showActionResult = new Records();
            var    gameOverResult   = new Records();
            string line;
            int    ln = 0;

            using (var file = new StreamReader(path))
            {
                while ((line = file.ReadLine()) != null)
                {
                    ln++;
                    var match = LinePattern.Match(line);
                    if (!match.Success || match.Groups["level"].Value != "INFO")
                    {
                        continue;
                    }
                    var match2 = EventPattern.Match(match.Groups["message"].Value);
                    if (!match2.Success || !new[] { "SHOW_ACTION", "GAME_OVER" }.Contains(match2.Groups["event"].Value))
                    {
                        continue;
                    }
                    var record = Record.Parse(match2.Groups["json"].Value, path, ln);
                    if (record != null && record.data.Canonicalize())
                    {
                        switch (match2.Groups["event"].Value)
                        {
                        case "SHOW_ACTION":
                            showActionResult[DateTime.Parse(match.Groups["time"].Value)] = record;
                            break;

                        case "GAME_OVER":
                            gameOverResult[DateTime.Parse(match.Groups["time"].Value)] = record;
                            break;
                        }
                    }
                }
            }
            if (showActionResult.Count == 0 && gameOverResult.Count == 0)
            {
                Error.WriteLine("    Deleting the file because it contains no useful data");
                File.Delete(path);
            }
            return(showActionResult, gameOverResult);
        }