Пример #1
0
        /// <summary>
        /// Discards the snapshot any changes made after the snapshot was taken are kept.
        /// </summary>
        public void ForgetSnapshot()
        {
            if (_diffStream == null)
            {
                throw new InvalidOperationException("No snapshot");
            }

            byte[] buffer = new byte[8192];

            foreach (var extent in _diffExtents)
            {
                _diffStream.Position = extent.Start;
                _baseStream.Position = extent.Start;

                int totalRead = 0;
                while (totalRead < extent.Length)
                {
                    int toRead = (int)Math.Min(extent.Length - totalRead, buffer.Length);

                    int read = _diffStream.Read(buffer, 0, toRead);
                    _baseStream.Write(buffer, 0, read);

                    totalRead += read;
                }
            }

            _diffStream  = null;
            _diffExtents = null;
        }
Пример #2
0
        /// <summary>
        /// Reverts to a previous snapshot, discarding any changes made to the stream.
        /// </summary>
        public void RevertToSnapshot()
        {
            if (_diffStream == null)
            {
                throw new InvalidOperationException("No snapshot");
            }

            _diffStream  = null;
            _diffExtents = null;

            _position = _savedPosition;
        }
Пример #3
0
        /// <summary>
        /// Takes a snapshot of the current stream contents.
        /// </summary>
        public void Snapshot()
        {
            if (_diffStream != null)
            {
                throw new InvalidOperationException("Already have a snapshot");
            }

            _savedPosition = _position;

            _diffExtents = new List <StreamExtent>();
            _diffStream  = new SparseMemoryStream();
            _diffStream.SetLength(_baseStream.Length);
        }
Пример #4
0
        /// <summary>
        /// Disposes of this instance.
        /// </summary>
        /// <param name="disposing"><c>true</c> if called from Dispose(), else <c>false</c>.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_baseStreamOwnership == Ownership.Dispose && _baseStream != null)
                {
                    _baseStream.Dispose();
                }

                _baseStream = null;

                if (_diffStream != null)
                {
                    _diffStream.Dispose();
                }

                _diffStream = null;
            }

            base.Dispose(disposing);
        }