Example #1
0
        private void GameExited(object context, int exitCode)
        {
            Game game = (Game)context;

            if (exitCode != 0)
            {
                View.Invoke(() =>
                {
                    var presenter = SubmitCoreErrorPresenter.Create(game, game.Name + " has ended unexpectedly",
                                                                    "An unhandled exception or fatal MGDF error has occurred");
                    presenter.ShowView(View);
                });
            }
            else if (StatisticsSession.CanSendStatistics(Game.Current))
            {
                IFile statisticsFile = FileSystem.Current.GetFile(Resources.UserStatistics());
                if (statisticsFile.Exists)
                {
                    try
                    {
                        if (StatisticsSession.GetStatisticsPermission(Game.Current, GetStatisticsPermission))
                        {
                            Logger.Current.Write(LogInfoLevel.Info, "Sending statistics...");
                            StatisticsSession session = new StatisticsSession(Game.Current.Uid, Game.Current.StatisticsService, statisticsFile.FullName);
                            if (session.Bundles.Count > 0)
                            {
                                StatisticsServiceClient client = new StatisticsServiceClient(session);

                                List <String> errors = new List <string>();
                                client.SendStatistics(errors);
                                foreach (var error in errors)
                                {
                                    Logger.Current.Write(LogInfoLevel.Error, error);
                                }
                            }
                            Logger.Current.Write(LogInfoLevel.Info, "Statistics sent.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Current.Write(ex, "Unable to send statistics");
                    }
                    finally
                    {
                        statisticsFile.DeleteWithTimeout();
                    }
                }
            }
            else if (!string.IsNullOrEmpty(Game.Current.StatisticsService))
            {
                Logger.Current.Write(LogInfoLevel.Warning, "Cannot send statistics due to missing privacy policy url");
            }

            View.Invoke(() =>
            {
                _workerThread = null;
                View.CloseView();
            });
        }
Example #2
0
        public void TestCanSendStatisticsDeniedNoPrivacyPolicy()
        {
            const string gameContent = @"{
  ""gameUid"":""Console"",
  ""gameName"":""Lua Console"",
  ""description"":""A Lua command console for interacting with the MGDF system"",
  ""version"":""0.1"",
  ""interfaceVersion"":""1"",
  ""developerUid"":""no-8"",
  ""developerName"":""no8 interactive"",
  ""homepage"":""http://www.junkship.org"",
  ""gamesourceService"":""http://games.junkship.org/gamesource.asmx"",
  ""statisticsService"":""http://statistics.junkship.org/statisticsservice.asmx"",
  ""supportEmail"":""*****@*****.**""
}";

            MockDirectory gameDirectory = ((MockDirectory)MockFileSystem.GetDirectory(EnvironmentSettings.Current.AppDirectory + "\\game"));

            gameDirectory.AddFile("game.json", gameContent);
            Game game = new Game(Path.Combine(EnvironmentSettings.Current.AppDirectory, "game\\game.json"));

            Assert.IsFalse(StatisticsSession.CanSendStatistics(game));
        }