Exemple #1
0
        public void TestGetStatisticsPermissionNoCachedPermission(bool allow)
        {
            const string gmeContent = @"{
  ""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"",
  ""statisticsPrivacyPolicy"":""http://www.junkship.org/privacy"",
  ""supportEmail"":""*****@*****.**""
}";

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

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

            Resources.InitUserDirectory("Console", false);

            Assert.AreEqual(allow, StatisticsSession.GetStatisticsPermission(game, args => allow));

            Assert.AreEqual(SettingsManager.Instance.Settings.GameUid, "Console");
            Assert.AreEqual(allow, SettingsManager.Instance.Settings.StatisticsServiceEnabled.Value);
        }
Exemple #2
0
        public void TestGetStatisticsPermissionCachedPermission()
        {
            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"",
  ""statisticsprivacypolicy"":""http://www.junkship.org/privacy"",
  ""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"));

            Resources.InitUserDirectory("Console", false);
            SettingsManager.Instance.Settings         = new GameSettings();
            SettingsManager.Instance.Settings.GameUid = "Console";
            SettingsManager.Instance.Settings.StatisticsServiceEnabled = true;
            SettingsManager.Instance.Save();

            Assert.IsTrue(StatisticsSession.GetStatisticsPermission(game, args =>
            {
                Assert.Fail("This get permission callback shouldn't be called when the permission has been cached");
                return(false);
            }));
        }
Exemple #3
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();
            });
        }