コード例 #1
0
 /// <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);
コード例 #2
0
        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);
        }
コード例 #3
0
        public async Task SaveDocumentAsync(ActorId actorId, DocumentWrapper document, CancellationToken cancellationToken)
        {
            await StateProvider.SaveStateAsync(actorId,
                                               new ActorStateChange[] {
                new ActorStateChange("Document", typeof(TDocument), document.Document,
                                     await StateProvider.ContainsStateAsync(actorId, "Document", cancellationToken) ? StateChangeKind.Update: StateChangeKind.Add)
            }, cancellationToken);

            await ActorUpdatedAsync(actorId, DateTimeOffset.UtcNow, true, cancellationToken);
        }
コード例 #4
0
 public async Task <bool> ActorExists(ActorId actorId, CancellationToken cancellationToken)
 {
     try
     {
         return(await StateProvider.ContainsStateAsync(actorId, Constants.ActivatedStateName, cancellationToken));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw;
     }
 }
コード例 #5
0
        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;
            }
        }
コード例 #6
0
 public Task <bool> ActorExistsAsync(ActorId actorId, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(StateProvider.ContainsStateAsync(actorId, ExistsMarker, cancellationToken));
 }