Esempio n. 1
0
        /// <summary>
        /// This is used to verify if the user that has logged in
        /// is the same that before, if not this will Reject every query in the Queue
        /// and clear all subscriptions, otherwise this will replay the Queue if it is waiting.
        /// </summary>
        internal override void OnUserLoggedIn(object sender, UserLoggedInEvent e)
        {
            if (previousKUID != e.Kuid)
            {
                if (AutoRecover &&
                    QueryReplayer.WaitLoginToReplay)
                {
                    QueryReplayer.RejectAllQueries(new UnauthorizeException("Request submitted by another user"));
                    QueryReplayer.Lock = false;
                    QueryReplayer.WaitLoginToReplay = false;
                }

                SubscriptionRecoverer.Clear();
            }
            else
            {
                if (AutoRecover &&
                    QueryReplayer.WaitLoginToReplay)
                {
                    QueryReplayer.ReplayQueries();
                    QueryReplayer.Lock = false;
                    QueryReplayer.WaitLoginToReplay = false;
                }

                SubscriptionRecoverer.RenewSubscriptions();
            }
            previousKUID = e.Kuid;
        }
Esempio n. 2
0
        public void SuccessReplayQueries(bool waitLoginToReplay, bool resetWaitLogin)
        {
            testableOfflineManager.MaxQueueSize    = -1;
            testableOfflineManager.MaxRequestDelay = 0;
            queryReplayer.Lock = false;
            queryReplayer.WaitLoginToReplay = waitLoginToReplay;
            int callCount = 0;

            queryReplayer.ReplayQuery = (TimedQuery query, CancellationToken token) => {
                callCount += 1;
                return(Task.CompletedTask);
            };

            Assert.Equal(!waitLoginToReplay, queryReplayer.Enqueue(JObject.Parse("{controller: 'foo', action: 'bar'}")));
            Assert.Equal(!waitLoginToReplay, queryReplayer.Enqueue(JObject.Parse("{controller: 'bar', action: 'foor'}")));
            Assert.Equal(!waitLoginToReplay, queryReplayer.Enqueue(JObject.Parse("{controller: 'foobar', action: 'foobar'}")));
            Assert.Equal(!waitLoginToReplay, queryReplayer.Enqueue(JObject.Parse("{controller: 'barfoo', action: 'foobar'}")));
            Assert.Equal(!waitLoginToReplay, queryReplayer.Enqueue(JObject.Parse("{controller: 'foobar', action: 'barfoo'}")));
            Assert.Equal(!waitLoginToReplay, queryReplayer.Enqueue(JObject.Parse("{controller: 'barfoo', action: 'barfoo'}")));

            Assert.Equal(waitLoginToReplay ? 0 : 6, queryReplayer.Count);

            Assert.IsType <CancellationTokenSource>(queryReplayer.ReplayQueries(resetWaitLogin));

            if (resetWaitLogin)
            {
                Assert.False(queryReplayer.WaitLoginToReplay);
            }
            else
            {
                Assert.Equal(waitLoginToReplay, queryReplayer.WaitLoginToReplay);
            }

            Assert.Equal(waitLoginToReplay ? 0 : 6, callCount);
        }
Esempio n. 3
0
        /// <summary>
        /// This will check the token validity,
        /// and chose what to do before replaying the Queue
        /// </summary>
        internal override async Task Recover()
        {
            if (!AutoRecover)
            {
                return;
            }

            if (await TokenVerifier.IsTokenValid())
            {
                QueryReplayer.ReplayQueries();
                SubscriptionRecoverer.RenewSubscriptions();
                return;
            }

            if (QueryReplayer.Lock)
            {
                QueryReplayer.ReplayQueries((obj) =>
                                            obj["controller"]?.ToString() == "auth" &&
                                            (obj["action"].ToString() == "login" ||
                                             obj["action"].ToString() == "logout"), false);
            }
        }