Esempio n. 1
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);
        }
Esempio n. 2
0
 public async Task DeactivateAsync(ActorId actorId)
 {
     try
     {
         await StateProvider.SaveStateAsync(actorId, new[] { new ActorStateChange(Constants.ActivatedStateName, typeof(bool), false, StateChangeKind.Update) });
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         throw;
     }
 }
Esempio n. 3
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;
            }
        }