Example #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);
        }
Example #2
0
        public Form1()
        {
            tournament = new SingleElimination();

            IRule bestof1 = new BestOf(1);
            IRule bestof3 = new BestOf(3);
            IRule BestOf5 = new BestOf(5);

            InitializeComponent();


            RulesBox.Items.Add(bestof1);
            RulesBox.Items.Add(bestof3);
            RulesBox.Items.Add(BestOf5);
            MatchVisualizer.SetParent(this);


            //Set current colors for application
            colorFactory = ColorHandler.Instance;
            colors       = colorFactory.GetColorTheme();
        }
Example #3
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());
        }