Exemplo n.º 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);
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
     }
 }
Exemplo n.º 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;
            }
        }
 public Task <bool> ActorExistsAsync(ActorId actorId, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(StateProvider.ContainsStateAsync(actorId, ExistsMarker, cancellationToken));
 }