public async Task <IEnumerable <int> > GetCountsAsync(CancellationToken cancellationToken) { ContinuationToken continuationToken = null; var result = new List <int>(); do { var page = await StateProvider.GetActorsAsync(10000, continuationToken, cancellationToken); foreach (var actorId in page.Items) { var state = await StateProvider.LoadStateAsync <int>( actorId : actorId, stateName : "count", cancellationToken : cancellationToken); result.Add(state); } continuationToken = page.ContinuationToken; } while (continuationToken != null); return(result); }
public async Task <int> GetCountAsync(ActorId id, CancellationToken cancellationToken) { var count = await StateProvider.LoadStateAsync <int>( id, "count", cancellationToken); return(count); }
/// <summary> /// Loads the state with the specified name or returns default. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="actorId"></param> /// <param name="stateName"></param> /// <param name="cancellationToken"></param> /// <returns></returns> async Task <T> GetStateOrDefaultAsync <T>(ActorId actorId, string stateName, CancellationToken cancellationToken) { if (await StateProvider.ContainsStateAsync(actorId, stateName, cancellationToken)) { return(await StateProvider.LoadStateAsync <T>(actorId, stateName, cancellationToken)); } else { return(default);
public async Task <object> GetDocumentAsync(ActorId actorId, CancellationToken requestAborted) { if (await StateProvider.ContainsStateAsync(actorId, "Document", requestAborted)) { return(await StateProvider.LoadStateAsync <TDocument>(actorId, "Document", requestAborted)); } return(null); }
public async Task ActorUpdatedAsync(ActorId actorid, DateTimeOffset time, bool initializeOnMissing, CancellationToken cancellationToken) { try { if (await StateProvider.ContainsStateAsync(actorid, Constants.ActivatedStateName, cancellationToken)) { if (await StateProvider.ContainsStateAsync(actorid, Constants.LastUpdatedStateName, cancellationToken)) { var old = await StateProvider.LoadStateAsync <DateTimeOffset>(actorid, Constants.LastUpdatedStateName, cancellationToken); if (time > old) { await StateProvider.SaveStateAsync(actorid, new ActorStateChange[] { new ActorStateChange(Constants.LastUpdatedStateName, typeof(DateTimeOffset), time, StateChangeKind.Update) }, cancellationToken); } else { return; } } else { await StateProvider.SaveStateAsync(actorid, new ActorStateChange[] { new ActorStateChange(Constants.LastUpdatedStateName, typeof(DateTimeOffset), time, StateChangeKind.Add) }, cancellationToken); } if (!await StateProvider.LoadStateAsync <bool>(actorid, Constants.ActivatedStateName, cancellationToken)) { ActorProxy.Create <IDocumentActor>(actorid, this.Context.ServiceName).DocumentUpdatedAsync().FireAndForget(); } } else if (initializeOnMissing) { ActorProxy.Create <IDocumentActor>(actorid, this.Context.ServiceName).InitializeAsync().FireAndForget(); } } catch (Exception ex) { Console.WriteLine(ex); throw; } }