Is this code good enough, or is it stinky?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace DotNetLegends
{
public class LogParser
{
/// <summary>
/// Returns a populated Game objects that has a list of players and other information.
/// </summary>
/// <param name="pathToLog">Path to the .log file.</param>
/// <returns>A Game object.</returns>
public Game Parse(string pathToLog)
{
Game game = new Game();
//On actual deployment of this code, I will use the pathToLog parameter.
StreamReader reader = new StreamReader(@"D:\Games\Riot Games\League of Legends\air\logs\LolClient.20110121.213758.log");
var content = reader.ReadToEnd();
game.Id = GetGameID(content);
game.Length = GetGameLength(content);
game.Map = GetGameMap(content);
game.MaximumPlayers = GetGameMaximumPlayers(content);
game.Date = GetGameDate(content);
return game;
}
internal string GetGameID(string content)
{
var location = content.IndexOf("gameId");
var gameID = content.Substring(location + 8, 10);
gameID = gameID.Trim();
return gameID;
}
internal string GetGameLength(string content)
{
var location = content.IndexOf("gameLength");
var gamelength = content.Substring(location + 13, 6);
gamelength = gamelength.Trim();
var time = Convert.ToInt32(gamelength) / 60;
return time.ToString();
}
internal string GetGameMap(string content)
{
var location = content.IndexOf("mapId");
var gameMap = content.Substring(location + 8, 1);
switch (gameMap)
{
case "2":
return "Summoner's Rift";
default:
return "nul";
}
}
internal string GetGameMaximumPlayers(string content)
{
var location = content.IndexOf("maxNumPlayers");
var maxPlayers = content.Substring(location + 16, 2);
maxPlayers = maxPlayers.Trim();
return maxPlayers;
}
internal string GetGameDate(string content)
{
var location = content.IndexOf("creationTime");
var creationDate = content.Substring(location + 14, 34);
creationDate = creationDate.Trim();
return creationDate;
}
}
}