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); }
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); })); }
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(); }); }
public void TestStatisticsManager() { FileSystem.Current.GetFile("C:\\stats.txt").WriteText(@"0:key value 1223:key1 value1 122444:key2 value2 122445:" + new String('a', 256) + " " + new String('b', 256) + @" "); StatisticsSession session = new StatisticsSession("game1", "http://stats.junkship.org", "c:\\stats.txt"); var statisticsService = new MockStatisticsService(); StatisticsServiceClient.ServiceFactory = () => new MockWCFClient <IStatisticsService>(statisticsService); StatisticsServiceClient client = new StatisticsServiceClient(session); List <string> errors = new List <string>(); client.SendStatistics(errors); Assert.AreEqual(0, errors.Count); var uploadedStats = statisticsService.Statistics; Assert.AreEqual(4, uploadedStats.Count); Assert.AreEqual("key", uploadedStats[0].Name); Assert.AreEqual("value", uploadedStats[0].Value); Assert.AreEqual(0, uploadedStats[0].Timestamp); Assert.AreEqual("key1", uploadedStats[1].Name); Assert.AreEqual("value1", uploadedStats[1].Value); Assert.AreEqual(1223, uploadedStats[1].Timestamp); Assert.AreEqual("key2", uploadedStats[2].Name); Assert.AreEqual("value2", uploadedStats[2].Value); Assert.AreEqual(122444, uploadedStats[2].Timestamp); Assert.AreEqual(new String('a', 255), uploadedStats[3].Name); Assert.AreEqual(new String('b', 255), uploadedStats[3].Value); Assert.AreEqual(122445, uploadedStats[3].Timestamp); Assert.AreEqual(uploadedStats[0].SessionId, uploadedStats[3].SessionId); Assert.IsTrue(!string.IsNullOrEmpty(uploadedStats[0].SessionId)); }
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)); }
public void TestStatisticsManager() { FileSystem.Current.GetFile("C:\\stats.txt").WriteText(@"0:key value 1223:key1 value1 122444:key2 value2 122445:"+new String('a',256)+" "+new String('b',256)+@" "); StatisticsSession session = new StatisticsSession("game1", "http://stats.junkship.org", "c:\\stats.txt"); var statisticsService = new MockStatisticsService(); StatisticsServiceClient.ServiceFactory = ()=>new MockWCFClient<IStatisticsService>(statisticsService); StatisticsServiceClient client = new StatisticsServiceClient(session); List<string> errors = new List<string>(); client.SendStatistics(errors); Assert.AreEqual(0, errors.Count); var uploadedStats = statisticsService.Statistics; Assert.AreEqual(4, uploadedStats.Count); Assert.AreEqual("key", uploadedStats[0].Name); Assert.AreEqual("value", uploadedStats[0].Value); Assert.AreEqual(0, uploadedStats[0].Timestamp); Assert.AreEqual("key1", uploadedStats[1].Name); Assert.AreEqual("value1", uploadedStats[1].Value); Assert.AreEqual(1223, uploadedStats[1].Timestamp); Assert.AreEqual("key2", uploadedStats[2].Name); Assert.AreEqual("value2", uploadedStats[2].Value); Assert.AreEqual(122444, uploadedStats[2].Timestamp); Assert.AreEqual(new String('a', 255), uploadedStats[3].Name); Assert.AreEqual(new String('b', 255), uploadedStats[3].Value); Assert.AreEqual(122445, uploadedStats[3].Timestamp); Assert.AreEqual(uploadedStats[0].SessionId, uploadedStats[3].SessionId); Assert.IsTrue(!string.IsNullOrEmpty(uploadedStats[0].SessionId)); }