Пример #1
0
    // [CommandHandler] inherited
    public override async Task SetOptions(
        SetSessionOptionsCommand command, CancellationToken cancellationToken = default)
    {
        var(session, options, baseVersion) = command;
        var context = CommandContext.GetCurrent();

        if (Computed.IsInvalidating())
        {
            _ = GetSessionInfo(session, default);
            _ = GetOptions(session, default);
            return;
        }

        var dbContext = await CreateCommandDbContext(cancellationToken).ConfigureAwait(false);

        await using var _1 = dbContext.ConfigureAwait(false);

        var dbSessionInfo = await Sessions.Get(dbContext, session.Id, true, cancellationToken).ConfigureAwait(false);

        var sessionInfo = SessionConverter.ToModel(dbSessionInfo);

        if (sessionInfo == null)
        {
            throw new KeyNotFoundException();
        }
        if (baseVersion.HasValue && sessionInfo.Version != baseVersion.GetValueOrDefault())
        {
            throw new VersionMismatchException();
        }

        sessionInfo = sessionInfo with {
            LastSeenAt = Clocks.SystemClock.Now,
            Options    = options,
        };
        await Sessions.Upsert(dbContext, sessionInfo, cancellationToken).ConfigureAwait(false);
    }
Пример #2
0
 public abstract Task SetOptions(SetSessionOptionsCommand command, CancellationToken cancellationToken            = default);