Skip to content

Commit

Permalink
Diagnostic output update
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyTarget committed Jun 19, 2015
1 parent c655ffc commit 732ae46
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions PollingEngine/Implementations/SteamPoller/SteamPoller2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ private async Task PollGamingInfo_Portable(PollingContext context, IList<SteamId
var fullDuration = time.Subtract(mostRecentSession.Time);
currentSession.Duration = fullDuration;
currentSession.SessionID = mostRecentSession.SessionID;
Console.WriteLine("Continuing game session: " + currentSession);
}
else
Console.WriteLine("Time diff to big, will not continue game session. Time diff: " + timeDiff);
}
}
gamerInfo.ActiveSession = currentSession;
Expand Down Expand Up @@ -411,6 +414,7 @@ private async Task StoreUserGameStats(int gameID, SteamIdentity steamIdentity, I
if (_odbc.State != ConnectionState.Open)
_odbc.Open();
var time = DateTime.UtcNow;
var changes = 0;
foreach (var stat in stats)
{
try
Expand All @@ -425,15 +429,17 @@ private async Task StoreUserGameStats(int gameID, SteamIdentity steamIdentity, I
cmd.Parameters.AddWithValue("@Time", time.ToUniversalTime());
cmd.Parameters.AddWithValue("@Name", stat.Name);
cmd.Parameters.AddWithValue("@Value", stat.Value);

var changes = await cmd.ExecuteNonQueryAsync();
var c = await cmd.ExecuteNonQueryAsync();
if (c > 0)
changes += c;
}
catch (Exception ex)
{
Console.WriteLine(ex);
//throw;
}
}
Console.WriteLine("{0}, {1} - Stats stored: {2}", GetPlayerAlias(steamIdentity), GetGameNameFromGameID(gameID), changes);
}


Expand All @@ -444,6 +450,7 @@ private async Task StoreUserGameAchievements(int gameID, SteamIdentity steamIden
if (_odbc.State != ConnectionState.Open)
_odbc.Open();
var time = DateTime.UtcNow;
var changes = 0;
foreach (var achive in achievements)
{
try
Expand All @@ -458,15 +465,17 @@ private async Task StoreUserGameAchievements(int gameID, SteamIdentity steamIden
cmd.Parameters.AddWithValue("@Time", time.ToUniversalTime());
cmd.Parameters.AddWithValue("@Name", achive.Name);
cmd.Parameters.AddWithValue("@Achieved", achive.Achieved);

var changes = await cmd.ExecuteNonQueryAsync();
var c = await cmd.ExecuteNonQueryAsync();
if (c > 0)
changes += c;
}
catch (Exception ex)
{
Console.WriteLine(ex);
//throw;
}
}
Console.WriteLine("{0}, {1} - Achievements stored: {2}", GetPlayerAlias(steamIdentity), GetGameNameFromGameID(gameID), changes);
}


Expand Down Expand Up @@ -606,6 +615,51 @@ private async Task<GamingSession> GetUserLastGamingSession(SteamIdentity steamId
}
}

private string GetPlayerAlias(SteamIdentity steamIdentity)
{
string res = null;
try
{
var gamingInfo = _data.Where(x => x.Key.SteamID == steamIdentity.SteamID).Select(x => x.Value).FirstOrDefault();
if (gamingInfo != null)
{
var player = gamingInfo.Sessions.Where(x => x.Player != null).Select(x => x.Player).FirstOrDefault();
if (player != null)
{
res = player.PersonaName;
}
}
}
catch (Exception ex)
{
Debug.WriteLine("Error getting player alias");
Debug.WriteLine(ex);
res = steamIdentity.SteamID.ToString();
}
return res;
}

private string GetGameNameFromGameID(long gameID)
{
string res = null;
try
{
var sessions = _data.Select(x => x.Value).SelectMany(x => x.Sessions);
var session = sessions.FirstOrDefault(x => x.Player != null && x.Player.GameID == gameID.ToString());
if (session != null)
{
res = session.Player.GameExtraInfo;
}
}
catch (Exception ex)
{
Debug.WriteLine("Error getting game name");
Debug.WriteLine(ex);
res = "#" + gameID;
}
return res;
}


[Obsolete("Should be moved to the application implementing using PollingData")]
private string WritePopularStats(List<StatDiff> diffs, int gameID)
Expand Down

0 comments on commit 732ae46

Please sign in to comment.