Esempio n. 1
0
        public IEnumerable<IStreamedEvent> Load(Guid identity)
        {
            FileStream fs;
            try {
                fs = new FileStream(
                    _repositoryHierarchy.For(identity, false),
                    FileMode.Open, FileAccess.Read, FileShare.None,
                    4096, FileOptions.SequentialScan);

            } catch (FileNotFoundException x) {
                throw new StreamNotFoundPersistenceException(identity, _repositoryHierarchy.RootPath, x);

            } catch (DirectoryNotFoundException x) {
                throw new StreamNotFoundPersistenceException(identity, _repositoryHierarchy.RootPath, x);

            } catch (DriveNotFoundException x) {
                throw new StreamNotFoundPersistenceException(identity, _repositoryHierarchy.RootPath, x);
            }

            // Note: The FileStream is created separately outside the using{} block because
            //       the C# compiler dislikes using the 'yield return' inside a try..catch block.

            using (fs) {
                using (var esw = new EventStreamReader(fs, _eventReader)) {
                    while (esw.HasNext())
                        yield return esw.Next();
                }
            }
        }
        public void Verify()
        {
            _innerStream.Position = 0;

            using (var esr = new EventStreamReader(_innerStream.PreventClosure(), _eventReader)) {
                while (_innerStream.Position < _innerStream.Length) {
                    try {
                        esr.Next();

                    } catch (TruncationVerificationPersistenceException x) {
                        // A trailing commit was unfinished possibly due to power cut or system crash.
                        // This can be repaired easily just by truncating the stream.
                        _innerStream.SetLength(x.Offset);
                    }
                }
            }

            _innerStream.Position = _innerStream.Length;
        }