예제 #1
0
        public void AddOneLeaderToLeaderboardTest()
        {
            LeaderboardAccess.AddLeaderEntry(DefaultZone.HashId, DefaultLeader);

            var leaderboard = LeaderboardAccess.GetLeaderboard(DefaultZone.HashId);
            var leaders     = LeaderboardModelHelper.GetOrderedLeaders(leaderboard);

            Assert.AreEqual(1, leaders.Count);
        }
예제 #2
0
        public void GetTheDefaultLeaderboardTest()
        {
            var leaderboard = LeaderboardAccess.GetLeaderboard(DefaultZone.HashId);

            Assert.AreEqual(DefaultZone.HashId, leaderboard.ZoneHashId);
            var leaders = LeaderboardModelHelper.GetOrderedLeaders(leaderboard);

            Assert.AreEqual(0, leaders.Count);
        }
예제 #3
0
        public void AddMoreThan10LeadersTest()
        {
            for (int i = 0; i < 12; i++)
            {
                DefaultLeader.Points += 1;
                LeaderboardAccess.AddLeaderEntry(DefaultZone.HashId, DefaultLeader);
            }

            var leaderboard = LeaderboardAccess.GetLeaderboard(DefaultZone.HashId);
            var leaders     = LeaderboardModelHelper.GetOrderedLeaders(leaderboard);

            Assert.AreEqual(10, leaders.Count);

            Assert.AreEqual(DefaultLeader.Points, leaders[0].Points);
        }
        public void Initialize(string mapHashId)
        {
            var leaderboard = LeaderboardAccess.Instance.GetLeaderboard(mapHashId);

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
            {
                _leaderEntries.Clear();
                var entry = LeaderboardModelHelper.GetOrderedLeaders(leaderboard);
                foreach (var leaderModel in entry)
                {
                    _leaderEntries.Add(leaderModel);
                }
                ListLeaderboardEntry.ItemsSource = _leaderEntries;
                CollectionViewSource.GetDefaultView(_leaderEntries).Refresh();
            }));
        }
        /// <summary>
        /// Create a new map in database and return it's hashid
        /// </summary>
        /// <param name="mapModel"></param>
        /// <returns></returns>
        public string CreateNewMap(MapModel mapModel)
        {
            if (!IsValid(mapModel))
            {
                throw HttpResponseExceptionHelper.Create("Invalid map model information", HttpStatusCode.BadRequest);
            }

            using (var db = new SystemDBContext())
            {
                // set hash
                mapModel.CreatorhashId = UserToken.UserId;
                mapModel.HashId        = GetMapHash(mapModel);

                if (db.Maps.FirstOrDefault(x => x.HashId == mapModel.HashId) != null)
                {
                    throw HttpResponseExceptionHelper.Create(
                              "Map already exist with name : " + mapModel.Name + "  From user : " + UserToken.Username,
                              HttpStatusCode.BadRequest);
                }

                mapModel.CreationDate = TimeHelper.CurrentCanadaTimeString();
                mapModel.UpdateTime   = TimeHelper.CurrentCanadaTime();

                // save database
                db.Maps.Add(mapModel);
                db.SaveChanges();

                // create leaderboard for map
                var leaderboard = new LeaderboardModel()
                {
                    ZoneHashId = mapModel.HashId,
                    Leaders    = LeaderboardModelHelper.GetLeaderString(new List <LeaderModel>())
                };

                db.Leaderboards.Add(leaderboard);
                db.SaveChanges();

                return(mapModel.HashId);
            }
        }