Beispiel #1
0
        public async Task <DomainValidationResult <IChallenge> > CreateChallengeAsync(
            ChallengeName name,
            Game game,
            BestOf bestOf,
            Entries entries,
            ChallengeDuration duration,
            IDateTimeProvider createAt,
            Scoring scoring,
            CancellationToken cancellationToken = default
            )
        {
            var result = new DomainValidationResult <IChallenge>();

            if (result.IsValid)
            {
                var challenge = new Challenge(
                    new ChallengeId(),
                    name,
                    game,
                    bestOf,
                    entries,
                    new ChallengeTimeline(createAt, duration),
                    scoring);

                _challengeRepository.Create(challenge);

                await _challengeRepository.CommitAsync(true, cancellationToken);

                return(challenge);
            }

            return(result);
        }
Beispiel #2
0
        public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (UserName.IsNullOrEmpty())
            {
                yield return(new ValidationResult(Messages.UserNameIsRequired, new[] { nameof(UserName) }));
            }

            if (ChallengeName.IsNullOrEmpty())
            {
                yield return(new ValidationResult(Messages.ChallengeNameIsRequired, new[] { nameof(ChallengeName) }));
            }

            if (Session.IsNullOrEmpty())
            {
                yield return(new ValidationResult(Messages.InvalidChallengeSession, new[] { nameof(Session) }));
            }
        }
        void ReleaseDesignerOutlets()
        {
            if (Background != null)
            {
                Background.Dispose();
                Background = null;
            }

            if (BadgeView != null)
            {
                BadgeView.Dispose();
                BadgeView = null;
            }

            if (ChallengeImage != null)
            {
                ChallengeImage.Dispose();
                ChallengeImage = null;
            }

            if (ChallengeName != null)
            {
                ChallengeName.Dispose();
                ChallengeName = null;
            }

            if (ChallengeProgressBar != null)
            {
                ChallengeProgressBar.Dispose();
                ChallengeProgressBar = null;
            }

            if (ChallengeProgressText != null)
            {
                ChallengeProgressText.Dispose();
                ChallengeProgressText = null;
            }
        }
Beispiel #4
0
        void ReleaseDesignerOutlets()
        {
            if (ChallengeImage != null)
            {
                ChallengeImage.Dispose();
                ChallengeImage = null;
            }

            if (ChallengeName != null)
            {
                ChallengeName.Dispose();
                ChallengeName = null;
            }

            if (ChallengeTime != null)
            {
                ChallengeTime.Dispose();
                ChallengeTime = null;
            }

            if (ChellangeRightImage != null)
            {
                ChellangeRightImage.Dispose();
                ChellangeRightImage = null;
            }

            if (ClosedImage != null)
            {
                ClosedImage.Dispose();
                ClosedImage = null;
            }

            if (LeftMargin != null)
            {
                LeftMargin.Dispose();
                LeftMargin = null;
            }

            if (LeftSideView != null)
            {
                LeftSideView.Dispose();
                LeftSideView = null;
            }

            if (NameSeparator != null)
            {
                NameSeparator.Dispose();
                NameSeparator = null;
            }

            if (PointsText != null)
            {
                PointsText.Dispose();
                PointsText = null;
            }

            if (RightMargin != null)
            {
                RightMargin.Dispose();
                RightMargin = null;
            }

            if (SeperatorView != null)
            {
                SeperatorView.Dispose();
                SeperatorView = null;
            }
        }
Beispiel #5
0
        public IChallenge FakeChallenge(ChallengeModel model)
        {
            var challengeFaker = new ChallengeFaker();

            challengeFaker.CustomInstantiator(
                faker =>
            {
                faker.User().Reset();

                var name = new ChallengeName(model.Name);

                var game = Game.FromValue(model.Game);

                var entries = new Entries(model.Entries);

                var bestOf = new BestOf(model.BestOf);

                var duration = new ChallengeDuration(TimeSpan.FromTicks(model.Timeline.Duration));

                var state = ChallengeState.FromValue(model.State);

                var utcNowDate = DateTime.UtcNow.Date;

                var createdAt = faker.Date.Recent(1, utcNowDate);

                var startedAt = faker.Date.Between(createdAt, utcNowDate);

                var endedAt = startedAt + duration;

                var synchronizationBuffer = endedAt + TimeSpan.FromHours(2);

                var closedAt = faker.Date.Soon(1, synchronizationBuffer);

                var synchronizedAt = faker.Date.Between(synchronizationBuffer, closedAt);

                var timeline = new ChallengeTimeline(new DateTimeProvider(startedAt), duration);

                var scoring = new Scoring
                {
                    [new StatName("StatName1")] = new StatWeighting(0.00015F),
                    [new StatName("StatName2")] = new StatWeighting(1),
                    [new StatName("StatName3")] = new StatWeighting(0.77F),
                    [new StatName("StatName4")] = new StatWeighting(100),
                    [new StatName("StatName5")] = new StatWeighting(-3)
                };

                var challenge = new Challenge(
                    model.Id.ConvertTo <ChallengeId>(),
                    name,
                    game,
                    bestOf,
                    entries,
                    timeline,
                    scoring);

                var participantFaker = new ParticipantFaker(game, createdAt, startedAt);

                participantFaker.UseSeed(faker.Random.Int());

                var participants = participantFaker.Generate(this.ParticipantCount(state, challenge.Entries));

                participants.ForEach(participant => challenge.Register(participant));

                if (state != ChallengeState.Inscription)
                {
                    challenge.Start(new DateTimeProvider(startedAt));

                    participants.ForEach(
                        participant =>
                    {
                        var matchFaker = new MatchFaker(challenge.Scoring, synchronizedAt);

                        matchFaker.UseSeed(faker.Random.Int());

                        var matches = matchFaker.Generate(this.MatchCount(state, challenge.BestOf));

                        participant.Snapshot(matches, new DateTimeProvider(synchronizedAt));
                    });

                    challenge.Synchronize(new DateTimeProvider(synchronizedAt));

                    if (state == ChallengeState.Ended || state == ChallengeState.Closed)
                    {
                        challenge.Start(new DateTimeProvider(startedAt - duration));
                    }

                    if (state == ChallengeState.Closed)
                    {
                        challenge.Close(new DateTimeProvider(closedAt));
                    }
                }

                return(challenge);
            });

            return(challengeFaker.Generate());
        }