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 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));
        }
Example #3
0
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(StatisticsServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_IStatisticsService));
 }
Example #4
0
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(StatisticsServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_IStatisticsService));
 }
Example #5
0
 public StatisticsServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(StatisticsServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #6
0
 public StatisticsServiceClient(EndpointConfiguration endpointConfiguration) :
     base(StatisticsServiceClient.GetBindingForEndpoint(endpointConfiguration), StatisticsServiceClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #7
0
 public StatisticsServiceClient() :
     base(StatisticsServiceClient.GetDefaultBinding(), StatisticsServiceClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_IStatisticsService.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Example #8
0
        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));
        }