コード例 #1
0
        private static void WriteUpdatedGamesData(HttpResponseMessage response)
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                Log.Error("Failed to update games data. Received response {Message} with Status {Status}", response.ReasonPhrase, response.StatusCode);
                SystemTrayForm.ShowBalloonError($"Failed to update games data. Received response {response.ReasonPhrase} with Status {response.StatusCode}");
            }

            response.Content.ReadAsStringAsync().ContinueWith(contentTask =>
            {
                Log.Information("Updating {GamesJsonPath} with new game information", GamesFilePath);

                try
                {
                    var json             = contentTask.Result;
                    var newGamesMetadata = JsonSerializer.Deserialize <GamesConfigurationFile>(json, GameTrackerService.JsonOptions);

                    if (newGamesMetadata?.Games == null)
                    {
                        throw new Exception("Downloaded json but was not a valid format.");
                    }

                    var overview = GetOverviewOfGameUpdates(newGamesMetadata);

                    return(File.WriteAllTextAsync(GamesFilePath, json).ContinueWith((t) => { SystemTrayForm.ShowBalloonInfo(overview); }));
                }
                catch (Exception e)
                {
                    Log.Error("Failed to update games data. Threw exception {Exception}", e.ToString());
                    SystemTrayForm.ShowBalloonError($"Failed to update games data. Threw exception {e}");

                    return(Task.CompletedTask);
                }
            });
        }
コード例 #2
0
        public bool TryCreateActivity(ProcessSession processSession, out UserActivity userActivity)
        {
            if (!_gameMatcher.TryMatch(processSession.FilePath, out var matchedGame))
            {
                userActivity = null;
                Log.Debug("Failed to match {FilePath}", processSession.FilePath);
                return(false);
            }

            userActivity = _userActivityFactory.Create(processSession, matchedGame);
            Log.Debug("Created user activity for game {GameId}.", matchedGame.GameId);
            SystemTrayForm.ShowBalloonInfo($"Played {matchedGame.Name} for {(processSession.EndTime - processSession.StartTime).HumanReadable()}.");
            return(true);
        }