예제 #1
0
        public void LocalRefresh(List <Challenge> challenges)
        {
            try
            {
                var current = Challenges.Select(vm => vm.Challenge).ToList();

                var comparer = new ChallengeComparer();
                var toRemove = current.Except(challenges, comparer).ToList();
                var toAdd    = challenges.Except(current, comparer).ToList();
                toRemove.ForEach(c => Challenges.Remove(Challenges.Single(vm => vm.Challenge == c)));

                var preSort = new List <ChallengeViewModel>();
                toAdd.ForEach(c => preSort.Add(new ChallengeViewModel {
                    Challenge = c
                }));

                preSort.Sort(new ChallengeSortComparer());
                preSort.ForEach(Challenges.Add);

                if (Challenges.Count == 0)
                {
                    Challenges.Add(new ChallengeViewModel()
                    {
                        EmptyMessage = "{0} no challenges for this league".Fmt(Membership.AthleteId == App.CurrentAthlete.Id
                                                        ? "You have" : "{0} has".Fmt(Membership.Athlete.Alias))
                    });
                }
            }
            catch (Exception e)
            {
                InsightsManager.Report(e);
            }
        }
예제 #2
0
        private static void CurrentUserMap(IDataReader reader, short set, ref UserBase authUser, ref List <string> Roles, ref List <string> Challenges)
        {
            List <string> extProviders = null;

            switch (set)
            {
            case 0:
                int startingIndex = 0;
                authUser = new UserBase
                {
                    Id       = reader.GetSafeInt32(startingIndex++),
                    Name     = reader.GetSafeString(startingIndex++),
                    PhotoUrl = reader.GetSafeString(startingIndex++)
                };

                break;

            case 1:
                string role = reader.GetSafeString(0);

                if (Roles == null)
                {
                    Roles = new List <string>();
                }
                Roles.Add(role);

                break;

            case 2:
                string extProvider = reader.GetSafeString(0);

                if (extProviders == null)
                {
                    extProviders = new List <string>();
                }

                extProviders.Add("Has" + extProvider);
                break;

            case 3:
                string challenge = reader.GetSafeString(0);

                if (Challenges == null)
                {
                    Challenges = new List <string>();
                }
                Challenges.Add(challenge);

                break;
            }

            if (authUser != null && (extProviders != null || Roles != null || Challenges != null))
            {
                authUser.ExtProviders = extProviders;
                authUser.Roles        = Roles;
                authUser.Challenges   = Challenges;
            }
        }
예제 #3
0
        public Challenge AddChallenge(string name, Weapon weapon, string postingPlayerDiscordId, string identifier)
        {
            Challenge c = new Challenge()
            {
                Name = name, Weapon = weapon, PlayerDiscordId = postingPlayerDiscordId, Identifier = identifier
            };

            Challenges.Add(c);
            challengeDatabase.AddChallenge(c);
            return(c);
        }
        public void Add(int addend1, int addend2, int expectedSum)
        {
            // Arrange
            Challenges challenger = new Challenges();

            // Act
            int actual = challenger.Add(addend1, addend2);

            // Assert
            Assert.Equal(expectedSum, actual);
        }
예제 #5
0
        public void AddChallenge(Challenge challenge)
        {
            if (Challenges.Any(c => c.Date.Date == DateTime.Today))
            {
                throw new ArgumentException("A challenge has already been chosen for today.");
            }

            Challenges.Add(challenge);
            challenge.Name = $"Challenge {Challenges.Count}";

            if (Challenges.Count == 1)
            {
                StartedAt = DateTime.Now;
            }
        }
예제 #6
0
        public void AddChallenge(Challenge challenge)
        {
            if (Challenges.Any(c => (c.TimeToAccept > 0 && c.Done == false)))
            {
                throw new ArgumentException("A challenge has already been chosen for today.");
            }

            Challenges.Add(challenge);
            challenge.Name = $"Challenge {Challenges.Count}";

            if (Challenges.Count == 1)
            {
                StartedAt = DateTime.Now;
            }
            BadgeSigner.Instance.RewardBadges(this, challenge);
        }
예제 #7
0
        /// <summary>
        /// Begins loading new challenges asynchronously.
        /// </summary>
        /// <param name="skipCount">The number of challenges to skip.</param>
        /// <returns>An awaitable task.</returns>
        protected async override Task LoadDataImpl(bool forceReload = false)
        {
            var geoposition = await Utilities.GeoLocationHelper.GetLocation();

            var geoPoint = new ParseGeoPoint(geoposition.Coordinate.Latitude, geoposition.Coordinate.Longitude);
            var query    = ParseObject.GetQuery("Challenge");

            query.WhereNear("location", geoPoint).Limit(20).Skip(CurrentlyLoaded);

            List <Task> challengeTasks = new List <Task>();

            foreach (var challenge in await query.FindAsync())
            {
                var challengeViewModel = new ChallengeViewModel(challenge);
                Challenges.Add(challengeViewModel);
                challengeTasks.Add(challengeViewModel.LoadData());
            }
            await Task.WhenAll(challengeTasks.ToArray());

            CurrentlyLoaded += 20;
        }
