Example #1
0
        public override void OnReceivedResponse(HttpMessage message)
        {
            if (message.Response.Headers.TryGetValues(SyncTokenHeader, out IEnumerable <string> rawSyncTokens))
            {
                foreach (string fullRawToken in rawSyncTokens)
                {
                    // Handle multiple header values.
                    string[] rawTokens = fullRawToken.Split(',');
                    foreach (string rawToken in rawTokens)
                    {
                        if (SyncTokenUtils.TryParse(rawToken, out SyncToken token))
                        {
                            _syncTokens.AddOrUpdate(token.Id, token, (key, existing) =>
                            {
                                if (existing.SequenceNumber < token.SequenceNumber)
                                {
                                    return(token);
                                }

                                return(existing);
                            });
                        }
                    }
                }
            }
        }
        public void AddToken(string fullRawToken)
        {
            // Handle multiple header values.
            string[] rawTokens = fullRawToken.Split(',');
            foreach (string rawToken in rawTokens)
            {
                if (SyncTokenUtils.TryParse(rawToken, out SyncToken token))
                {
                    _syncTokens.AddOrUpdate(token.Id, token, (key, existing) =>
                    {
                        if (existing.SequenceNumber < token.SequenceNumber)
                        {
                            return(token);
                        }

                        return(existing);
                    });
                }
            }
        }
Example #3
0
        private async Task ProcessAsync(HttpPipelineMessage message, ReadOnlyMemory <HttpPipelinePolicy> pipeline, bool async)
        {
            foreach (SyncToken token in _syncTokens.Values)
            {
                message.Request.Headers.Add(SyncTokenHeader, token.ToString());
            }

            if (async)
            {
                await ProcessNextAsync(message, pipeline).ConfigureAwait(false);
            }
            else
            {
                ProcessNext(message, pipeline);
            }

            if (message.Response.Headers.TryGetValues(SyncTokenHeader, out IEnumerable <string> rawSyncTokens))
            {
                foreach (string fullRawToken in rawSyncTokens)
                {
                    // Handle multiple header values.
                    string[] rawTokens = fullRawToken.Split(',');
                    foreach (string rawToken in rawTokens)
                    {
                        if (SyncTokenUtils.TryParse(rawToken, out SyncToken token))
                        {
                            _syncTokens.AddOrUpdate(token.Id, token, (key, existing) =>
                            {
                                if (existing.SequenceNumber < token.SequenceNumber)
                                {
                                    return(token);
                                }

                                return(existing);
                            });
                        }
                    }
                }
            }
        }