public async Task SetCountAsync(SetCountCommand command, CancellationToken cancellationToken) { var count = await StateManager.TryGetStateAsync <int>("count", cancellationToken); var countValue = count.HasValue ? count.Value : 0; await StateManager.AddOrUpdateStateAsync("count", command.Count, (key, value) => command.Count > value?command.Count : value, cancellationToken); if (command.Count > countValue) { await _outbox.AddAsync(new CounterIncreasedEvent { EventId = Guid.NewGuid(), CounterId = this.GetActorId().GetGuidId() }, cancellationToken); ActorEventSource.Current.ActorMessage(this, nameof(CounterIncreasedEvent)); } else if (command.Count < countValue) { await _outbox.AddAsync(new CounterDecreasedEvent { EventId = Guid.NewGuid(), CounterId = this.GetActorId().GetGuidId() }, cancellationToken); ActorEventSource.Current.ActorMessage(this, nameof(CounterDecreasedEvent)); } else { ActorEventSource.Current.ActorMessage(this, "No-op"); } }
public async Task Post(Guid id, [FromBody] SetCountCommand command) { await ActorProxy.Create <IActor1>(new ActorId(id)).SetCountAsync(command, CancellationToken.None); }