Esempio n. 1
0
    public ValueTask HandleAsync(ConnectedClient sender, PullRope message, CancellationToken cancellationToken)
    {
        var contestantId = sender.ClientId;

        var contest = _contestStore.FindActiveByContestantId(contestantId);

        if (contest == null)
        {
            throw new InvalidOperationException($"Contest is not found for contestant {contestantId}.");
        }

        contest.PullRope(contestantId, message.Distance);
        _contestStore.Save(contest);

        return(default);
    public ValueTask HandleAsync(ConnectedClient sender, JoinContest message, CancellationToken cancellationToken)
    {
        var existingContest = _contestStore.FindActiveByContestantId(sender.ClientId);

        if (existingContest != null)
        {
            throw new InvalidOperationException($"Already in contest {existingContest.ContestId}");
        }

        var contest = _contestStore.Find(sender.Group);

        if (contest == null)
        {
            contest = new Contest(sender.Group);
        }

        contest.Join(sender.ClientId, message.Side);
        _contestStore.Save(contest);

        return(default);