public ChangeTrackerResponseCode ProcessResponseStream(Stream stream, CancellationToken token)
        {
            _pauseWait.Wait();
            var type = (ChangeTrackerMessageType)stream.ReadByte();

            if (type == ChangeTrackerMessageType.Plaintext || type == ChangeTrackerMessageType.GZip)
            {
                return(ProcessResponseStream(stream, token, type == ChangeTrackerMessageType.GZip));
            }
            else if (type == ChangeTrackerMessageType.EOF)
            {
                Log.To.ChangeTracker.D(Tag, "{0} Received EOF for processing", this);
                if (_changeProcessor == null)
                {
                    if (!_caughtUp)
                    {
                        _caughtUp = true;
                        OnCaughtUp?.Invoke();
                    }
                }
                else
                {
                    _changeProcessor.ScheduleCaughtUp();
                }

                return(ChangeTrackerResponseCode.Normal);
            }

            Log.To.Sync.E(Tag, "Unknown response code {0}, returning failed status", type);
            return(ChangeTrackerResponseCode.Failed);
        }
Exemple #2
0
        public ChunkedChanges(bool compressed, CancellationToken token, ManualResetEventSlim pauseWait)
        {
            _innerStream = new ChunkStream();
            _innerStream.BookmarkReached += (sender, args) => OnCaughtUp?.Invoke(this, null);
            if (compressed)
            {
                _inflater = new Inflater(true);
            }

            token.Register(Dispose);
            _pauseWait = pauseWait;
            Task.Factory.StartNew(Process, TaskCreationOptions.LongRunning);
        }
        private void SetupChangeProcessorCallback()
        {
            _changeProcessor.ChunkFound += (sender, args) =>
            {
                OnChangeFound?.Invoke(args);
            };

            _changeProcessor.Finished += (sender, args) =>
            {
                OnFinished?.Invoke(args);
            };

            _changeProcessor.OnCaughtUp += (sender, args) =>
            {
                if (!_caughtUp)
                {
                    _caughtUp = true;
                    OnCaughtUp?.Invoke();
                }
            };
        }