Esempio n. 1
0
        public Task WriteAsync(IDictionary <string, object> changes, CancellationToken cancellationToken = new CancellationToken())
        {
            return(Task.Run(() =>
            {
                Rv.WithRaven(session =>
                {
                    foreach (var change in changes)
                    {
                        var data = change.Value as ConcurrentDictionary <string, object>;

                        if (change.Key.Contains("/users/"))
                        {
                            session.Store(new UserData {
                                Id = change.Key, StateValue = data
                            });
                        }
                        else if (change.Key.Contains("/conversations/"))
                        {
                            session.Store(new Conversation {
                                Id = change.Key, StateValue = data
                            });
                        }
                        else
                        {
                            session.Store(new OtherContextData {
                                Id = change.Key, StateValue = data
                            });
                        }
                    }

                    session.SaveChanges();
                });
            }, cancellationToken));
        }
Esempio n. 2
0
        public async Task <ConversationReference[]> GetAll()
        {
            await Task.Delay(0);

            return(Rv.WithRaven(session =>
                                session
                                .Query <ConversationReference>()
                                .ToArray()));
        }
Esempio n. 3
0
        public async Task SaveReference(ConversationReference reference)
        {
            await Task.Delay(0);

            Rv.WithRaven(session =>
            {
                session.Store(reference, reference.Conversation.Id);
                session.SaveChanges();
            });
        }
Esempio n. 4
0
        public async Task RemoveConversationOnError(string conversationId)
        {
            await Task.Delay(0);

            Log.Warning("Removing {conversationWithError} conversations after error", conversationId);

            Rv.WithRaven(session =>
            {
//                session.Delete(conversationId);
                session.SaveChanges();
            });
        }
Esempio n. 5
0
 public Task <IDictionary <string, object> > ReadAsync(string[] keys, CancellationToken cancellationToken = new CancellationToken())
 {
     return(Task.Run(() =>
     {
         return Rv.WithRaven(session =>
         {
             return session
             .Load <EntityProxy>(keys)
             .ToDictionary(x => x.Key, x => (object)x.Value?.StateValue) as IDictionary <string, object>;
         });
     }, cancellationToken));
 }
Esempio n. 6
0
        public Task DeleteAsync(string[] keys, CancellationToken cancellationToken = new CancellationToken())
        {
            return(Task.Run(() =>
            {
                Rv.WithRaven(session =>
                {
                    foreach (var key in keys)
                    {
                        session.Delete(key);
                    }

                    session.SaveChanges();
                });
            }, cancellationToken));
        }
Esempio n. 7
0
        public async Task Check(ConversationReference reference)
        {
            await Task.Delay(0);

            Rv.WithRaven(session =>
            {
                var allConversations = session
                                       .Query <ConversationReference>()
                                       .ToArray();

                var existingConversationsFound = allConversations
                                                 .Any(x => x.User.Id == reference.User.Id);

                if (!existingConversationsFound)
                {
                    session.Store(reference, reference.Conversation.Id);
                    session.SaveChanges();
                }
            });
        }
Esempio n. 8
0
        public async Task RemoveOldConversations(string userId)
        {
            await Task.Delay(0);

            Log.Information("Removing old conversations for user: {recipientId}", userId);
            Rv.WithRaven(session =>
            {
                var allConversations = session
                                       .Query <ConversationReference>()
                                       .ToArray();

                var existingConversations = allConversations
                                            .Where(x => x.User.Id == userId)
                                            .ToArray();

                Log.Information("Found {conversationsToRemove} old conversations to remove", existingConversations.Length);
                foreach (var c in existingConversations.Take(20)) // session limit is 30 operations
                {
                    session.Delete(c);
                }

                session.SaveChanges();
            });
        }