예제 #8
0
        public void AddChannel(GameChannel channel, KgsConnection connection)
        {
            var kChallenge = KgsChallenge.FromChannel(channel);

            if (kChallenge != null)
            {
                connection.Data.EnsureChannelExists(kChallenge);
                Challenges.Add(kChallenge);
                AllChannelsCollection.Add(kChallenge);
                return;
            }
            var kGame = KgsTrueGameChannel.FromChannel(channel);

            if (kGame != null)
            {
                connection.Data.EnsureChannelExists(kGame);
                Games.Add(kGame);
                AllChannelsCollection.Add(kGame);
                return;
            }
        }
        private void _WireDesignerData()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                return;
            }

            var challenge = new Challenge()
            {
                Id          = 1,
                Title       = "another trial",
                Description = "A new challenge to fight over!",
                Created     = System.DateTime.Now,
                Modified    = System.DateTime.Now,
                Location    = new System.Device.Location.GeoPosition <System.Device.Location.GeoCoordinate>(
                    new System.DateTimeOffset(),
                    new System.Device.Location.GeoCoordinate(32, 32)),
                Image       = "SampleData/Images/img1.jpg",
                SolvedCount = 3,
                MissedCount = 2
            };

            var challenge2 = new Challenge()
            {
                Id          = 1,
                Title       = "On the edge",
                Description = "Of the world",
                Created     = System.DateTime.Now,
                Modified    = System.DateTime.Now,
                Location    = new System.Device.Location.GeoPosition <System.Device.Location.GeoCoordinate>(
                    new System.DateTimeOffset(),
                    new System.Device.Location.GeoCoordinate(32, 32)),
                Image       = "SampleData/Images/img2.jpg",
                SolvedCount = 2,
                MissedCount = 8
            };

            Challenges.Add(challenge);
            Challenges.Add(challenge2);
        }
예제 #10
0
        async public Task GetChallengeHistory(bool forceRefresh = false)
        {
            using (new Busy(this))
            {
                ChallengeViewModel empty = null;
                if (Challenges.Count == 0)
                {
                    empty = new ChallengeViewModel()
                    {
                        EmptyMessage = "Loading previous challenges"
                    };

                    Challenges.Add(empty);
                }

                if (forceRefresh)
                {
                    await AzureService.Instance.GameResultManager.PullLatestAsync().ConfigureAwait(false);

                    await AzureService.Instance.ChallengeManager.PullLatestAsync().ConfigureAwait(false);
                }

                var list = await AzureService.Instance.ChallengeManager.Table.Where(c => c.DateCompleted != null &&
                                                                                    (c.ChallengerAthleteId == Membership.AthleteId || c.ChallengeeAthleteId == Membership.AthleteId) &&
                                                                                    c.LeagueId == Membership.LeagueId)
                           .OrderByDescending(c => c.DateCompleted).ToListAsync();

                Challenges.Clear();
                list.ForEach(c => Challenges.Add(new ChallengeViewModel {
                    Challenge = c
                }));

                if (Challenges.Count == 0)
                {
                    Challenges.Add(new ChallengeViewModel {
                        EmptyMessage = "There are no previous challenges."
                    });
                }
            }
        }
예제 #11
0
        async public Task GetChallengeHistory(bool forceRefresh = false)
        {
            if (!forceRefresh && _hasLoadedBefore)
            {
                return;
            }

            using (new Busy(this))
            {
                ChallengeViewModel empty = null;
                if (Challenges.Count == 0)
                {
                    empty = new ChallengeViewModel()
                    {
                        EmptyMessage = "Loading previous challenges"
                    };

                    Challenges.Add(empty);
                }

                var task = AzureService.Instance.GetChallengesForMembership(Membership);
                await RunSafe(task);

                if (task.IsFaulted)
                {
                    return;
                }

                if (empty != null && Challenges.Contains(empty))
                {
                    Challenges.Remove(empty);
                }

                LocalRefresh(task.Result);
            }
        }
예제 #12
0
 public void AddChallenges(List <ChallengeUser> challenges) => challenges.ForEach(ch => Challenges.Add(ch));